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 hidden or 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 hidden or 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()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, great! Superb library man. Appreciate what you do.