小编Ste*_*art的帖子

如何获取 JSON.NET JSchema 生成器以在 JSON 模式中呈现additionalProperties 属性

我正在使用 JSON.NET JSchema Generator 创建基于用数据注释属性修饰的类的架构。我正在使用这样的生成器:

var generator = new JSchemaGenerator();
generator.ContractResolver = new CamelCasePropertyNamesContractResolver();
generator.SchemaIdGenerationHandling = SchemaIdGenerationHandling.TypeName;
var schema = generator.Generate(typeof(myType));
string jsonSchema = schema.ToString();
Run Code Online (Sandbox Code Playgroud)

这会生成一个示例架构,如下所示:

{
     "$id": "myType",
     "definitions": {
          "mySubType" : {
              "$id": "mySubType",
              "type": [
                   "object",
                   "null"
              ],
              "properties": {
                  "name": {
                     "type: "string"
                  }
              },
              "required": [
                  "name"
              ]
          }
     },
     "type": "object",
     "properties": {
         "name": {
            "type": "string"
         },
         "details": {
            "$ref": "mySubType"
         }
      },
      "required": [
          "name",
          "details"
      ]
}
Run Code Online (Sandbox Code Playgroud)

希望能够生成一个架构,其中包含 和 …

c# json.net jsonschema

5
推荐指数
1
解决办法
1579
查看次数

标签 统计

c# ×1

json.net ×1

jsonschema ×1