Skip to content

Instantly share code, notes, and snippets.

@dj-nitehawk
Created September 18, 2023 02:07
Show Gist options
  • Select an option

  • Save dj-nitehawk/d172140b1f7d576e632a0d15e9682f54 to your computer and use it in GitHub Desktop.

Select an option

Save dj-nitehawk/d172140b1f7d576e632a0d15e9682f54 to your computer and use it in GitHub Desktop.
Customizing Swagger Spec With An IOperationProcessor
internal sealed class AddCustomHeader : IOperationProcessor
{
public bool Process(OperationProcessorContext context)
{
var hdrParameter = new OpenApiParameter()
{
Name = "x-custom",
Kind = OpenApiParameterKind.Header,
IsRequired = true,
Type = JsonObjectType.String,
Default = "xyz",
Description = "The description of the field"
};
context.OperationDescription.Operation.Parameters.Add(hdrParameter);
return true;
}
}
builder.Services.SwaggerDocument(o =>
{
o.DocumentSettings = s => s.OperationProcessors.Add(new AddCustomHeader());
});
@binair-io
Copy link
Copy Markdown

Really missed having this one in the documentation. Luckily, I found this on your gists.

@dj-nitehawk
Copy link
Copy Markdown
Author

it's linked from the cookbook since it didn't feel right to shove everything in the doc page :-)

the swagger page is already kinda chunky.

if you ever have any questions, just head on over to our discord. there's always someone hanging out in there.

@binair-io
Copy link
Copy Markdown

Ok, great! Superb library man. Appreciate what you do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment