本文整理汇总了C#中Newtonsoft.Json.Schema.JsonSchemaModelBuilder.AddSchema方法的典型用法代码示例。如果您正苦于以下问题:C# JsonSchemaModelBuilder.AddSchema方法的具体用法?C# JsonSchemaModelBuilder.AddSchema怎么用?C# JsonSchemaModelBuilder.AddSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Schema.JsonSchemaModelBuilder
的用法示例。
在下文中一共展示了JsonSchemaModelBuilder.AddSchema方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddSchema
public void AddSchema()
{
string first = @"{
""id"":""first"",
""type"":""object"",
""properties"":
{
""firstproperty"":{""type"":""string"",""maxLength"":10},
""secondproperty"":{
""type"":""object"",
""properties"":
{
""secondproperty_firstproperty"":{""type"":""string"",""maxLength"":10,""minLength"":7}
}
}
},
""additionalProperties"":{}
}";
string second = @"{
""id"":""second"",
""type"":""object"",
""extends"":{""$ref"":""first""},
""properties"":
{
""firstproperty"":{""type"":""string""},
""secondproperty"":{
""extends"":{
""properties"":
{
""secondproperty_firstproperty"":{""maxLength"":9,""minLength"":6}
}
},
""type"":""object"",
""properties"":
{
""secondproperty_firstproperty"":{}
}
},
""thirdproperty"":{""type"":""string""}
},
""additionalProperties"":false
}";
JsonSchemaResolver resolver = new JsonSchemaResolver();
JsonSchema firstSchema = JsonSchema.Parse(first, resolver);
JsonSchema secondSchema = JsonSchema.Parse(second, resolver);
JsonSchemaModelBuilder modelBuilder = new JsonSchemaModelBuilder();
JsonSchemaNode node = modelBuilder.AddSchema(null, secondSchema);
Assert.AreEqual(2, node.Schemas.Count);
Assert.AreEqual(2, node.Properties["firstproperty"].Schemas.Count);
Assert.AreEqual(3, node.Properties["secondproperty"].Schemas.Count);
Assert.AreEqual(3, node.Properties["secondproperty"].Properties["secondproperty_firstproperty"].Schemas.Count);
}
示例2: CircularReference
public void CircularReference()
{
string json = @"{
""id"":""CircularReferenceArray"",
""description"":""CircularReference"",
""type"":[""array""],
""items"":{""$ref"":""CircularReferenceArray""}
}";
JsonSchema schema = JsonSchema.Parse(json);
JsonSchemaModelBuilder modelBuilder = new JsonSchemaModelBuilder();
JsonSchemaNode node = modelBuilder.AddSchema(null, schema);
Assert.AreEqual(1, node.Schemas.Count);
Assert.AreEqual(node, node.Items[0]);
}