diff --git a/src/idl_gen_json_schema.cpp b/src/idl_gen_json_schema.cpp index e519415dd..7f98a6e6a 100644 --- a/src/idl_gen_json_schema.cpp +++ b/src/idl_gen_json_schema.cpp @@ -175,13 +175,14 @@ class JsonSchemaGenerator : public BaseGenerator { } code_ += typeLine; } + code_ += " },"; // close properties + std::vector requiredProperties; std::copy_if(properties.begin(), properties.end(), back_inserter(requiredProperties), [](FieldDef const *prop) { return prop->required; }); if (requiredProperties.size() > 0) { - code_ += " },"; // close properties - std::string required_string(" \"required\" : [ "); + std::string required_string(" \"required\" : ["); for (auto req_prop = requiredProperties.cbegin(); req_prop != requiredProperties.cend(); ++req_prop) { @@ -190,12 +191,10 @@ class JsonSchemaGenerator : public BaseGenerator { required_string.append(", "); } } - required_string.append("]"); + required_string.append("],"); code_ += required_string; - } else { - code_ += " }"; // close properties } - + code_ += " \"additionalProperties\" : false"; std::string closeType(" }"); if (*s != parser_.structs_.vec.back()) { closeType.append(","); diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index 843e308c5..15d399862 100644 Binary files a/tests/monster_test.bfbs and b/tests/monster_test.bfbs differ diff --git a/tests/monster_test.schema.json b/tests/monster_test.schema.json index 578e89645..62880abbc 100644 --- a/tests/monster_test.schema.json +++ b/tests/monster_test.schema.json @@ -16,42 +16,49 @@ "MyGame_OtherNameSpace_Unused" : { "type" : "object", "properties" : { - } + }, + "additionalProperties" : false }, "MyGame_OtherNameSpace_TableB" : { "type" : "object", "properties" : { "a" : { "$ref" : "#/definitions/TableA" } - } + }, + "additionalProperties" : false }, "TableA" : { "type" : "object", "properties" : { "b" : { "$ref" : "#/definitions/MyGame_OtherNameSpace_TableB" } - } + }, + "additionalProperties" : false }, "MyGame_InParentNamespace" : { "type" : "object", "properties" : { - } + }, + "additionalProperties" : false }, "MyGame_Example2_Monster" : { "type" : "object", "properties" : { - } + }, + "additionalProperties" : false }, "MyGame_Example_Test" : { "type" : "object", "properties" : { "a" : { "type" : "number" }, "b" : { "type" : "number" } - } + }, + "additionalProperties" : false }, "MyGame_Example_TestSimpleTableWithEnum" : { "type" : "object", "properties" : { "color" : { "$ref" : "#/definitions/MyGame_Example_Color" } - } + }, + "additionalProperties" : false }, "MyGame_Example_Vec3" : { "type" : "object", @@ -62,14 +69,16 @@ "test1" : { "type" : "number" }, "test2" : { "$ref" : "#/definitions/MyGame_Example_Color" }, "test3" : { "$ref" : "#/definitions/MyGame_Example_Test" } - } + }, + "additionalProperties" : false }, "MyGame_Example_Ability" : { "type" : "object", "properties" : { "id" : { "type" : "number" }, "distance" : { "type" : "number" } - } + }, + "additionalProperties" : false }, "MyGame_Example_Stat" : { "type" : "object", @@ -77,7 +86,8 @@ "id" : { "type" : "string" }, "val" : { "type" : "number" }, "count" : { "type" : "number" } - } + }, + "additionalProperties" : false }, "MyGame_Example_Monster" : { "type" : "object", @@ -119,7 +129,8 @@ "vector_of_doubles" : { "type" : "array", "items" : { "type" : "number" } }, "parent_namespace_test" : { "$ref" : "#/definitions/MyGame_InParentNamespace" } }, - "required" : [ "name"] + "required" : ["name"], + "additionalProperties" : false }, "MyGame_Example_TypeAliases" : { "type" : "object", @@ -136,7 +147,8 @@ "f64" : { "type" : "number" }, "v8" : { "type" : "array", "items" : { "type" : "number" } }, "vf64" : { "type" : "array", "items" : { "type" : "number" } } - } + }, + "additionalProperties" : false } }, "$ref" : "#/definitions/MyGame_Example_Monster"