Fix OpenApiSchemaService to handle implementation different from Dictionary<,> for schema.Properties#67384
Open
marcominerva wants to merge 3 commits into
Open
Conversation
…ionary<,> for schema.Properties
Contributor
|
Thanks for your PR, @marcominerva. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a runtime InvalidOperationException in OpenAPI schema reference resolution that can occur when schema.Properties is backed by an IDictionary implementation that detects modification during enumeration (e.g., SortedDictionary). It also adds a regression test to ensure schema transformers can swap in such a dictionary without breaking document generation.
Changes:
- Update
ResolveReferenceForSchemato iterate a snapshot ofschema.Propertieskeys before mutating entries. - Add a test that replaces
schema.Propertieswith aSortedDictionaryduring schema transformation and verifies OpenAPI document generation does not throw.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs | Avoids mutating schema.Properties while enumerating it by iterating a key snapshot first. |
| src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Transformers/SchemaTransformerTests.cs | Adds regression coverage for schema.Properties backed by a SortedDictionary. |
… tuple deconstruction
Youssef1313
reviewed
Jun 23, 2026
…nApiSchemaService.
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 addresses a potential runtime exception when handling OpenAPI schema properties that are stored in collections sensitive to modification during enumeration (such as
SortedDictionary). The core fix involves modifying the way properties are iterated and updated, and a test is added to ensure robustness.Bug fix for property enumeration and update:
schema.PropertiesinOpenApiSchemaService.csto first create a list of keys (schema.Properties.Keys.ToList()) and then update properties by key, preventingInvalidOperationExceptionwhenschema.Propertiesis a collection likeSortedDictionarythat detects modification during enumeration.Test coverage improvements:
SchemaTransformer_WithSortedDictionaryProperties_DoesNotThrowinSchemaTransformerTests.csto verify thatResolveReferenceForSchemadoes not throw whenschema.Propertiesis aSortedDictionary, ensuring the fix is validated and preventing regressions.Fixes #67086