Fix handling of top-level nullable type schema generation.#117503
Merged
eiriktsarpalis merged 1 commit intodotnet:mainfrom Jul 11, 2025
Merged
Fix handling of top-level nullable type schema generation.#117503eiriktsarpalis merged 1 commit intodotnet:mainfrom
eiriktsarpalis merged 1 commit intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the schema exporter to correctly treat top-level nullable types (Nullable<T>) as nullable and adds tests for primitive nullable schemas.
- Registers
DateTimeOffset?in the source-gen serializer for top-level schema generation - Introduces
int?andDateTimeOffset?test cases inJsonSchemaExporterTests.TestTypes.cs - Refactors
CompleteSchemato factor out nullable-detection logic and includeNullable<T>support
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/Serialization/JsonSchemaExporterTests.cs | Added [JsonSerializable(typeof(DateTimeOffset?))] to enable source-gen schema support for nullable DateTimeOffset |
| src/libraries/System.Text.Json/tests/Common/JsonSchemaExporterTests.TestTypes.cs | Added TestData<int?> and TestData<DateTimeOffset?> cases to verify primitive nullable schema output |
| src/libraries/System.Text.Json/src/System/Text/Json/Schema/JsonSchemaExporter.cs | Refactored CompleteSchema to a local IsNullableSchema function that now special-cases Nullable<T> |
Comments suppressed due to low confidence (1)
src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/Serialization/JsonSchemaExporterTests.cs:44
- Add a corresponding test in the source-generation suite that asserts a
DateTimeOffset?schema hastype["string","null"] andformat"date-time" so the new registration is actually verified.
[JsonSerializable(typeof(DateTimeOffset?))]
5e30653 to
f87a2a2
Compare
This was referenced Jul 10, 2025
stephentoub
approved these changes
Jul 11, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fix #117493.