Use JSON.NET to generate JSON schema with extra attributes

后端 未结 5 2127
鱼传尺愫
鱼传尺愫 2020-12-28 08:28

I am using JSON.NET to generate JSON Schema from c# object class. But I was unable to add any other json schema attributes e.g. maxLength, pattern(regex to validate email),

5条回答
  •  星月不相逢
    2020-12-28 08:35

    Json.NET Schema now has much improved schema generation support.

    You can annotate properties with .NET's Data Annotation attributes to specify information like minimum, maximum, minLength, maxLength and more on a schema.

    There is also JSchemaGenerationProvider that lets you take complete control when generating a schema for a type.

    More details here: http://www.newtonsoft.com/jsonschema/help/html/GeneratingSchemas.htm

提交回复
热议问题