- Swagger,在localhost上为web api 2.0应用程序完美地生成文档
- Swagger,不会在具有按需付费订阅的Azure应用程序服务上生成文档
您能否建议一下Azure应用服务的相关配置。
[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "FFX WebAPI");
c.OperationFilter<AuthorizationOperationFilter>();
c.PrettyPrint();
})
.EnableSwaggerUi(c =>
{
c.DocumentTitle("FFX WebAPI");
c.SupportedSubmitMethods(!int.TryParse(ConfigurationManager.AppSettings["Environment"],out int result) || result != 4 ? new string[] { "Get", "Post" }: new string[] { });
});
}
}
public class AuthorizationOperationFilter : IOperationFilter
{
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation.parameters == null)
{
operation.parameters = new List<Parameter>();
}
operation.parameters.Add(new Parameter
{
name = ApplicationConstants.Token,
@in = "header",
description = "enter token",
required = false,
type = "string"
});
}
}
1条答案
按热度按时间68bkxrlz1#
在控制器文件中:需要检查在构建调试和发布模式下浏览API设置是启用还是禁用。