-
-
Save stormwild/d9760bde9f51daa2b6ac50a28fbcfa2a 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