Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I created a webapi on asp.net core and for the documentation I am using swagger swashbuckl.

My API need's some custom headers to validate request along with jwt-token

I need this custom headers

orgid: fe5mp0 brnid: NY0023 Authorization: Bearer

I managed to add Authorization header and it is working but can't find how to add these custom headers.

like image 683
Nitesh Shaw Avatar asked Nov 30 '25 15:11

Nitesh Shaw


1 Answers

The official explanation is here

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
            });
    }
}
like image 162
Vladmir Avatar answered Dec 02 '25 04:12

Vladmir