Пример #1
0
        public void SchemaBuilder_includes_default_value_for_nullable_value_types()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : [""integer"", ""null""],
                        ""default"" : null
                    }},
                    ""property2"" : {{
                        ""type"" : [""integer"", ""null""],
                        ""default"" : 23
                    }}
                }}
            }}");


            var modelInstance = new Class12()
            {
                Property1 = null,
                Property2 = 23
            };

            // ACT
            var schema = JsonSchemaGenerator.GetSchema(modelInstance);

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #2
0
        public void SchemaBuilder_returns_expected_schema_for_properties_of_primitive_types()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : ""string""
                    }},
                    ""property2"" : {{
                        ""type"" : ""integer""
                    }},
                    ""property3"" : {{
                        ""type"" : [ ""integer"", ""null"" ]
                    }},
                    ""property4"" : {{
                        ""type"" : ""boolean""
                    }},
                    ""property5"" : {{
                        ""type"" : [ ""boolean"", ""null"" ]
                    }}
                }}
            }}");

            // ACT
            var schema = JsonSchemaGenerator.GetSchema <Class2>();

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #3
0
        public void SchemaBuilder_includes_default_value_for_enum_properties()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : ""string"",
                        ""enum"" : [
                            ""Value1"",
                            ""Value2""
                        ],
                        ""default"" : ""Value2""
                    }}
                }}
            }}");

            var modelInstance = new Class10()
            {
                Property1 = Enum1.Value2
            };

            // ACT
            var schema = JsonSchemaGenerator.GetSchema(modelInstance);

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #4
0
        public void SchemaBuilder_returns_expected_schema_for_nullable_enum_properties()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : ""string"",
                        ""enum"" : [
                            ""Value1"",
                            ""Value2"",
                            null
                        ]
                    }},
                    ""property2"" : {{
                        ""type"" : ""string"",
                        ""enum"" : [
                            ""Value1"",
                            ""Value2"",
                            null
                        ]
                    }}
                }}
            }}");

            // ACT
            var schema = JsonSchemaGenerator.GetSchema <Class11>();

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #5
0
        public void SchemaBuilder_returns_expected_schema_for_dictionary_properties_01()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : ""object"",
                        ""patternProperties"" : {{
                            "".*"" : {{
                                ""type"" : ""string""
                            }}
                        }}
                    }},
                    ""property2"" : {{
                        ""type"" : ""object"",
                        ""patternProperties"" : {{
                            "".*"" : {{
                                ""type"" : ""string""
                            }}
                        }}
                    }}
                }}
            }}");

            // ACT
            var schema = JsonSchemaGenerator.GetSchema <Class6>();

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #6
0
        public void SchemaBuilder_includes_default_values_for_objects()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property"" : {{
                        ""type"" : ""object"",
                        ""properties"" : {{
                            ""property1"" : {{
                                ""type"" : ""string""
                            }}
                        }},
                        ""default"" : {{
                            ""property1"" : ""some-string""
                        }}
                    }}
                }}
            }}");

            var modelInstance = new Class4()
            {
                Property = new Class5()
                {
                    Property1 = "some-string"
                }
            };

            // ACT
            var schema = JsonSchemaGenerator.GetSchema(modelInstance);

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #7
0
        public void SchemaBuilder_includes_default_values_for_arrays()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : ""array"",
                        ""items"" : {{
                            ""type"" : ""string""
                        }},
                        ""default"" : [""abc"", ""def""]
                    }},
                    ""property2"" : {{
                        ""type"" : ""array"",
                        ""items"" : {{
                            ""type"" : ""integer""
                        }}
                    }}
                }}
            }}");

            var modelInstance = new Class3()
            {
                Property1 = new[] { "abc", "def" }
            };

            // ACT
            var schema = JsonSchemaGenerator.GetSchema(modelInstance);

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #8
0
        public void SchemaBuilder_returns_expected_schema_for_arrays()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : ""array"",
                        ""items"" : {{
                            ""type"" : ""string""
                        }}
                    }},
                    ""property2"" : {{
                        ""type"" : ""array"",
                        ""items"" : {{
                            ""type"" : ""integer""
                        }}
                    }}
                }}
            }}");

            // ACT
            var schema = JsonSchemaGenerator.GetSchema <Class3>();

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #9
0
        public void SchemaBuilder_includes_individual_default_values_for_dictionary_properties_01()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : ""object"",                        
                        ""patternProperties"" : {{
                            "".*"" : {{
                                ""type"" : ""string""
                            }}
                        }},
                        ""properties"" : {{
                            ""key1"" : {{
                                ""type"" : ""string"",
                                ""default"" : ""value1""
                            }},
                            ""key2"" : {{
                                ""type"" : ""string"" ,
                                ""default"" : ""value2""
                            }}
                        }}
                    }},
                    ""property2"" : {{
                        ""type"" : ""object"",                        
                        ""patternProperties"" : {{
                            "".*"" : {{
                                ""type"" : ""string""
                            }}
                        }}
                    }}
                }}
            }}");

            var modelInstance = new Class6()
            {
                Property1 = new Dictionary <string, string>()
                {
                    { "key1", "value1" },
                    { "key2", "value2" }
                },
                // Property2's value should not be included in the schema, because it has no JsonSchemaDefaultValue attribute
                Property2 = new Dictionary <string, string>()
                {
                    { "key1", "value1" },
                }
            };

            // ACT
            var schema = JsonSchemaGenerator.GetSchema(modelInstance);

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #10
0
        public void SchemaBuilder_returns_expected_schema_for_empty_class()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object""
            }}");

            // ACT
            var schema = JsonSchemaGenerator.GetSchema <Class1>();

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #11
0
        public void SchemaBuilder_ignores_properties_with_a_JsonSchemaIgnore_attribute()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : ""string""
                    }}
                }}
            }}");

            // ACT
            var schema = JsonSchemaGenerator.GetSchema <Class15>();

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #12
0
        public void SchemaBuilder_includes_title_specified_using_a_SettingDisplayName_attribute()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""title"" : ""Property Title"",
                        ""type"" : ""string""
                    }}
                }}
            }}");

            // ACT
            var schema = JsonSchemaGenerator.GetSchema <Class16>();

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #13
0
        public void SchemaBuilder_includes_default_values_for_primitive_properties_with_a_JsonSchemaDefaultValue_attribute()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : ""string"",
                        ""default"" : ""some-string""
                    }},
                    ""property2"" : {{
                        ""type"" : ""integer"",
                        ""default"": 23
                    }},
                    ""property3"" : {{
                        ""type"" : [""integer"", ""null"" ],
                        ""default"" : 42
                    }},
                    ""property4"" : {{
                        ""type"" : ""boolean""
                    }},
                    ""property5"" : {{
                        ""type"" : [ ""boolean"", ""null"" ]
                    }}
                }}
            }}");

            var modelInstance = new Class2()
            {
                Property1 = "some-string",
                Property2 = 23,
                Property3 = 42
            };

            // ACT
            var schema = JsonSchemaGenerator.GetSchema(modelInstance);

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #14
0
        public void SchemaBuilder_includes_unique_items_setting_if_a_property_has_a_JsonSchemaUniqueItems_attribute()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : ""array"",
                        ""items"" : {{
                            ""type"": ""string""
                        }},
                        ""uniqueItems"" : true
                    }},
                    ""property2"" : {{
                        ""type"" : ""array"",
                        ""items"" : {{
                            ""type"": ""integer""
                        }},
                        ""uniqueItems"" : true
                    }},
                    ""property3"" : {{
                        ""type"" : ""array"",
                        ""items"" : {{
                            ""type"": ""integer""
                        }}
                    }},
                    ""property4"" : {{
                        ""type"" : ""integer""
                    }}
                }}
            }}");


            // ACT
            var schema = JsonSchemaGenerator.GetSchema <Class13>();

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #15
0
        public void SchemaBuilder_includes_null_as_possible_value_for_nullable_reference_types_02()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : [ ""string"", ""null"" ]
                    }},
                    ""property2"" : {{
                        ""type"" : [ ""string"", ""null"" ]
                    }}
                }}
            }}");

            // ACT
            var schema = JsonSchemaGenerator.GetSchema <Class18>();

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #16
0
        public void SchemaBuilder_returns_expected_schema_for_nullable_value_types()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : [""integer"", ""null""]
                    }},
                    ""property2"" : {{
                        ""type"" : [""integer"", ""null""]
                    }}
                }}
            }}");

            // ACT

            var schema = JsonSchemaGenerator.GetSchema <Class12>();

            // ASSERT
            AssertEqual(expected, schema);
        }
Пример #17
0
        public void SchemaBuilder_does_not_include_default_value_for_empty_dictionaries()
        {
            // ARRANGE
            var expected = JObject.Parse($@"{{
                ""$schema"" : ""{s_SchemaNamespace}"",
                ""type"" : ""object"",
                ""properties"" : {{
                    ""property1"" : {{
                        ""type"" : ""object"",                        
                        ""patternProperties"" : {{
                            "".*"" : {{
                                ""type"" : ""string""
                            }}
                        }}
                    }},
                    ""property2"" : {{
                        ""type"" : ""object"",                        
                        ""patternProperties"" : {{
                            "".*"" : {{
                                ""type"" : ""string""
                            }}
                        }}
                    }}
                }}
            }}");

            var modelInstance = new Class6()
            {
                Property1 = new Dictionary <string, string>()
            };

            // ACT
            var schema = JsonSchemaGenerator.GetSchema(modelInstance);

            // ASSERT
            AssertEqual(expected, schema);
        }