Last active
October 3, 2019 07:49
-
-
Save EifelMono/1d02472d39d84872f4bef16d68bb961e to your computer and use it in GitHub Desktop.
Generate Schema from class with enums as string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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