当代码在Azure App Service上部署时,Swagger未生成Web API 2.0文档

发布于 2025-02-01 04:19:09 字数 1700 浏览 2 评论 0原文

  1. Swagger,完美地在Web API 2.0应用程序Swagger上完美生成文档
  2. ,在订阅时不会生成付费的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"
        });
    }
}
  1. Swagger, generating documents perfectly on localhost for web api 2.0 application
  2. 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.

enter image description here

[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扮仙女 2025-02-08 04:19:10
#if DEBUG
    [ApiExplorerSettings(IgnoreApi = false)]
#else
    [ApiExplorerSettings(IgnoreApi = false)]
#endif

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

#if DEBUG
    [ApiExplorerSettings(IgnoreApi = false)]
#else
    [ApiExplorerSettings(IgnoreApi = false)]
#endif

In controller file : Need to check whether explore API settings is enable or disable in build debug and release mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文