Draft
Respect IgnoreReadOnlyProperties/IgnoreReadOnlyFields in JsonSchemaExporter#132179
Conversation
|
Azure Pipelines: 16 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-text-json |
Co-authored-by: steveisok <471438+steveisok@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/libraries/System.Text.Json/tests/Common/JsonSchemaExporterTests.TestTypes.cs:851
- The comment says read-only members are omitted when IgnoreReadOnlyProperties/IgnoreReadOnlyFields are enabled, but this test still expects the read-only collection property to be present. Please clarify that only members actually ignored by those settings (e.g., non-collection read-only properties/fields) are omitted, while collection properties can still be serialized/populated.
// Read-only members are omitted when IgnoreReadOnlyProperties/IgnoreReadOnlyFields are enabled.
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
Co-authored-by: steveisok <471438+steveisok@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix JsonSchemaExporter to respect IgnoreReadOnlyProperties and IgnoreReadOnlyFields
Respect IgnoreReadOnlyProperties/IgnoreReadOnlyFields in JsonSchemaExporter
Aug 11, 2026
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (2)
src/libraries/System.Text.Json/tests/Common/JsonSchemaExporterTests.TestTypes.cs:859
ReadOnlyCollectionPropertyis declared as a non-nullableList<int>, so the schema for the property should not include"null"in itstypeunion. This expected JSON currently marks it as nullable.
"properties": {
"Name": { "type": ["string", "null"] },
"ReadOnlyCollectionProperty": { "type": ["array", "null"], "items": { "type": "integer" } }
}
src/libraries/System.Text.Json/tests/Common/JsonSchemaExporterTests.TestTypes.cs:844
ReadOnlyCollectionPropertyis declared as a non-nullableList<int>, so the schema for the property should not include"null"in itstypeunion. In this file, non-nullable collection properties (e.g.PocoWithRecursiveCollectionElement.Children) are expected to emit"type": "array"withoutnull.
This issue also appears on line 856 of the same file.
"Name": { "type": ["string", "null"] },
"ReadOnlyProperty": { "type": "integer" },
"ReadOnlyCollectionProperty": { "type": ["array", "null"], "items": { "type": "integer" } }
}
- Files reviewed: 4/4 changed files
- Comments generated: 0 new
- Review effort level: Lite
This was referenced Aug 12, 2026
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.
JsonSchemaExporteremitted read-only members that the serializer never writes whenIgnoreReadOnlyProperties/IgnoreReadOnlyFieldsare enabled, so the schema disagreed with the actual serialized payload.Changes
JsonSchemaExporter: the property filter previously skipped only members with bothGetandSetnull. It now uses the flags the serializer itself computes:CanSerialize/CanDeserializeOrPopulatealready account for the ignore-read-only policy,[JsonIgnore], andShouldSerializeoverrides, so no new option plumbing is needed. Read-only collection properties are unaffected — they remain serializable and stay in the schema.Tests: shared
TestDataentries for a POCO with read-only properties, with and withoutIgnoreReadOnlyProperties(exercised under both reflection and source gen), plus a reflection-only theory forIgnoreReadOnlyFields. Fields are kept out of the shared data because source gen drops non-[JsonInclude]fields at generation time and gives[JsonInclude]readonly fields an UnsafeAccessor setter, making them non-read-only at runtime.