OpenApi: Lowercase document name on registration to match AddOpenApi internal behaviour (closes #23210)#23212
Conversation
|
Claude finished @lauraneto's task in 4m 8s —— View job PR ReviewTarget: Normalises the OpenAPI document name to lowercase before all DI registration calls ( Important
Approved with Suggestions for improvementThe fix is correct and minimal — the split between |
There was a problem hiding this comment.
Pull request overview
This PR fixes a startup failure when registering OpenAPI documents with mixed-case names by normalizing the document name to lowercase for DI registration, aligning Umbraco’s registrations with Microsoft.AspNetCore.OpenApi’s internal lowercasing behavior.
Changes:
- Normalize
BackOfficeOpenApiDocumentBuilder’s DI registration key toDocumentName.ToLowerInvariant()while preserving the originalDocumentNamefor[MapToApi]endpoint filtering. - Normalize
AddUmbracoOpenApiDocument’sapiNameto lowercase before callingAddOpenApi, UI registration, and schema-service replacement.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Umbraco.Cms.Api.Common/OpenApi/BackOfficeOpenApiDocumentBuilder.cs | Lowercases the OpenAPI document registration key to keep AddOpenApi, UI registration, and schema-service replacement keyed consistently. |
| src/Umbraco.Cms.Api.Common/DependencyInjection/UmbracoBuilderApiExtensions.cs | Lowercases apiName before OpenAPI registration to match keyed service behavior. |
…nternal behaviour AddOpenApi lowercases the document name when registering its keyed services, so ReplaceOpenApiSchemaService must receive the same lowercased key or the lookup throws. BackOfficeOpenApiDocumentBuilder now computes a normalised registration name and uses it for all DI calls, while keeping DocumentName in its original casing. ShouldInclude matches [MapToApi] case-insensitively to align with how documents are registered, and the UI dropdown label falls back to DocumentName (original casing) rather than the lowercased registration key. AddUmbracoOpenApiDocument applies the same normalisation for its apiName parameter.
b894f50 to
293bb7d
Compare
Covers the bug scenario where AddBackOfficeOpenApiDocument with a mixed-case name and WithJsonOptions threw InvalidOperationException at startup, and verifies that ShouldInclude matches [MapToApi] case-insensitively.
|
kjac
left a comment
There was a problem hiding this comment.
Works like a charm, and I can reproduce the issue on main 👍
…internal behaviour (closes umbraco#23210) (umbraco#23212) * Lowercase OpenAPI document name on registration to match AddOpenApi internal behaviour AddOpenApi lowercases the document name when registering its keyed services, so ReplaceOpenApiSchemaService must receive the same lowercased key or the lookup throws. BackOfficeOpenApiDocumentBuilder now computes a normalised registration name and uses it for all DI calls, while keeping DocumentName in its original casing. ShouldInclude matches [MapToApi] case-insensitively to align with how documents are registered, and the UI dropdown label falls back to DocumentName (original casing) rather than the lowercased registration key. AddUmbracoOpenApiDocument applies the same normalisation for its apiName parameter. * Add regression tests for mixed-case OpenAPI document name registration Covers the bug scenario where AddBackOfficeOpenApiDocument with a mixed-case name and WithJsonOptions threw InvalidOperationException at startup, and verifies that ShouldInclude matches [MapToApi] case-insensitively.



Prerequisites
If there's an existing issue for this PR then this fixes #23210
Description
AddOpenApi(fromMicrosoft.AspNetCore.OpenApi) lowercases the document name internally when registering its keyed services.ReplaceOpenApiSchemaServicethen searches for the keyedOpenApiSchemaServiceregistration using the name as passed — so if the name contains uppercase letters the lookup fails with anInvalidOperationException.Both
BackOfficeOpenApiDocumentBuilder.Build()andAddUmbracoOpenApiDocumentnow normalise the name to lowercase for DI registration calls (AddOpenApi,AddOpenApiDocumentToUi,ReplaceOpenApiSchemaService). The original name is preserved where it is used for endpoint filtering —HasMapToApiAttributeinBackOfficeOpenApiDocumentBuilderandApiNameinConfigureUmbracoOpenApiOptionsBasesubclasses — so[MapToApi]attribute matching continues to work correctly.Testing
Add a sample constants file:
Add a sample controller:
Add a sample composer registering :
Start the application. Before this fix it throws
InvalidOperationExceptionat startup. After the fix the application starts and the document is available at/umbraco/openapi/mydocument.json.Also verify that the Management and DeliveryAPI open api documents are still accessible and including the respective endpoints.