Skip to content

Instantly share code, notes, and snippets.

@ankitvijay
Created January 15, 2020 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankitvijay/8fe6c26379ab67b7c358fbb035e23d83 to your computer and use it in GitHub Desktop.
Save ankitvijay/8fe6c26379ab67b7c358fbb035e23d83 to your computer and use it in GitHub Desktop.
Default Header Filter
using System;
using System.Net.Http;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace MyAwesomeApplication
{
public class DefaultHeaderFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (string.Equals(context.ApiDescription.HttpMethod, HttpMethod.Post.Method, StringComparison.InvariantCultureIgnoreCase))
{
operation.Parameters.Add(new OpenApiParameter
{
Name = "my-default-header",
In = ParameterLocation.Header,
Required = false,
Example = new OpenApiString("my-default-header-value")
});
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment