diff options
author | schoetbi <schoetbi@users.noreply.github.com> | 2017-08-31 17:56:04 +0200 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2017-08-31 08:56:04 -0700 |
commit | bb736091f336de070d0fdee4ad06fe0fc9c8b3dd (patch) | |
tree | c005d3d9eacf3624dfbf24177882cde115f0b7d0 | |
parent | d5b4db06922a9d81ab767abe3dfe2f54f267b8c2 (diff) | |
download | flatbuffers-bb736091f336de070d0fdee4ad06fe0fc9c8b3dd.tar.gz flatbuffers-bb736091f336de070d0fdee4ad06fe0fc9c8b3dd.tar.bz2 flatbuffers-bb736091f336de070d0fdee4ad06fe0fc9c8b3dd.zip |
Every type gets additionalProperties set to "false" (#4424)
#4423
-rw-r--r-- | src/idl_gen_json_schema.cpp | 11 | ||||
-rw-r--r-- | tests/monster_test.bfbs | bin | 5400 -> 4480 bytes | |||
-rw-r--r-- | tests/monster_test.schema.json | 36 |
3 files changed, 29 insertions, 18 deletions
diff --git a/src/idl_gen_json_schema.cpp b/src/idl_gen_json_schema.cpp index e519415d..7f98a6e6 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<FieldDef *> 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 Binary files differindex 843e308c..15d39986 100644 --- a/tests/monster_test.bfbs +++ b/tests/monster_test.bfbs diff --git a/tests/monster_test.schema.json b/tests/monster_test.schema.json index 578e8964..62880abb 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" |