Azure / azure-functions-openapi-extension

This extension provides an Azure Functions app with Open API capability for better discoverability to consuming parties
https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/
MIT License
370 stars 194 forks source link

SwaggerUI Bundle request/response interceptors #635

Open tpwalke2 opened 9 months ago

tpwalke2 commented 9 months ago

This PR is motivated by a need for supporting Auth0's additional requirements when generating access tokens. An additional parameter must be sent in the token request.

The SwaggerUI object allows passing in functions that intercept the request and response objects. The Swashbuckle.AspNetCore.Swagger project allows access to these functions via a builder extension method (https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/8f363f7359cb1cb8fa5de5195ec6d97aefaa16b3/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptionsExtensions.cs#L321C4-L321C4).

I chose to follow the same replacement strategy as the custom CSS and custom Javascript. I added 2 methods to the IOpenApiCustomUIOptions interface and implemented them as empty strings in the default implementation.

The downside to this method is that it is a breaking change for any downstream implementations of IOpenApiCustomUIOptions.

I also considered a solution of adding a new options class and passing it to the ISwaggerUI.BuildAsync method. However, this would have represented a breaking change to the ISwaggerUI interface. This solution would have also required a new default implementation, a new resolver, an update to the IOpenApiHttpTriggerContext interface and OpenApiHttpTriggerContext class.

The additional spread of the change required for the second solution seemed to be more complicated than updating the IOpenApiCustomUIOptions interface.

tpwalke2 commented 9 months ago

@microsoft-github-policy-service agree