add custom swagger header

Yes you can do it via inheriting from IOperationFilter

You can find the answer on github here: AddRequiredHeaderParameter

   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 = "X-User-Token",
            @in = "header",
            type = "string",
            required = false
        });
    }
}

Then you go to your SwaggerConfig.cs file and add the following in the EnableSwaggersection:

   c.OperationFilter(() => new AddRequiredHeaderParameter());

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s