I am trying to create a JSON schema with the usage of Json.NET Schema. Anyway, my class has JsonConverter attribute, like in the example below:
public class Building
{
[JsonConverter(typeof(BuildConverter))]
public string Name { get; set; }
public string Phone { get; set; }
public string Type { get; set; }
public string Address { get; set; }
}
When generating a schema from the above class getting an empty schema {{}}, which is caused by the mentioned attribute.
What I have tried:
I wanted to create a JSchemaGenerationProvider for my class but still cannot get the correct schema.
public class CustomSchemaProvider : JSchemaGenerationProvider
{
public override JSchema GetSchema(JSchemaTypeGenerationContext context)
{
if (context.ObjectType == typeof(MyType))
{
return CreateSchemaWithFormat(context.ObjectType, context.Required);
}
return null;
}
private JSchema CreateSchemaWithFormat(Type type, Required required)
{
JSchemaGenerator generator = new JSchemaGenerator();
JSchema schema = generator.Generate(type, required != Required.Always);
return schema;
}
}
Usage:
public void ValidateSchema()
{
JSchemaGenerator generator = new JSchemaGenerator();
generator.GenerationProviders.Add(new CustomSchemaProvider());
JSchema schema = generator.Generate(typeof(Building));
Console.WriteLine(schema);
}
Could someone please take a look and suggest what I am doing wrong and how to get the correct schema against {{}}? I will appreciate any help.