Add special handling for array types in OpenAPI schema references.#66583
Open
marcominerva wants to merge 2 commits intodotnet:mainfrom
Open
Add special handling for array types in OpenAPI schema references.#66583marcominerva wants to merge 2 commits intodotnet:mainfrom
marcominerva wants to merge 2 commits intodotnet:mainfrom
Conversation
1 task
Contributor
There was a problem hiding this comment.
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 appendingArrayto 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[]>, andOk<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. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
mikekistler
approved these changes
May 5, 2026
Contributor
mikekistler
left a comment
There was a problem hiding this comment.
Looks good! 👍
Thanks for this fix!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
JsonTypeInfoExtensions.csso that array types (e.g.,string[]) now generate schema reference IDs ending withArrayinstead of using invalid characters for OpenAPI schema keys. For example,string[]becomesstringArray, andstring[][]becomesstringArrayArray.Unit Test Coverage:
JsonTypeInfoExtensionsTests.csto add test cases for types likeOk<string[]>,Ok<int[]>,Ok<Todo[]>, andOk<string[][]>, ensuring the new schema reference ID logic for arrays is properly tested.Fixes #66299