Esempio n. 1
0
        public void PrimitiveProperties()
        {
            //// Arrange
            var data      = @"{
                int: 1, 
                str: ""abc"", 
                bool: true, 
                date: ""2012-07-19"", 
                datetime: ""2012-07-19 10:11:11"", 
                timespan: ""10:11:11""
            }";
            var generator = new SampleJsonSchemaGenerator();

            //// Act
            var schema = generator.Generate(data);
            var json   = schema.ToJson();

            //// Assert
            Assert.Equal(JsonObjectType.Integer, schema.Properties["int"].Type);
            Assert.Equal(JsonObjectType.String, schema.Properties["str"].Type);
            Assert.Equal(JsonObjectType.Boolean, schema.Properties["bool"].Type);

            Assert.Equal(JsonObjectType.String, schema.Properties["date"].Type);
            Assert.Equal(JsonFormatStrings.Date, schema.Properties["date"].Format);

            Assert.Equal(JsonObjectType.String, schema.Properties["datetime"].Type);
            Assert.Equal(JsonFormatStrings.DateTime, schema.Properties["datetime"].Format);

            Assert.Equal(JsonObjectType.String, schema.Properties["timespan"].Type);
            Assert.Equal(JsonFormatStrings.TimeSpan, schema.Properties["timespan"].Format);
        }
Esempio n. 2
0
        public void PrimitiveArrayProperty()
        {
            //// Arrange
            var data      = @"{
                array: [ 1, true ]
            }";
            var generator = new SampleJsonSchemaGenerator();

            //// Act
            var schema   = generator.Generate(data);
            var json     = schema.ToJson();
            var property = schema.Properties["array"].ActualTypeSchema;

            //// Assert
            Assert.Equal(JsonObjectType.Array, property.Type);
            Assert.Equal(JsonObjectType.Integer, property.Item.ActualSchema.Type);
        }
Esempio n. 3
0
        /// <summary>Creates a <see cref="JsonSchema4" /> from sample JSON data.</summary>
        /// <returns>The JSON Schema.</returns>
        public static JsonSchema4 FromSampleJson(string data)
        {
            var generator = new SampleJsonSchemaGenerator();

            return(generator.Generate(data));
        }