【问题标题】:How to add custom headers on swashbuckl asp.net core web api如何在 swashbuckl asp.net core web api 上添加自定义标头
【发布时间】:2018-04-30 06:53:55
【问题描述】:

我在 asp.net core 上创建了一个 webapi,并为文档使用了 swagger swashbuckl。

我的 API 需要一些自定义标头来验证请求以及 jwt-token

我需要这个自定义标题

orgid: fe5mp0 名称:NY0023 授权:承载

我设法添加了授权标头,它正在工作,但找不到如何添加这些自定义标头。

【问题讨论】:

    标签: c# asp.net-core swagger asp.net-core-webapi swashbuckle


    【解决方案1】:

    官方解释在这里

    https://github.com/domaindrivendev/Swashbuckle/issues/501#issuecomment-143254123

    public class AddRequiredHeaderParameter : 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 = "Foo-Header",
                    @in = "header",
                    type = "string",
                    required = true
                });
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-21
      • 2018-05-13
      • 1970-01-01
      • 1970-01-01
      • 2012-11-09
      • 1970-01-01
      • 1970-01-01
      • 2019-03-04
      • 2018-08-15
      相关资源
      最近更新 更多