Skip to content

Commit f223bd3

Browse files
cwe-dixaJens-G
authored andcommitted
Improve enum support for json generator
Client: [json]
1 parent b39370e commit f223bd3

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

compiler/cpp/src/thrift/generate/t_json_generator.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void t_json_generator::end_array() {
245245

246246
void t_json_generator::write_type_spec_object(const char* name, t_type* ttype) {
247247
ttype = ttype->get_true_type();
248-
if (ttype->is_struct() || ttype->is_xception() || ttype->is_container()) {
248+
if (ttype->is_struct() || ttype->is_xception() || ttype->is_container() || ttype->is_enum()) {
249249
write_key_and(name);
250250
start_object(NO_INDENT);
251251
write_key_and("typeId");
@@ -275,7 +275,7 @@ void t_json_generator::write_type_spec(t_type* ttype) {
275275
end_object();
276276
}
277277

278-
if (ttype->is_struct() || ttype->is_xception()) {
278+
if (ttype->is_struct() || ttype->is_xception() || ttype->is_enum()) {
279279
write_key_and_string("class", get_qualified_name(ttype));
280280
} else if (ttype->is_map()) {
281281
t_type* ktype = ((t_map*)ttype)->get_key_type();
@@ -780,7 +780,7 @@ string t_json_generator::get_type_name(t_type* ttype) {
780780
return "map";
781781
}
782782
if (ttype->is_enum()) {
783-
return "i32";
783+
return "enum";
784784
}
785785
if (ttype->is_struct()) {
786786
return ((t_struct*)ttype)->is_union() ? "union" : "struct";

lib/json/schema.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"union",
2424
"struct",
2525
"binary",
26-
"uuid"
26+
"uuid",
27+
"enum"
2728
]
2829
},
2930
"base-type": {
@@ -67,7 +68,7 @@
6768
"type": "object",
6869
"properties": {
6970
"typeId": {
70-
"enum": [ "union", "struct", "exception" ]
71+
"enum": [ "union", "struct", "exception", "enum" ]
7172
}
7273
},
7374
"required": [ "typeId", "class" ]

0 commit comments

Comments
 (0)