Fix Minimal API endpoints not being part of OpenAPI document in ASP.Versioning v10 preview#1166
Conversation
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
4a43f35 to
5af8563
Compare
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
|
I am unable to view the error logs of the build due to a required login. |
|
CI builds should be fully anonymous. It looks like 2 failed tests. I'm currently traveling. I'll return home Tuesday. |
|
The tests fail due to 2 culture issues:
|
… 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
|
The tests have been fixed! 🥳 |
Strange that would be an issue. I too run on Windows and so does the build agent. 🤷🏽
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. 😄 |
Summary
Fixes #1165
AddApiExplorerServices()only calledAddMvcCore().AddApiExplorer(), which registersDefaultApiDescriptionProvider— a provider that only discovers controller-based endpoints. When using minimal APIs,OpenApiDocumentServicequeriesIApiDescriptionGroupCollectionProviderwhich aggregates from all registeredIApiDescriptionProviderinstances. WithoutEndpointMetadataApiDescriptionProvider, minimal API endpoints were never discovered, resulting in emptypathsand noschemasin the generated OpenAPI documents.Fix
Added
services.AddEndpointsApiExplorer()inAddApiExplorerServices(), which registersEndpointMetadataApiDescriptionProvider. This call is safe to invoke multiple times as it usesTryAddEnumerableinternally.Changes
IApiVersioningBuilderExtensions.cs: Addedservices.AddEndpointsApiExplorer()afterservices.AddMvcCore().AddApiExplorer()(1 line)AcceptanceTest.cs:minimal_api_should_generate_expected_open_api_documentto 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 correctidandapi-versionparameters.mixed_api_should_generate_expected_open_api_documentto verify both controller (/Test) and minimal API (/minimal/{id}) endpoints appear together in the same OpenAPI document.