Skip to content

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

@eiriktsarpalis

Description

@eiriktsarpalis

Description

Discovered while investigating modelcontextprotocol/csharp-sdk#601

Reproduction Steps

using System.Text.Json;
using System.Text.Json.Schema;

JsonSchemaExporterOptions options = new() { TreatNullObliviousAsNonNullable = true };
Console.WriteLine(JsonSerializerOptions.Default.GetJsonSchemaAsNode(typeof(int?), exporterOptions: options));

Expected behavior

Should have produced

{
  "type": ["integer","null"]
}

Actual behavior

Actually produces

{
  "type": "integer"
}

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions