Created
September 18, 2023 02:07
-
-
Save dj-nitehawk/d172140b1f7d576e632a0d15e9682f54 to your computer and use it in GitHub Desktop.
Customizing Swagger Spec With An IOperationProcessor
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
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; | |
} | |
} |
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
builder.Services.SwaggerDocument(o => | |
{ | |
o.DocumentSettings = s => s.OperationProcessors.Add(new AddCustomHeader()); | |
}); |
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.
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
Really missed having this one in the documentation. Luckily, I found this on your gists.