Description
The IgnoreReadOnlyProperties and IgnoreReadOnlyFields options are not taken into consideration by the JsonSchemaExporter today.
A property that is never serialized or deserialized is still emitting as part of the JSON schema.
Reproduction Steps
using System;
using System.Text.Json;
using System.Text.Json.Schema;
var options = new JsonSerializerOptions(JsonSerializerOptions.Default)
{
IgnoreReadOnlyProperties = true,
IgnoreReadOnlyFields = true,
};
Console.WriteLine("Serialized object:");
Console.WriteLine(JsonSerializer.Serialize(new C(), options));
Console.WriteLine();
Console.WriteLine("======");
Console.WriteLine();
Console.WriteLine("Json schema:");
Console.WriteLine(options.GetJsonSchemaAsNode(typeof(C)));
class C
{
public string S => "Hello";
}
Expected behavior
Output is:
Serialized object:
{}
======
Json schema:
{
"type": [
"object",
"null"
]
}
Actual behavior
Output is:
Serialized object:
{}
======
Json schema:
{
"type": [
"object",
"null"
],
"properties": {
"S": {
"type": [
"string",
"null"
]
}
}
}
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Description
The
IgnoreReadOnlyPropertiesandIgnoreReadOnlyFieldsoptions are not taken into consideration by theJsonSchemaExportertoday.A property that is never serialized or deserialized is still emitting as part of the JSON schema.
Reproduction Steps
Expected behavior
Output is:
Actual behavior
Output is:
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response