Auto schema ID generation |
This sample generates a new JSchema with SchemaIdGenerationHandling set to automatically generate IDs based on the type name.
public class Person { public string Name { get; set; } public int Age { get; set; } }
JSchemaGenerator generator = new JSchemaGenerator(); // types with no defined ID have their type name as the ID generator.SchemaIdGenerationHandling = SchemaIdGenerationHandling.TypeName; JSchema schema = generator.Generate(typeof(Person)); // { // "id": "Person", // "type": "object", // "properties": { // "name": { // "type": [ "string", "null" ] // }, // "age": { "type": "integer" } // }, // "required": [ "name", "age" ] // }