support deprecated flag in json schema (#6022)
authorDmitry <Captfrozenberg@gmail.com>
Thu, 16 Jul 2020 20:49:42 +0000 (23:49 +0300)
committerGitHub <noreply@github.com>
Thu, 16 Jul 2020 20:49:42 +0000 (13:49 -0700)
src/idl_gen_json_schema.cpp
tests/arrays_test.schema.json
tests/monster_test.schema.json

index a1d0704dd7b74a3de55659570536d6afb4865c96..e1125d10f98e4f2e606fbc9deed038d3b20bb411 100644 (file)
@@ -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;
       }
index 1ef5110da3b61914713449015419ea05945a28b0..8c77dd13469ad83b0b341592c95e440cff983d62 100644 (file)
@@ -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",
index 0c7d30de9a151507146b7a95ab9ab19ad31bd07c..e4ce0df7adf9271305e27a8bbf8e1c109ab55b18 100644 (file)
@@ -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",
                 "type" : "string"
               },
         "friendly" : {
-                "type" : "boolean"
+                "type" : "boolean",
+                "deprecated" : true,
               },
         "inventory" : {
                 "type" : "array", "items" : { "type" : "number" }