Install Newtonsoft.Json.Schema
package via NuGet package manager, then you can output enums as strings out-of-the-box.
Given classes
public class Foo
{
public Options Bar { get; set; }
}
public enum Options
{
Option1,
Option2
}
Schema would be generated as follows, no need to decorate classes/properties with [JsonConverter(typeof(StringEnumConverter))]
attribute.
JSchemaGenerator generator = new JSchemaGenerator();
generator.GenerationProviders.Add(new StringEnumGenerationProvider());
JSchema schema = generator.Generate(typeof(Foo), false);
//Console.WriteLine(schema);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…