当前位置: 首页>>代码示例>>C#>>正文


C# JSchemaReader.ReadRoot方法代码示例

本文整理汇总了C#中JSchemaReader.ReadRoot方法的典型用法代码示例。如果您正苦于以下问题:C# JSchemaReader.ReadRoot方法的具体用法?C# JSchemaReader.ReadRoot怎么用?C# JSchemaReader.ReadRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSchemaReader的用法示例。


在下文中一共展示了JSchemaReader.ReadRoot方法的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);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:13,代码来源:JSchemaReaderTests.cs

示例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);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:20,代码来源:JSchemaReaderTests.cs

示例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.");
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:16,代码来源:JSchemaReaderTests.cs

示例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);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:14,代码来源:JSchemaReaderTests.cs

示例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"]);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:14,代码来源:JSchemaReaderTests.cs

示例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]);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:30,代码来源:JSchemaReaderTests.cs

示例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);
            }
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:24,代码来源:JSchemaReaderTests.cs

示例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);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:13,代码来源:JSchemaReaderTests.cs

示例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);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:13,代码来源:JSchemaReaderTests.cs

示例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);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:13,代码来源:JSchemaReaderTests.cs

示例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]);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:20,代码来源:JSchemaReaderTests.cs

示例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);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:14,代码来源:JSchemaReaderTests.cs

示例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);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:14,代码来源:JSchemaReaderTests.cs

示例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);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:15,代码来源:JSchemaReaderTests.cs

示例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]);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:18,代码来源:JSchemaReaderTests.cs


注:本文中的JSchemaReader.ReadRoot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。