Forum Discussion

shaowansh's avatar
6 months ago

Append custom header to Swagger request header and not change API parameter list

I am using Swashbuckle.Core.5.6.0 and have a SwaggeCongfig.cs file, I hope to append a custom header value pair(X-API-Source:Swagger) in all Swagger http request. 
I try to use add a class AddRequestHeaderOperationFilter : IOperationFilter

public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)

    operation.parameters.Add(new Parameter
        name = "X-API-Source",
        @in = "header",
        type = "string",
        required = false,
        description = $"Value of the {_headerKey} header",
        @default = "Swagger"

But it has a side effect add the header in API parameter list. I hope not change API parameter list, I just want to append the custom header in http request. Can I achieve in Swashbuckle.Core.5.6.0 with SwaggeCongfig.cs?

No RepliesBe the first to reply