Skip to content

Fix OpenAPI schema ID collisions for duplicate type names#66937

Open
Bellambharath wants to merge 1 commit into
dotnet:mainfrom
Bellambharath:fix/64325-openapi-schema-id-collisions-v2
Open

Fix OpenAPI schema ID collisions for duplicate type names#66937
Bellambharath wants to merge 1 commit into
dotnet:mainfrom
Bellambharath:fix/64325-openapi-schema-id-collisions-v2

Conversation

@Bellambharath

Copy link
Copy Markdown
Contributor

Summary

  1. Deduplicate schema reference IDs when different types resolve to the same schema ID.
  2. Update CreateSchemaReferenceId tests to reflect non-nullable DateTime properties.
  3. Add test case for types with the same name in different namespaces.

Testing
otnet test src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Microsoft.AspNetCore.OpenApi.Tests.csproj --filter "FullyQualifiedName~CreateSchemaReferenceIdTests" -p:UseIsNativeAssets=false

Fixes #64325

Fixes dotnet#64325

When two different types resolve to the same schema ID (e.g. same class
name in different namespaces), both end up registered under the same key
in the OpenAPI components section — last one wins and the schema for the
first type just disappears silently.

This adds a ConcurrentDictionary<string, Type> (_schemaIdToType) that
tracks which type owns each schema ID. If a new type comes in with a
colliding ID, we append a numeric suffix (2, 3, ...) until we find a
slot that's free. Same type always gets the same ID back, so repeated
calls are stable.
@Bellambharath
Bellambharath requested a review from a team as a code owner May 31, 2026 17:19
@github-actions github-actions Bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label May 31, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 31, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @Bellambharath. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@tebeco

tebeco commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

why does this PR removes a lot of existing comments @Bellambharath ?
this seems to have been done it all in the same commit, and it's unclear why these were removed

or is that diff only visible until rebased ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI wrong schema generation

3 participants