- I configured Swagger UI in my Web API MVC5. For testing API's, swagger works fine until I add some header parameters.
- API's are created in such way that username & password fields are in headers and all other data is taken in the body.
- Headers are added by
IOperationFilter
as suggested in Web Api How to add a Header parameter for all API in Swagger andOperationFilter
is added inSwaggerConfig.cs
as:c.OperationFilter<AddHeaderParameters>();
public class AddHeaderParameters : 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 = "Account Username", @in = "header", type = "string", required = true, }); operation.parameters.Add(new Parameter { name = "Account Password", @in = "header", type = "string", required = true, }); } }
Required help that which thing I have missed or something done not correct.