Skip to content

Instantly share code, notes, and snippets.

@EifelMono
Last active October 3, 2019 07:49
Show Gist options
  • Save EifelMono/1d02472d39d84872f4bef16d68bb961e to your computer and use it in GitHub Desktop.
Save EifelMono/1d02472d39d84872f4bef16d68bb961e to your computer and use it in GitHub Desktop.
Generate Schema from class with enums as string
// nuget:Newtonsoft.Json.Schema
using System;
using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Schema.Generation;
//nuget Newtonsoft.Json.Schema v2.0.8
public class Program
{
public static void Main()
{
Test1();
}
static void Test1()
{
var jsonSchemaGenerator = new JSchemaGenerator();
jsonSchemaGenerator.GenerationProviders.Add(new StringEnumGenerationProvider());
var myType = typeof(Person);
var schema = jsonSchemaGenerator.Generate(myType);
schema.Title = myType.Name;
Console.WriteLine(schema);
}
}
class Person
{
public int id {get;set;}
public string name {get;set;}
public DayOfWeek DoW {get;set;}
}
/*
Memory: ~ 390 kb
CPU: 0.766s
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment