diff options
author | Marc Butler <mockbutler@gmail.com> | 2020-03-13 06:10:30 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-12 12:10:30 -0700 |
commit | 0e3fdd0eeac998974179fd48874a2d98dbf9af83 (patch) | |
tree | 6de77eae5f782a665a4c580c9a8e4539cdfdc6b6 | |
parent | 45a2b07cbd83c14c233bafd0f7d850bc52f9aa24 (diff) | |
download | flatbuffers-0e3fdd0eeac998974179fd48874a2d98dbf9af83.tar.gz flatbuffers-0e3fdd0eeac998974179fd48874a2d98dbf9af83.tar.bz2 flatbuffers-0e3fdd0eeac998974179fd48874a2d98dbf9af83.zip |
Escape characters in jsonschema descriptions (#5644)
* Escape JSON Schema comments
* Add quotes to monster comment
Thus exercising the JSON Schema comment escape support.
-rw-r--r-- | src/idl_gen_json_schema.cpp | 7 | ||||
-rw-r--r-- | tests/MyGame/Example/Monster.cs | 2 | ||||
-rw-r--r-- | tests/MyGame/Example/Monster.go | 2 | ||||
-rw-r--r-- | tests/MyGame/Example/Monster.java | 2 | ||||
-rw-r--r-- | tests/MyGame/Example/Monster.kt | 2 | ||||
-rw-r--r-- | tests/MyGame/Example/Monster.lua | 2 | ||||
-rw-r--r-- | tests/MyGame/Example/Monster.php | 2 | ||||
-rw-r--r-- | tests/MyGame/Example/Monster.py | 2 | ||||
-rw-r--r-- | tests/cpp17/generated_cpp17/monster_test_generated.h | 2 | ||||
-rw-r--r-- | tests/monster_test.bfbs | bin | 12176 -> 12176 bytes | |||
-rw-r--r-- | tests/monster_test.fbs | 2 | ||||
-rw-r--r-- | tests/monster_test.schema.json | 2 | ||||
-rw-r--r-- | tests/monster_test_bfbs_generated.h | 6 | ||||
-rw-r--r-- | tests/monster_test_generated.h | 2 | ||||
-rw-r--r-- | tests/monster_test_generated.js | 2 | ||||
-rw-r--r-- | tests/monster_test_generated.lobster | 2 | ||||
-rw-r--r-- | tests/monster_test_generated.rs | 2 | ||||
-rw-r--r-- | tests/monster_test_generated.ts | 2 | ||||
-rw-r--r-- | tests/monster_test_my_game.example_generated.dart | 2 |
19 files changed, 25 insertions, 20 deletions
diff --git a/src/idl_gen_json_schema.cpp b/src/idl_gen_json_schema.cpp index ecdb587b..a1d0704d 100644 --- a/src/idl_gen_json_schema.cpp +++ b/src/idl_gen_json_schema.cpp @@ -155,7 +155,12 @@ class JsonSchemaGenerator : public BaseGenerator { comment.append(*comment_line); } if (comment.size() > 0) { - code_ += " \"description\" : \"" + comment + "\","; + std::string description; + if (!EscapeString(comment.c_str(), comment.length(), &description, true, + true)) { + return false; + } + code_ += " \"description\" : " + description + ","; } code_ += " \"properties\" : {"; diff --git a/tests/MyGame/Example/Monster.cs b/tests/MyGame/Example/Monster.cs index 2faa6d7c..8531b14a 100644 --- a/tests/MyGame/Example/Monster.cs +++ b/tests/MyGame/Example/Monster.cs @@ -9,7 +9,7 @@ using global::System; using global::System.Collections.Generic; using global::FlatBuffers; -/// an example documentation comment: monster object +/// an example documentation comment: "monster object" public struct Monster : IFlatbufferObject { private Table __p; diff --git a/tests/MyGame/Example/Monster.go b/tests/MyGame/Example/Monster.go index 7ef41e36..7db88a9c 100644 --- a/tests/MyGame/Example/Monster.go +++ b/tests/MyGame/Example/Monster.go @@ -8,7 +8,7 @@ import ( MyGame "MyGame" ) -/// an example documentation comment: monster object +/// an example documentation comment: "monster object" type MonsterT struct { Pos *Vec3T Mana int16 diff --git a/tests/MyGame/Example/Monster.java b/tests/MyGame/Example/Monster.java index 465d68a4..d1d66398 100644 --- a/tests/MyGame/Example/Monster.java +++ b/tests/MyGame/Example/Monster.java @@ -9,7 +9,7 @@ import com.google.flatbuffers.*; @SuppressWarnings("unused") /** - * an example documentation comment: monster object + * an example documentation comment: "monster object" */ public final class Monster extends Table { public static void ValidateVersion() { Constants.FLATBUFFERS_1_11_1(); } diff --git a/tests/MyGame/Example/Monster.kt b/tests/MyGame/Example/Monster.kt index b284c7ac..14552734 100644 --- a/tests/MyGame/Example/Monster.kt +++ b/tests/MyGame/Example/Monster.kt @@ -7,7 +7,7 @@ import kotlin.math.sign import com.google.flatbuffers.* /** - * an example documentation comment: monster object + * an example documentation comment: "monster object" */ @Suppress("unused") @ExperimentalUnsignedTypes diff --git a/tests/MyGame/Example/Monster.lua b/tests/MyGame/Example/Monster.lua index 07f69fcb..8f82d9de 100644 --- a/tests/MyGame/Example/Monster.lua +++ b/tests/MyGame/Example/Monster.lua @@ -4,7 +4,7 @@ local flatbuffers = require('flatbuffers') --- an example documentation comment: monster object +-- an example documentation comment: "monster object" local Monster = {} -- the module local Monster_mt = {} -- the class metatable diff --git a/tests/MyGame/Example/Monster.php b/tests/MyGame/Example/Monster.php index 6dbbde2e..a07ffcc6 100644 --- a/tests/MyGame/Example/Monster.php +++ b/tests/MyGame/Example/Monster.php @@ -8,7 +8,7 @@ use \Google\FlatBuffers\Table; use \Google\FlatBuffers\ByteBuffer; use \Google\FlatBuffers\FlatBufferBuilder; -/// an example documentation comment: monster object +/// an example documentation comment: "monster object" class Monster extends Table { /** diff --git a/tests/MyGame/Example/Monster.py b/tests/MyGame/Example/Monster.py index ff288d7f..641d038c 100644 --- a/tests/MyGame/Example/Monster.py +++ b/tests/MyGame/Example/Monster.py @@ -6,7 +6,7 @@ import flatbuffers from flatbuffers.compat import import_numpy np = import_numpy() -# an example documentation comment: monster object +# an example documentation comment: "monster object" class Monster(object): __slots__ = ['_tab'] diff --git a/tests/cpp17/generated_cpp17/monster_test_generated.h b/tests/cpp17/generated_cpp17/monster_test_generated.h index 928d8dd0..359fd1a9 100644 --- a/tests/cpp17/generated_cpp17/monster_test_generated.h +++ b/tests/cpp17/generated_cpp17/monster_test_generated.h @@ -1043,7 +1043,7 @@ struct MonsterT : public flatbuffers::NativeTable { } }; -/// an example documentation comment: monster object +/// an example documentation comment: "monster object" struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef MonsterT NativeTableType; typedef MonsterBuilder Builder; diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs Binary files differindex 51af3549..84f24470 100644 --- a/tests/monster_test.bfbs +++ b/tests/monster_test.bfbs diff --git a/tests/monster_test.fbs b/tests/monster_test.fbs index 4a3b9a86..094de8ca 100644 --- a/tests/monster_test.fbs +++ b/tests/monster_test.fbs @@ -66,7 +66,7 @@ table Referrable { id:ulong(key, hash:"fnv1a_64"); } -/// an example documentation comment: monster object +/// an example documentation comment: "monster object" table Monster { pos:Vec3 (id: 0); hp:short = 100 (id: 2); diff --git a/tests/monster_test.schema.json b/tests/monster_test.schema.json index b70f647a..0c7d30de 100644 --- a/tests/monster_test.schema.json +++ b/tests/monster_test.schema.json @@ -147,7 +147,7 @@ }, "MyGame_Example_Monster" : { "type" : "object", - "description" : " an example documentation comment: monster object", + "description" : " an example documentation comment: \"monster object\"", "properties" : { "pos" : { "$ref" : "#/definitions/MyGame_Example_Vec3" diff --git a/tests/monster_test_bfbs_generated.h b/tests/monster_test_bfbs_generated.h index 27b0cec0..07acbe42 100644 --- a/tests/monster_test_bfbs_generated.h +++ b/tests/monster_test_bfbs_generated.h @@ -167,10 +167,10 @@ struct MonsterBinarySchema { 0x02,0x00,0x00,0x00,0x75,0x38,0x00,0x00,0x5E,0xDD,0xFF,0xFF,0x00,0x00,0x04,0x00,0x18,0x00,0x00,0x00, 0x0C,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x9A,0xDC,0xFF,0xFF,0x00,0x00,0x00,0x03, 0x02,0x00,0x00,0x00,0x69,0x38,0x00,0x00,0xDA,0xDD,0xFF,0xFF,0x18,0x01,0x00,0x00,0x4C,0x00,0x00,0x00, - 0x01,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x31,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x33,0x00,0x00,0x00, 0x20,0x61,0x6E,0x20,0x65,0x78,0x61,0x6D,0x70,0x6C,0x65,0x20,0x64,0x6F,0x63,0x75,0x6D,0x65,0x6E,0x74, - 0x61,0x74,0x69,0x6F,0x6E,0x20,0x63,0x6F,0x6D,0x6D,0x65,0x6E,0x74,0x3A,0x20,0x6D,0x6F,0x6E,0x73,0x74, - 0x65,0x72,0x20,0x6F,0x62,0x6A,0x65,0x63,0x74,0x00,0x00,0x00,0x31,0x00,0x00,0x00,0xC0,0x01,0x00,0x00, + 0x61,0x74,0x69,0x6F,0x6E,0x20,0x63,0x6F,0x6D,0x6D,0x65,0x6E,0x74,0x3A,0x20,0x22,0x6D,0x6F,0x6E,0x73, + 0x74,0x65,0x72,0x20,0x6F,0x62,0x6A,0x65,0x63,0x74,0x22,0x00,0x31,0x00,0x00,0x00,0xC0,0x01,0x00,0x00, 0x1C,0x02,0x00,0x00,0x7C,0x02,0x00,0x00,0xD4,0x02,0x00,0x00,0xB0,0x06,0x00,0x00,0x90,0x17,0x00,0x00, 0xEC,0x14,0x00,0x00,0x04,0x0C,0x00,0x00,0x78,0x18,0x00,0x00,0xD8,0x19,0x00,0x00,0xF8,0x17,0x00,0x00, 0x48,0x1A,0x00,0x00,0x2C,0x19,0x00,0x00,0x34,0x04,0x00,0x00,0x6C,0x0A,0x00,0x00,0xB0,0x1A,0x00,0x00, diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index b0512a26..ad87ffe3 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -1269,7 +1269,7 @@ inline bool operator!=(const MonsterT &lhs, const MonsterT &rhs) { } -/// an example documentation comment: monster object +/// an example documentation comment: "monster object" struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef MonsterT NativeTableType; typedef MonsterBuilder Builder; diff --git a/tests/monster_test_generated.js b/tests/monster_test_generated.js index 3ea7a3cd..bc7db45b 100644 --- a/tests/monster_test_generated.js +++ b/tests/monster_test_generated.js @@ -985,7 +985,7 @@ MyGame.Example.Referrable.createReferrable = function(builder, id) { } /** - * an example documentation comment: monster object + * an example documentation comment: "monster object" * * @constructor */ diff --git a/tests/monster_test_generated.lobster b/tests/monster_test_generated.lobster index 74c5967a..d56aef4b 100644 --- a/tests/monster_test_generated.lobster +++ b/tests/monster_test_generated.lobster @@ -208,7 +208,7 @@ struct ReferrableBuilder: def end(): return b_.EndObject() -/// an example documentation comment: monster object +/// an example documentation comment: "monster object" class Monster : flatbuffers_handle def pos(): let o = buf_.flatbuffers_field_struct(pos_, 4) diff --git a/tests/monster_test_generated.rs b/tests/monster_test_generated.rs index af275dbc..528505c3 100644 --- a/tests/monster_test_generated.rs +++ b/tests/monster_test_generated.rs @@ -1028,7 +1028,7 @@ impl<'a: 'b, 'b> ReferrableBuilder<'a, 'b> { pub enum MonsterOffset {} #[derive(Copy, Clone, Debug, PartialEq)] -/// an example documentation comment: monster object +/// an example documentation comment: "monster object" pub struct Monster<'a> { pub _tab: flatbuffers::Table<'a>, } diff --git a/tests/monster_test_generated.ts b/tests/monster_test_generated.ts index 3ac61785..414bedbb 100644 --- a/tests/monster_test_generated.ts +++ b/tests/monster_test_generated.ts @@ -838,7 +838,7 @@ static createReferrable(builder:flatbuffers.Builder, id:flatbuffers.Long):flatbu } } /** - * an example documentation comment: monster object + * an example documentation comment: "monster object" * * @constructor */ diff --git a/tests/monster_test_my_game.example_generated.dart b/tests/monster_test_my_game.example_generated.dart index 427b5e91..2ad2c952 100644 --- a/tests/monster_test_my_game.example_generated.dart +++ b/tests/monster_test_my_game.example_generated.dart @@ -717,7 +717,7 @@ class ReferrableObjectBuilder extends fb.ObjectBuilder { return fbBuilder.finish(offset, fileIdentifier); } } -/// an example documentation comment: monster object +/// an example documentation comment: "monster object" class Monster { Monster._(this._bc, this._bcOffset); factory Monster(List<int> bytes) { |