Refer https://github.com/domaindrivendev/Swashbuckle
Swashbuckle adds swagger documentation to .NET Web API project.
This article explains how to document parameters that are passed in via HTTPHeader.
for this create a custom operation filter:
public class SwaggerHeaderparameters: IOperationFilter
{
public string Description { get; set; }
public string Key { get; set; }
public string Name { get; set; }
public string DefaultValue { get; set; }
public void Apply(SwaggerDocsConfig c)
{
c.ApiKey(Key).Name(Name).Description(Description).In("header");
c.OperationFilter(() => this);
}
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
operation.parameters = operation.parameters ?? new List<Parameter>();
operation.parameters.Add(new Parameter
{
name = Name,
description = Description,
@in = "header",
required = true,
type = "string",
@default = DefaultValue
});
}
}
How to use?
var brandHeader = new SwaggerHeaderparameters
{
Description = "brand",
Key = "brand",
Name = "brand"
};
config.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "API Documentation");
c.RootUrl(req => req.RequestUri.GetLeftPart(UriPartial.Authority)
+ req.GetRequestContext().VirtualPathRoot.TrimEnd('/'));
brandHeader.Apply(c);
}
).EnableSwaggerUi();
No comments:
Post a Comment