本文整理匯總了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]);
}