From bb736091f336de070d0fdee4ad06fe0fc9c8b3dd Mon Sep 17 00:00:00 2001 From: schoetbi Date: Thu, 31 Aug 2017 17:56:04 +0200 Subject: [PATCH] Every type gets additionalProperties set to "false" (#4424) #4423 --- src/idl_gen_json_schema.cpp | 11 +++++----- tests/monster_test.bfbs | Bin 5400 -> 4480 bytes 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 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 843e308c5204d9c36bad66ae49ac2d37041b4cce..15d39986259c8ed21e12dd8f9d0b096784f54c48 100644 GIT binary patch literal 4480 zcma)uk)%Y>l;}m9PX^bhQ$Kly$4d1YM{bPoFj0Vq;dYqLpmKM(G*hugcJ#V=g+nGNn3EjRi z{`Nw`Tu#S$wXM*pi!WD~qlsgy)#X+rnm7_)^tk)*K7?i=sVq59Mw~CQw*rk~lip>E zo_k()d64&KAuoF_l|4Cksu_2>QQNL3NwNq2ReY0d%+H?PkDSeA*(w>cQ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