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

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 ?

},
};

// Using JsonArray inline causes the compile to pick the generic Add<T>() overload

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider reverting the removal of comments.

@Youssef1313 Youssef1313 added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Sep 2, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Sep 26, 2026
@tebeco

tebeco commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

@Youssef1313
can a fix be planned somehow even if that mean net12

the removal of duplicate created a serious bug for teams that needs to expose an openapi schema with similar names for sub entity

This branch has not been deployed

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

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc 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 pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI wrong schema generation

3 participants