Slide 14
Slide 14 text
C# の型情報から JSON Schema を生成
JsonSchemaExporter
JsonSchemaExporter.GetJsonSchemaAsNode
(
JsonSerializerOptions.Default,
typeof(Person),
exporterOptions: new()
{
TreatNullObliviousAsNonNullable = true,
}
)
.ToJsonString();
.NET 9+
public class Person
{
public required string Name { get; init; }
public DateOnly? Birthday { get; init; }
}
{
"type": "object",
"properties": {
"Name": { "type": "string" },
"Birthday": {
"type": ["string", "null"],
"format": "date"
}
},
"required": ["Name"]
}