diff options
author | Christian Westberg <cwe@dixa.com> | 2022-12-22 09:39:48 +0100 |
---|---|---|
committer | Jens Geyer <Jens-G@users.noreply.github.com> | 2023-01-16 22:37:17 +0100 |
commit | f223bd3b54d04c21289d806c7f51b115757703e7 (patch) | |
tree | c7161d8e1dbc3be3434b0844cac96e3e749e1e32 | |
parent | b39370ec3bc96d201bbc82fbde136f98ae605ed1 (diff) | |
download | thrift-f223bd3b54d04c21289d806c7f51b115757703e7.tar.gz |
Improve enum support for json generator
Client: [json]
-rw-r--r-- | compiler/cpp/src/thrift/generate/t_json_generator.cc | 6 | ||||
-rw-r--r-- | lib/json/schema.json | 5 |
2 files changed, 6 insertions, 5 deletions
diff --git a/compiler/cpp/src/thrift/generate/t_json_generator.cc b/compiler/cpp/src/thrift/generate/t_json_generator.cc index b94e81c08..e91d65ad5 100644 --- a/compiler/cpp/src/thrift/generate/t_json_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_json_generator.cc @@ -245,7 +245,7 @@ void t_json_generator::end_array() { void t_json_generator::write_type_spec_object(const char* name, t_type* ttype) { ttype = ttype->get_true_type(); - if (ttype->is_struct() || ttype->is_xception() || ttype->is_container()) { + if (ttype->is_struct() || ttype->is_xception() || ttype->is_container() || ttype->is_enum()) { write_key_and(name); start_object(NO_INDENT); write_key_and("typeId"); @@ -275,7 +275,7 @@ void t_json_generator::write_type_spec(t_type* ttype) { end_object(); } - if (ttype->is_struct() || ttype->is_xception()) { + if (ttype->is_struct() || ttype->is_xception() || ttype->is_enum()) { write_key_and_string("class", get_qualified_name(ttype)); } else if (ttype->is_map()) { t_type* ktype = ((t_map*)ttype)->get_key_type(); @@ -780,7 +780,7 @@ string t_json_generator::get_type_name(t_type* ttype) { return "map"; } if (ttype->is_enum()) { - return "i32"; + return "enum"; } if (ttype->is_struct()) { return ((t_struct*)ttype)->is_union() ? "union" : "struct"; diff --git a/lib/json/schema.json b/lib/json/schema.json index 90bb7a59d..f7b10dff4 100644 --- a/lib/json/schema.json +++ b/lib/json/schema.json @@ -23,7 +23,8 @@ "union", "struct", "binary", - "uuid" + "uuid", + "enum" ] }, "base-type": { @@ -67,7 +68,7 @@ "type": "object", "properties": { "typeId": { - "enum": [ "union", "struct", "exception" ] + "enum": [ "union", "struct", "exception", "enum" ] } }, "required": [ "typeId", "class" ] |