You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.2 KiB
Plaintext

11 months ago
using System.Web.Http;
using WebActivatorEx;
using Swashbuckle.Application;
using CCFlow.DataUser.API;
using Swashbuckle.Swagger;
using System.Web.Http.Description;
using System.Linq;
[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
namespace CCFlow.DataUser.API
{
/// <summary>
/// <20><><EFBFBD>ؽӿڣ<D3BF><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD>swagger<65>ĵ<EFBFBD>չʾ
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Class)]
public partial class HiddenApiAttribute : System.Attribute { }
public class HiddenApiFilter : IDocumentFilter
{
/// <summary>
/// <20><>дApply<6C><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD>ؽӿڵ<D3BF><DAB5><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="swaggerDoc">swagger<65>ĵ<EFBFBD><C4B5>ļ<EFBFBD></param>
/// <param name="schemaRegistry"></param>
/// <param name="apiExplorer">api<70>ӿڼ<D3BF><DABC><EFBFBD></param>
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
{
foreach (ApiDescription apiDescription in apiExplorer.ApiDescriptions)
{
if (Enumerable.OfType<HiddenApiAttribute>(apiDescription.GetControllerAndActionAttributes<HiddenApiAttribute>()).Any())
{
string key = "/" + apiDescription.RelativePath;
if (key.Contains("?"))
{
int idx = key.IndexOf("?", System.StringComparison.Ordinal);
key = key.Substring(0, idx);
}
swaggerDoc.paths.Remove(key);
}
}
}
}
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "ToolKit");
string path = System.AppDomain.CurrentDomain.BaseDirectory;
c.IncludeXmlComments(System.String.Format(@"{0}\bin\ToolKit.XML", path));
c.DocumentFilter<HiddenApiFilter>();
})
.EnableSwaggerUi(c =>{});
}
}
}