在Azure应用程序服务上部署代码时,Swagger未生成Web API 2.0文档

mwyxok5s  于 2022-11-06  发布在  其他
关注(0)|答案(1)|浏览(180)
  1. Swagger,在localhost上为web api 2.0应用程序完美地生成文档
  2. 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"
        });
    }
}
68bkxrlz

68bkxrlz1#


# if DEBUG

    [ApiExplorerSettings(IgnoreApi = false)]

# else

    [ApiExplorerSettings(IgnoreApi = false)]

# endif

在控制器文件中:需要检查在构建调试和发布模式下浏览API设置是启用还是禁用。

相关问题