当代码在Azure App Service上部署时,Swagger未生成Web API 2.0文档
- Swagger,完美地在Web API 2.0应用程序Swagger上完美生成文档
- ,在订阅时不会生成付费的Azure App Service文档,
您可以建议您在Azure App Service上提出任何有关Swagger的配置。
[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"
});
}
}
- Swagger, generating documents perfectly on localhost for web api 2.0 application
- Swagger, does not generating documents on Azure App service having pay as you go subscription
Could you please suggest any related configuration around azure app service for swagger.
[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"
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在控制器文件中:需要检查探索API设置是否在构建调试和发布模式下启用还是禁用。
In controller file : Need to check whether explore API settings is enable or disable in build debug and release mode.