Created
January 15, 2020 21:27
-
-
Save ankitvijay/8fe6c26379ab67b7c358fbb035e23d83 to your computer and use it in GitHub Desktop.
Default Header Filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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