代码之家  ›  专栏  ›  技术社区  ›  Grant M

新泽西州纽顿市。架构如何不在架构中生成引用$ref

  •  1
  • Grant M  · 技术社区  · 10 年前

    Json.Net公司。架构正在为我的所有字符串数组生成引用。例如这个c#

    public string[] ovoImageUrl;    
    public string[] ovoMetaprofile;
    

    生成此Json架构

    "ovoImageUrl": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": [
          "string",
          "null"
        ]
      }
    },
    "ovoMetaprofile": {
      "$ref": "#/properties/ovoImageUrl"
    },
    

    由于我使用Json模式作为人类可读的文档,这是不可取的。有没有办法,也许是通过属性,阻止创建这些“$ref”?

    干杯 授予

    1 回复  |  直到 10 年前
        1
  •  3
  •   James Newton-King dbc    10 年前

    Newtonsoft.Json的最新版本。架构具有 SchemaReferenceHandling 正在设置 JSchemaGenerator 用于控制参考。

    JSchemaGenerator generator = new JSchemaGenerator();
    generator.SchemaReferenceHandling = SchemaReferenceHandling.None;
    JSchema schema = generator.Generate(typeof(Person));
    

    http://www.newtonsoft.com/jsonschema/help/html/P_Newtonsoft_Json_Schema_Generation_JSchemaGenerator_SchemaReferenceHandling.htm