本文整理汇总了C#中JSchemaReader类的典型用法代码示例。如果您正苦于以下问题:C# JSchemaReader类的具体用法?C# JSchemaReader怎么用?C# JSchemaReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSchemaReader类属于命名空间,在下文中一共展示了JSchemaReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultipleTypes
public void MultipleTypes()
{
string json = @"{
""description"":""Age"",
""type"":[""string"", ""integer""]
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Age", schema.Description);
Assert.AreEqual(JSchemaType.String | JSchemaType.Integer, schema.Type);
}
示例2: EscapedReferences
public void EscapedReferences()
{
string json = @"{
""tilda~field"": {""type"": ""integer""},
""slash/field"": {""type"": ""object""},
""percent%field"": {""type"": ""array""},
""properties"": {
""tilda"": {""$ref"": ""#/tilda~0field""},
""slash"": {""$ref"": ""#/slash~1field""},
""percent"": {""$ref"": ""#/percent%25field""}
}
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.AreEqual(JSchemaType.Integer, schema.Properties["tilda"].Type);
Assert.AreEqual(JSchemaType.Object, schema.Properties["slash"].Type);
Assert.AreEqual(JSchemaType.Array, schema.Properties["percent"].Type);
}
示例3: References_Items_IndexNotInteger
public void References_Items_IndexNotInteger()
{
string json = @"{
""items"": [{""type"": ""integer""},{""prop"":{""type"": ""object""}}],
""properties"": {
""array"": {""$ref"": ""#/items/0""},
""arrayprop"": {""$ref"": ""#/items/one""}
}
}";
ExceptionAssert.Throws<JSchemaReaderException>(() =>
{
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
}, "Could not resolve schema reference '#/items/one'. Path 'properties.arrayprop', line 5, position 31.");
}
示例4: AdditionalItems
public void AdditionalItems()
{
string json = @"{
""items"": [],
""additionalItems"": {""type"": ""integer""}
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.IsNotNull(schema.AdditionalItems);
Assert.AreEqual(JSchemaType.Integer, schema.AdditionalItems.Type);
Assert.AreEqual(true, schema.AllowAdditionalItems);
}
示例5: Reference_ForwardsLocation
public void Reference_ForwardsLocation()
{
string json = @"{
""properties"": {
""bar"": {""$ref"": ""#/properties/foo""},
""foo"": {""type"": ""integer""}
}
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.AreEqual(schema.Properties["foo"], schema.Properties["bar"]);
}
示例6: ReferenceToNestedSchemaWithIdInResolvedSchema_ExtensionData
public void ReferenceToNestedSchemaWithIdInResolvedSchema_ExtensionData()
{
JSchema nested = new JSchema();
nested.Id = new Uri("nested.json", UriKind.RelativeOrAbsolute);
JSchema root = new JSchema
{
Id = new Uri("http://test.test"),
ExtensionData =
{
{ "nested", nested }
}
};
string rootJson = root.ToString();
string json = @"{
""type"":[""array""],
""items"":{""$ref"":""http://test.test/nested.json""}
}";
NestedPreloadedResolver resolver = new NestedPreloadedResolver();
resolver.Add(root.Id, rootJson);
JSchemaReader schemaReader = new JSchemaReader(resolver);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.AreEqual(new Uri("nested.json", UriKind.RelativeOrAbsolute), schema.Items[0].Id);
Assert.AreEqual(nested, schema.Items[0]);
}
示例7: UnresolvedReference
public void UnresolvedReference()
{
try
{
string json = @"{
""id"":""CircularReferenceArray"",
""description"":""CircularReference"",
""type"":[""array""],
""items"":{""$ref"":""#/definitions/nested""},
""definitions"":{
""nested"": {""$ref"":""MyUnresolvedReference""}
}
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
}
catch (JSchemaReaderException ex)
{
Assert.AreEqual(@"Could not resolve schema reference 'MyUnresolvedReference'. Path 'definitions.nested', line 7, position 16.", ex.Message);
Assert.AreEqual(null, ex.BaseUri);
}
}
示例8: ExclusiveMinimum_ExclusiveMaximum
public void ExclusiveMinimum_ExclusiveMaximum()
{
string json = @"{
""exclusiveMinimum"":true,
""exclusiveMaximum"":true
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.AreEqual(true, schema.ExclusiveMinimum);
Assert.AreEqual(true, schema.ExclusiveMaximum);
}
示例9: Id
public void Id()
{
string json = @"{
""description"":""Id"",
""id"":""testid""
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Id", schema.Description);
Assert.AreEqual(new Uri("testid", UriKind.RelativeOrAbsolute), schema.Id);
}
示例10: Required
public void Required()
{
string json = @"{
""description"":""Required"",
""required"":true
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Required", schema.Description);
Assert.AreEqual(true, schema.DeprecatedRequired);
}
示例11: DeprecatedRequired
public void DeprecatedRequired()
{
string schemaJson = @"{
""description"":""A person"",
""type"":""object"",
""properties"":
{
""name"":{""type"":""string""},
""hobbies"":{""type"":""string"",""required"":true},
""age"":{""type"":""integer"",""required"":true}
}
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(schemaJson)));
Assert.AreEqual(2, schema.Required.Count);
Assert.AreEqual("hobbies", schema.Required[0]);
Assert.AreEqual("age", schema.Required[1]);
}
示例12: AdditionalProperties
public void AdditionalProperties()
{
string json = @"{
""description"":""AdditionalProperties"",
""type"":[""string"", ""integer""],
""additionalProperties"":{""type"":[""object"", ""boolean""]}
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("AdditionalProperties", schema.Description);
Assert.AreEqual(JSchemaType.Object | JSchemaType.Boolean, schema.AdditionalProperties.Type);
}
示例13: Extends
public void Extends()
{
string json = @"{
""extends"": [{""type"":""string""},{""type"":""null""}],
""description"":""Extends""
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Extends", schema.Description);
Assert.AreEqual(JSchemaType.String, schema.AllOf[0].Type);
Assert.AreEqual(JSchemaType.Null, schema.AllOf[1].Type);
}
示例14: MultipleItems
public void MultipleItems()
{
string json = @"{
""description"":""MultipleItems"",
""type"":""array"",
""items"": [{""type"":""string""},{""type"":""array""}]
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("MultipleItems", schema.Description);
Assert.AreEqual(JSchemaType.String, schema.Items[0].Type);
Assert.AreEqual(JSchemaType.Array, schema.Items[1].Type);
}
示例15: Enum
public void Enum()
{
string json = @"{
""description"":""Type"",
""type"":[""string"",""array""],
""enum"":[""string"",""object"",""array"",""boolean"",""number"",""integer"",""null"",""any""]
}";
JSchemaReader schemaReader = new JSchemaReader(JSchemaDummyResolver.Instance);
JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Type", schema.Description);
Assert.AreEqual(JSchemaType.String | JSchemaType.Array, schema.Type);
Assert.AreEqual(8, schema.Enum.Count);
Assert.AreEqual("string", (string)schema.Enum[0]);
Assert.AreEqual("any", (string)schema.Enum[schema.Enum.Count - 1]);
}