Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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