Skip to content

Fix Minimal API endpoints not being part of OpenAPI document in ASP.Versioning v10 preview#1166

Merged
commonsensesoftware merged 7 commits intodotnet:mainfrom
sander1095:fix/minimal-api-openapi-empty-paths
Mar 9, 2026
Merged

Fix Minimal API endpoints not being part of OpenAPI document in ASP.Versioning v10 preview#1166
commonsensesoftware merged 7 commits intodotnet:mainfrom
sander1095:fix/minimal-api-openapi-empty-paths

Conversation

@sander1095
Copy link
Contributor

Summary

Fixes #1165

AddApiExplorerServices() only called AddMvcCore().AddApiExplorer(), which registers DefaultApiDescriptionProvider — a provider that only discovers controller-based endpoints. When using minimal APIs, OpenApiDocumentService queries IApiDescriptionGroupCollectionProvider which aggregates from all registered IApiDescriptionProvider instances. Without EndpointMetadataApiDescriptionProvider, minimal API endpoints were never discovered, resulting in empty paths and no schemas in the generated OpenAPI documents.

Fix

Added services.AddEndpointsApiExplorer() in AddApiExplorerServices(), which registers EndpointMetadataApiDescriptionProvider. This call is safe to invoke multiple times as it uses TryAddEnumerable internally.

Changes

  • IApiVersioningBuilderExtensions.cs: Added services.AddEndpointsApiExplorer() after services.AddMvcCore().AddApiExplorer() (1 line)
  • AcceptanceTest.cs:
    • Rewrote minimal_api_should_generate_expected_open_api_document to test a pure minimal-API-only scenario (no controllers). Application parts are cleared to prevent MVC auto-discovery of test controllers. Asserts that /test/{id} path is present with correct id and api-version parameters.
    • Added mixed_api_should_generate_expected_open_api_document to verify both controller (/Test) and minimal API (/minimal/{id}) endpoints appear together in the same OpenAPI document.

AddApiExplorerServices() only called AddMvcCore().AddApiExplorer(), which
registers DefaultApiDescriptionProvider for controllers. Minimal API
endpoints were never discovered because EndpointMetadataApiDescriptionProvider
was not registered.

Added services.AddEndpointsApiExplorer() which registers the missing
provider. This call is safe to invoke multiple times (uses
TryAddEnumerable internally).

Fixes dotnet#1165
@sander1095 sander1095 force-pushed the fix/minimal-api-openapi-empty-paths branch from 4a43f35 to 5af8563 Compare February 27, 2026 23:27
Copilot AI and others added 2 commits February 28, 2026 00:11
Replace manual parameter checks in minimal_api and mixed_api tests
with JsonNode.DeepEquals comparison against expected JSON content files.
Add v1-minimal.json and v1-mixed.json expected output files.

Co-authored-by: sander1095 <7312681+sander1095@users.noreply.github.com>
Rewrite AcceptanceTests to use JSON files and JsonNode.DeepEquals
@sander1095
Copy link
Contributor Author

I am unable to view the error logs of the build due to a required login.

@commonsensesoftware
Copy link
Collaborator

CI builds should be fully anonymous. It looks like 2 failed tests.

https://dev.azure.com/aspnet-api-versioning/build/_build/results?buildId=619&view=logs&j=12f1170f-54f2-53f3-20dd-22fc7dff55f9&t=9c939e41-62c2-5605-5e05-fc3554afc9f5

I'm currently traveling. I'll return home Tuesday.

@sander1095
Copy link
Contributor Author

The tests fail due to 2 culture issues:

  • I run on Windows, and the newlines in the expected vs actual OpenAPI generated document differ.
  • The dates expect an (american) 1/1/2026 notation. This can be fixed by using the AssumeCulture attribute

… descriptions

The AssumeCultureAttribute is, for now, copied from another test project. PR feedback can indicate if a shared approach is preferred, and, if so, how that can be achieved
@sander1095
Copy link
Contributor Author

The tests have been fixed! 🥳

@sander1095 sander1095 changed the title Register EndpointMetadataApiDescriptionProvider for minimal APIs Fix Minimal API endpoints not being part of OpenAPI document in ASP.Versioning v10 preview Mar 4, 2026
@commonsensesoftware
Copy link
Collaborator

I run on Windows, and the newlines in the expected vs actual OpenAPI generated document differ.

Strange that would be an issue. I too run on Windows and so does the build agent. 🤷🏽

The dates expect an (american) 1/1/2026 notation...

There are other kinds of formats and notations? 🤔 🤣

I've been hit by this kind of thing before. This is a reasonable fix. I try to stay out of the localization biz, but this was a valid use case to have some default text. Almost crazy to think there are different, cultural ways of the writing the same text in the same language. 😄

@commonsensesoftware commonsensesoftware merged commit 7f0ac09 into dotnet:main Mar 9, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minimal API endpoints produce empty paths and schemas in OpenAPI documents

3 participants