Skip to content

Conversation

@eiriktsarpalis
Copy link
Member

Fix #117493.

Copy link
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 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? and DateTimeOffset? test cases in JsonSchemaExporterTests.TestTypes.cs
  • Refactors CompleteSchema to factor out nullable-detection logic and include Nullable<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 has type ["string","null"] and format "date-time" so the new registration is actually verified.
        [JsonSerializable(typeof(DateTimeOffset?))]

@eiriktsarpalis eiriktsarpalis merged commit 496af72 into dotnet:main Jul 11, 2025
82 of 87 checks passed
@eiriktsarpalis eiriktsarpalis deleted the fix-nullable-exporter branch July 11, 2025 07:18
@github-actions github-actions bot locked and limited conversation to collaborators Aug 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JsonSchemaExporter] TreatNullObliviousAsNonNullable incorrectly applies to Nullable<T> types

2 participants