Swashbuckle.HeaderParameter.Extension
Decorate your controllers and methods with header parameters with this Swashbuckle extension
Adding support in your startup file:
services.AddSwaggerGen(c =>
{
c.AddHeaderParameters();
});
Or, to add a header parameter(s) to all methods within an Api:
services.AddSwaggerGen(c =>
{
c.AddHeaderParameters
(
new[]
{
new HeaderParameter
{
Name = "X-Correlation-ID",
AllowEmptyValue = false,
Required = true,
Description = "Correlates HTTP requests between a client and server.",
Type = "string",
Format = "uuid"
}
}
);
Adding a required header parameter to a method:
[HttpPost]
[HeaderParameter(Name = "Content-Type", Required = true, Example = "application/json", Type = "string")]
public async Task<IActionResult> Post([FromBody] WeatherForecast _)
{
Adding a header paramter to all methods within a controller:
[ApiController]
[Route("[controller]")]
[HeaderParameter(Name = "Content-Disposition", Required = true, Example = "inline", Type = "string")]
public class WeatherForecastController : ControllerBase
{