From 6942704f2b4ce42aa64f371e4937f410437faf13 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 16 Jul 2020 23:49:42 +0300 Subject: [PATCH] support deprecated flag in json schema (#6022) --- src/idl_gen_json_schema.cpp | 13 ++++++++++--- tests/arrays_test.schema.json | 2 +- tests/monster_test.schema.json | 5 +++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/idl_gen_json_schema.cpp b/src/idl_gen_json_schema.cpp index a1d0704d..e1125d10 100644 --- a/src/idl_gen_json_schema.cpp +++ b/src/idl_gen_json_schema.cpp @@ -127,7 +127,7 @@ class JsonSchemaGenerator : public BaseGenerator { if (parser_.root_struct_def_ == nullptr) { return false; } code_.Clear(); code_ += "{"; - code_ += " \"$schema\": \"http://json-schema.org/draft-04/schema#\","; + code_ += " \"$schema\": \"https://json-schema.org/draft/2019-09/schema\","; code_ += " \"definitions\": {"; for (auto e = parser_.enums_.vec.cbegin(); e != parser_.enums_.vec.cend(); ++e) { @@ -174,9 +174,16 @@ class JsonSchemaGenerator : public BaseGenerator { ",\n \"maxItems\": " + NumToString(property->value.type.fixed_length); } + std::string deprecated_info = ""; + if (property->deprecated) { + deprecated_info = ",\n \"deprecated\" : true,"; + } std::string typeLine = - " \"" + property->name + "\" : {\n" + " " + - GenType(property->value.type) + arrayInfo + "\n }"; + " \"" + property->name + "\" : {\n" + " "; + typeLine += GenType(property->value.type); + typeLine += arrayInfo; + typeLine += deprecated_info; + typeLine += "\n }"; if (property != properties.back()) { typeLine.append(","); } code_ += typeLine; } diff --git a/tests/arrays_test.schema.json b/tests/arrays_test.schema.json index 1ef5110d..8c77dd13 100644 --- a/tests/arrays_test.schema.json +++ b/tests/arrays_test.schema.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "https://json-schema.org/draft/2019-09/schema", "definitions": { "MyGame_Example_TestEnum" : { "type" : "string", diff --git a/tests/monster_test.schema.json b/tests/monster_test.schema.json index 0c7d30de..e4ce0df7 100644 --- a/tests/monster_test.schema.json +++ b/tests/monster_test.schema.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "https://json-schema.org/draft/2019-09/schema", "definitions": { "MyGame_OtherNameSpace_FromInclude" : { "type" : "string", @@ -162,7 +162,8 @@ "type" : "string" }, "friendly" : { - "type" : "boolean" + "type" : "boolean", + "deprecated" : true, }, "inventory" : { "type" : "array", "items" : { "type" : "number" } -- 2.34.1