Support Minimal API endpoints in offline OpenAPI generation#7874
Draft
Hinton wants to merge 1 commit into
Draft
Conversation
Extract the PAM-free swagger foundation from the PAM POC so it can land on main independently. - Add Bit.HttpExtensions.StandaloneEndpointDataSource and the AddOpenApiEndpointDataSource registration helper. The offline OpenAPI generator (dotnet swagger tofile) never runs the Configure pipeline where Minimal API endpoints are mapped via UseEndpoints, so it omits them. A single DI-registered EndpointDataSource composes every feature's mapping delegate and is gated to swagger generation only, so it never replaces the runtime composite EndpointDataSource that routing and link generation depend on. - Teach SwaggerGenOptionsExt.BuildOperationId and ActionNameOperationFilter to derive the operation ID and action name from the endpoint name set via .WithName(...) when there are no controller/action route values, as is the case for Minimal API endpoints. - Guarantee BuildOperationId never returns a null/empty operation ID: a Minimal API endpoint mapped without .WithName() now falls back to a deterministic id derived from the HTTP method and route template. Swashbuckle writes the selector's value straight onto operation.OperationId, so a null/empty id would collapse distinct endpoints together and abort spec generation via CheckDuplicateOperationIdsDocumentFilter. - Add unit tests for BuildOperationId (including the route fallback), the ActionNameOperationFilter endpoint-name branch, StandaloneEndpointDataSource composition, and AddOpenApiEndpointDataSource gating/registration.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7874 +/- ##
==========================================
- Coverage 65.74% 61.23% -4.51%
==========================================
Files 2219 2221 +2
Lines 98064 98116 +52
Branches 8849 8859 +10
==========================================
- Hits 64471 60081 -4390
- Misses 31379 35918 +4539
+ Partials 2214 2117 -97 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



🎟️ Tracking
📔 Objective
Our current Swagger implementation using Swashbuckle with
Startup.csdoes not support automatically detecting Minimal Api's. This implements a workaround which creates a customEndpointDataSourcewhich gets registered earlier and are therefore detected by the Swagger generation CLI.Bit.HttpExtensions.StandaloneEndpointDataSourceand theAddOpenApiEndpointDataSourceregistration helper. The offline OpenAPI generator (dotnet swagger tofile) never runs the Configure pipeline where Minimal API endpoints are mapped viaUseEndpoints, so it omits them. A single DI-registeredEndpointDataSourcecomposes every feature's mapping delegate and is gated to swagger generation only, so it never replaces the runtime compositeEndpointDataSourcethat routing and link generation depend on.SwaggerGenOptionsExt.BuildOperationIdandActionNameOperationFilterto derive the operation ID and action name from the endpoint name set via.WithName(...)when there are no controller/action route values, as is the case for Minimal API endpoints.BuildOperationIdnever returns a null/empty operation ID: a Minimal API endpoint mapped without.WithName()now falls back to a deterministic id derived from the HTTP method and route template. Swashbuckle writes the selector's value straight ontooperation.OperationId, so a null/empty id would collapse distinct endpoints together and abort spec generation viaCheckDuplicateOperationIdsDocumentFilter.BuildOperationId(including the route fallback), theActionNameOperationFilterendpoint-name branch,StandaloneEndpointDataSourcecomposition, andAddOpenApiEndpointDataSourcegating/registration.Example Output
Example output of a minimal API.