Skip to content

Add special handling for array types in OpenAPI schema references.#66583

Open
marcominerva wants to merge 2 commits intodotnet:mainfrom
marcominerva:fix-createschemareferenceid
Open

Add special handling for array types in OpenAPI schema references.#66583
marcominerva wants to merge 2 commits intodotnet:mainfrom
marcominerva:fix-createschemareferenceid

Conversation

@marcominerva
Copy link
Copy Markdown
Contributor

This pull request enhances the handling of array types in OpenAPI schema reference IDs and updates the corresponding unit tests to cover these scenarios. The most important changes are grouped below:

Schema Reference ID Generation:

  • Added special handling in JsonTypeInfoExtensions.cs so that array types (e.g., string[]) now generate schema reference IDs ending with Array instead of using invalid characters for OpenAPI schema keys. For example, string[] becomes stringArray, and string[][] becomes stringArrayArray.

Unit Test Coverage:

  • Updated JsonTypeInfoExtensionsTests.cs to add test cases for types like Ok<string[]>, Ok<int[]>, Ok<Todo[]>, and Ok<string[][]>, ensuring the new schema reference ID logic for arrays is properly tested.

Fixes #66299

Copilot AI review requested due to automatic review settings May 5, 2026 08:16
@marcominerva marcominerva requested a review from a team as a code owner May 5, 2026 08:16
@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 5, 2026
@martincostello martincostello added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels May 5, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes OpenAPI schema reference ID generation for array types so the resulting component schema keys avoid invalid characters like [], aligning with OpenAPI’s component key constraints and addressing #66299.

Changes:

  • Updated GetSchemaReferenceId(Type, ...) to special-case arrays by appending Array to the element type’s schema ID (including jagged arrays).
  • Added unit test coverage for array generic arguments such as Ok<string[]>, Ok<int[]>, Ok<Todo[]>, and Ok<string[][]>.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/OpenApi/src/Extensions/JsonTypeInfoExtensions.cs Adds array-specific schema reference ID formatting to avoid invalid OpenAPI component schema key characters.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Extensions/JsonTypeInfoExtensionsTests.cs Extends test data to validate schema reference IDs produced for array-based generic result types.

Comment thread src/OpenApi/src/Extensions/JsonTypeInfoExtensions.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@mikekistler mikekistler left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

Thanks for this fix!

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 feature-openapi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OpenAPI] Default CreateSchemaReferenceId produces invalid schema keys for array types

4 participants