Click or drag to resize
Json.NET Schema

Using JSchemaGenerationProvider

 

This sample generates a new JSchema with a JSchemaGenerationProvider.

Sample
Types
public class BuildingReport
{
    public DateTime Date { get; set; }
    public BuildingZone Zone { get; set; }
}

public enum BuildingZone
{
    Residential,
    Commercial,
    Industrial
}
Usage
JSchemaGenerator generator = new JSchemaGenerator();

JSchema schema = generator.Generate(typeof(BuildingReport));
// {
//   "type": "object",
//   "properties": {
//     "Date": {
//       "type": "string"
//     },
//     "Zone": {
//       "type": "integer",
//       "enum": [ 0, 1, 2 ]
//     }
//   },
//   "required": [ "Date", "Zone" ]
// }

JSchemaGenerator stringEnumGenerator = new JSchemaGenerator();

// change Zone enum to generate a string
stringEnumGenerator.GenerationProviders.Add(new StringEnumGenerationProvider());

JSchema stringEnumSchema = stringEnumGenerator.Generate(typeof(BuildingReport));
// {
//   "type": "object",
//   "properties": {
//     "Date": {
//       "type": "string"
//     },
//     "Zone": {
//       "type": "string",
//       "enum": [ "Residential", "Commercial", "Industrial" ]
//     }
//   },
//   "required": [ "Date", "Zone" ]
// }