Repository navigation
Labels
Description
Description
When creating a schema, my understanding for the $ref part is that it follows https://www.rfc-editor.org/info/rfc6901/#section-6 (The URI Fragment Identifier Representation part)
Looking at the example there, the reference tokens appear to be percent-encoded, but STJ doesn't encode it.
Reproduction Steps
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Schema;
using System.Text.Json.Serialization;
var options = new JsonSerializerOptions()
{
TypeInfoResolver = JsonSerializerOptions.Default.TypeInfoResolver,
WriteIndented = true,
};
Console.WriteLine(JsonSchemaExporter.GetJsonSchemaAsNode(options, typeof(Base))
.ToJsonString(options));
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[JsonDerivedType(typeof(Derived1), typeDiscriminator: "alpha")]
[JsonDerivedType(typeof(Derived2), typeDiscriminator: "beta")]
internal abstract class Base
{
[JsonPropertyName("hello%20world")]
public required Dictionary<string, string[]> SpecialChars { get; set; }
}
internal class Derived1 : Base { }
internal class Derived2 : Base { }Expected behavior
{
"type": [
"object",
"null"
],
"required": [
"$type"
],
"anyOf": [
{
"properties": {
"$type": {
"const": "alpha"
},
"hello%20world": {
"type": "object",
"additionalProperties": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
}
}
},
"required": [
"hello%20world"
]
},
{
"properties": {
"$type": {
"const": "beta"
},
"hello%20world": {
"type": "object",
"additionalProperties": {
"$ref": "#/anyOf/0/properties/hello%2520world/additionalProperties"
}
}
},
"required": [
"hello%20world"
]
}
]
}Actual behavior
{
"type": [
"object",
"null"
],
"required": [
"$type"
],
"anyOf": [
{
"properties": {
"$type": {
"const": "alpha"
},
"hello%20world": {
"type": "object",
"additionalProperties": {
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
}
}
},
"required": [
"hello%20world"
]
},
{
"properties": {
"$type": {
"const": "beta"
},
"hello%20world": {
"type": "object",
"additionalProperties": {
"$ref": "#/anyOf/0/properties/hello%20world/additionalProperties"
}
}
},
"required": [
"hello%20world"
]
}
]
}Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
See https://www.jsonschemavalidator.net/s/DC2SIxpb (with the currently produced schema showing as invalid):
Could not resolve schema reference '#/anyOf/0/properties/hello%20world/additionalProperties'. Path 'anyOf[1].properties.hello%20world.additionalProperties', line 42, position 35.
See https://www.jsonschemavalidator.net/s/jBmPEngV (with the expected schema showing as valid).
Reacted by Copilot
Activity
dotnet-policy-service commentedon Jul 3, 2026
Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.