繁体   English   中英

如何在Swashbuckl ASP.NET Core Web API上添加自定义标头

[英]How to add custom headers on swashbuckl asp.net core web api

我在asp.net核心上创建了一个webapi,对于文档,我使用了大方的swashbuckl。

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

我需要这个自定义标题

orgid:fe5mp0 brnid:NY0023授权:Bearer

我设法添加了Authorization标头,并且它可以正常工作,但是找不到如何添加这些自定义标头。

官方解释在这里

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
            });
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM