Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <iostream> |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 18 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 19 | #include "flatbuffers/code_generators.h" |
| 20 | #include "flatbuffers/idl.h" |
| 21 | #include "flatbuffers/util.h" |
| 22 | |
| 23 | namespace flatbuffers { |
| 24 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 25 | namespace jsons { |
| 26 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 27 | template<class T> std::string GenFullName(const T *enum_def) { |
| 28 | std::string full_name; |
| 29 | const auto &name_spaces = enum_def->defined_namespace->components; |
| 30 | for (auto ns = name_spaces.cbegin(); ns != name_spaces.cend(); ++ns) { |
| 31 | full_name.append(*ns + "_"); |
| 32 | } |
| 33 | full_name.append(enum_def->name); |
| 34 | return full_name; |
| 35 | } |
| 36 | |
| 37 | template<class T> std::string GenTypeRef(const T *enum_def) { |
| 38 | return "\"$ref\" : \"#/definitions/" + GenFullName(enum_def) + "\""; |
| 39 | } |
| 40 | |
| 41 | std::string GenType(const std::string &name) { |
| 42 | return "\"type\" : \"" + name + "\""; |
| 43 | } |
| 44 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 45 | std::string GenType(BaseType type) { |
| 46 | switch (type) { |
| 47 | case BASE_TYPE_BOOL: return "\"type\" : \"boolean\""; |
| 48 | case BASE_TYPE_CHAR: |
| 49 | return "\"type\" : \"integer\", \"minimum\" : " + |
| 50 | NumToString(std::numeric_limits<int8_t>::min()) + |
| 51 | ", \"maximum\" : " + |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame^] | 52 | NumToString(std::numeric_limits<int8_t>::max()); |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 53 | case BASE_TYPE_UCHAR: |
| 54 | return "\"type\" : \"integer\", \"minimum\" : 0, \"maximum\" :" + |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame^] | 55 | NumToString(std::numeric_limits<uint8_t>::max()); |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 56 | case BASE_TYPE_SHORT: |
| 57 | return "\"type\" : \"integer\", \"minimum\" : " + |
| 58 | NumToString(std::numeric_limits<int16_t>::min()) + |
| 59 | ", \"maximum\" : " + |
| 60 | NumToString(std::numeric_limits<int16_t>::max()); |
| 61 | case BASE_TYPE_USHORT: |
| 62 | return "\"type\" : \"integer\", \"minimum\" : 0, \"maximum\" : " + |
| 63 | NumToString(std::numeric_limits<uint16_t>::max()); |
| 64 | case BASE_TYPE_INT: |
| 65 | return "\"type\" : \"integer\", \"minimum\" : " + |
| 66 | NumToString(std::numeric_limits<int32_t>::min()) + |
| 67 | ", \"maximum\" : " + |
| 68 | NumToString(std::numeric_limits<int32_t>::max()); |
| 69 | case BASE_TYPE_UINT: |
| 70 | return "\"type\" : \"integer\", \"minimum\" : 0, \"maximum\" : " + |
| 71 | NumToString(std::numeric_limits<uint32_t>::max()); |
| 72 | case BASE_TYPE_LONG: |
| 73 | return "\"type\" : \"integer\", \"minimum\" : " + |
| 74 | NumToString(std::numeric_limits<int64_t>::min()) + |
| 75 | ", \"maximum\" : " + |
| 76 | NumToString(std::numeric_limits<int64_t>::max()); |
| 77 | case BASE_TYPE_ULONG: |
| 78 | return "\"type\" : \"integer\", \"minimum\" : 0, \"maximum\" : " + |
| 79 | NumToString(std::numeric_limits<uint64_t>::max()); |
| 80 | case BASE_TYPE_FLOAT: |
| 81 | case BASE_TYPE_DOUBLE: return "\"type\" : \"number\""; |
| 82 | case BASE_TYPE_STRING: return "\"type\" : \"string\""; |
| 83 | default: return ""; |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 84 | } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | std::string GenBaseType(const Type &type) { |
| 88 | if (type.struct_def != nullptr) { return GenTypeRef(type.struct_def); } |
| 89 | if (type.enum_def != nullptr) { return GenTypeRef(type.enum_def); } |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 90 | return GenType(type.base_type); |
| 91 | } |
| 92 | |
| 93 | std::string GenArrayType(const Type &type) { |
| 94 | std::string element_type; |
| 95 | if (type.struct_def != nullptr) { |
| 96 | element_type = GenTypeRef(type.struct_def); |
| 97 | } else if (type.enum_def != nullptr) { |
| 98 | element_type = GenTypeRef(type.enum_def); |
| 99 | } else { |
| 100 | element_type = GenType(type.element); |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 101 | } |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 102 | |
| 103 | return "\"type\" : \"array\", \"items\" : {" + element_type + "}"; |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | std::string GenType(const Type &type) { |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 107 | switch (type.base_type) { |
| 108 | case BASE_TYPE_ARRAY: FLATBUFFERS_FALLTHROUGH(); // fall thru |
| 109 | case BASE_TYPE_VECTOR: { |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 110 | return GenArrayType(type); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 111 | } |
| 112 | case BASE_TYPE_STRUCT: { |
| 113 | return GenTypeRef(type.struct_def); |
| 114 | } |
| 115 | case BASE_TYPE_UNION: { |
| 116 | std::string union_type_string("\"anyOf\": ["); |
| 117 | const auto &union_types = type.enum_def->Vals(); |
| 118 | for (auto ut = union_types.cbegin(); ut < union_types.cend(); ++ut) { |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 119 | const auto &union_type = *ut; |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 120 | if (union_type->union_type.base_type == BASE_TYPE_NONE) { continue; } |
| 121 | if (union_type->union_type.base_type == BASE_TYPE_STRUCT) { |
| 122 | union_type_string.append( |
| 123 | "{ " + GenTypeRef(union_type->union_type.struct_def) + " }"); |
| 124 | } |
| 125 | if (union_type != *type.enum_def->Vals().rbegin()) { |
| 126 | union_type_string.append(","); |
| 127 | } |
| 128 | } |
| 129 | union_type_string.append("]"); |
| 130 | return union_type_string; |
| 131 | } |
| 132 | case BASE_TYPE_UTYPE: return GenTypeRef(type.enum_def); |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 133 | default: { |
| 134 | return GenBaseType(type); |
| 135 | } |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | class JsonSchemaGenerator : public BaseGenerator { |
| 140 | private: |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 141 | std::string code_; |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 142 | |
| 143 | public: |
| 144 | JsonSchemaGenerator(const Parser &parser, const std::string &path, |
| 145 | const std::string &file_name) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 146 | : BaseGenerator(parser, path, file_name, "", "", "json") {} |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 147 | |
| 148 | explicit JsonSchemaGenerator(const BaseGenerator &base_generator) |
| 149 | : BaseGenerator(base_generator) {} |
| 150 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 151 | std::string GeneratedFileName(const std::string &path, |
| 152 | const std::string &file_name, |
| 153 | const IDLOptions &options /* unused */) const { |
| 154 | (void)options; |
| 155 | return path + file_name + ".schema.json"; |
| 156 | } |
| 157 | |
| 158 | // If indentation is less than 0, that indicates we don't want any newlines |
| 159 | // either. |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 160 | std::string NewLine() const { |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 161 | return parser_.opts.indent_step >= 0 ? "\n" : ""; |
| 162 | } |
| 163 | |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 164 | std::string Indent(int indent) const { |
| 165 | const auto num_spaces = indent * std::max(parser_.opts.indent_step, 0); |
| 166 | return std::string(num_spaces, ' '); |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 167 | } |
| 168 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame^] | 169 | std::string PrepareDescription( |
| 170 | const std::vector<std::string> &comment_lines) { |
| 171 | std::string comment; |
| 172 | for (auto line_iterator = comment_lines.cbegin(); |
| 173 | line_iterator != comment_lines.cend(); ++line_iterator) { |
| 174 | const auto &comment_line = *line_iterator; |
| 175 | |
| 176 | // remove leading and trailing spaces from comment line |
| 177 | const auto start = std::find_if(comment_line.begin(), comment_line.end(), |
| 178 | [](char c) { return !isspace(c); }); |
| 179 | const auto end = |
| 180 | std::find_if(comment_line.rbegin(), comment_line.rend(), [](char c) { |
| 181 | return !isspace(c); |
| 182 | }).base(); |
| 183 | if (start < end) { |
| 184 | comment.append(start, end); |
| 185 | } else { |
| 186 | comment.append(comment_line); |
| 187 | } |
| 188 | |
| 189 | if (line_iterator + 1 != comment_lines.cend()) comment.append("\n"); |
| 190 | } |
| 191 | if (!comment.empty()) { |
| 192 | std::string description; |
| 193 | if (EscapeString(comment.c_str(), comment.length(), &description, true, |
| 194 | true)) { |
| 195 | return description; |
| 196 | } |
| 197 | return ""; |
| 198 | } |
| 199 | return ""; |
| 200 | } |
| 201 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 202 | bool generate() { |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 203 | code_ = ""; |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame^] | 204 | if (parser_.root_struct_def_ == nullptr) { |
| 205 | std::cerr << "Error: Binary schema not generated, no root struct found\n"; |
| 206 | return false; |
| 207 | } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 208 | code_ += "{" + NewLine(); |
| 209 | code_ += Indent(1) + |
| 210 | "\"$schema\": \"https://json-schema.org/draft/2019-09/schema\"," + |
| 211 | NewLine(); |
| 212 | code_ += Indent(1) + "\"definitions\": {" + NewLine(); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 213 | for (auto e = parser_.enums_.vec.cbegin(); e != parser_.enums_.vec.cend(); |
| 214 | ++e) { |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 215 | code_ += Indent(2) + "\"" + GenFullName(*e) + "\" : {" + NewLine(); |
| 216 | code_ += Indent(3) + GenType("string") + "," + NewLine(); |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 217 | auto enumdef(Indent(3) + "\"enum\": ["); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 218 | for (auto enum_value = (*e)->Vals().begin(); |
| 219 | enum_value != (*e)->Vals().end(); ++enum_value) { |
| 220 | enumdef.append("\"" + (*enum_value)->name + "\""); |
| 221 | if (*enum_value != (*e)->Vals().back()) { enumdef.append(", "); } |
| 222 | } |
| 223 | enumdef.append("]"); |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 224 | code_ += enumdef + NewLine(); |
| 225 | code_ += Indent(2) + "}," + NewLine(); // close type |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 226 | } |
| 227 | for (auto s = parser_.structs_.vec.cbegin(); |
| 228 | s != parser_.structs_.vec.cend(); ++s) { |
| 229 | const auto &structure = *s; |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 230 | code_ += Indent(2) + "\"" + GenFullName(structure) + "\" : {" + NewLine(); |
| 231 | code_ += Indent(3) + GenType("object") + "," + NewLine(); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 232 | const auto &comment_lines = structure->doc_comment; |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame^] | 233 | auto comment = PrepareDescription(comment_lines); |
| 234 | if (comment != "") { |
| 235 | code_ += Indent(3) + "\"description\" : " + comment + "," + NewLine(); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 236 | } |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame^] | 237 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 238 | code_ += Indent(3) + "\"properties\" : {" + NewLine(); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 239 | |
| 240 | const auto &properties = structure->fields.vec; |
| 241 | for (auto prop = properties.cbegin(); prop != properties.cend(); ++prop) { |
| 242 | const auto &property = *prop; |
| 243 | std::string arrayInfo = ""; |
| 244 | if (IsArray(property->value.type)) { |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 245 | arrayInfo = "," + NewLine() + Indent(8) + "\"minItems\": " + |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 246 | NumToString(property->value.type.fixed_length) + "," + |
| 247 | NewLine() + Indent(8) + "\"maxItems\": " + |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 248 | NumToString(property->value.type.fixed_length); |
| 249 | } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 250 | std::string deprecated_info = ""; |
| 251 | if (property->deprecated) { |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 252 | deprecated_info = |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame^] | 253 | "," + NewLine() + Indent(8) + "\"deprecated\" : true"; |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 254 | } |
| 255 | std::string typeLine = Indent(4) + "\"" + property->name + "\""; |
| 256 | typeLine += " : {" + NewLine() + Indent(8); |
| 257 | typeLine += GenType(property->value.type); |
| 258 | typeLine += arrayInfo; |
| 259 | typeLine += deprecated_info; |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame^] | 260 | auto description = PrepareDescription(property->doc_comment); |
| 261 | if (description != "") { |
| 262 | typeLine += |
| 263 | "," + NewLine() + Indent(8) + "\"description\" : " + description; |
| 264 | } |
| 265 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 266 | typeLine += NewLine() + Indent(7) + "}"; |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 267 | if (property != properties.back()) { typeLine.append(","); } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 268 | code_ += typeLine + NewLine(); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 269 | } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 270 | code_ += Indent(3) + "}," + NewLine(); // close properties |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 271 | |
| 272 | std::vector<FieldDef *> requiredProperties; |
| 273 | std::copy_if(properties.begin(), properties.end(), |
| 274 | back_inserter(requiredProperties), |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame^] | 275 | [](FieldDef const *prop) { return prop->IsRequired(); }); |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 276 | if (!requiredProperties.empty()) { |
| 277 | auto required_string(Indent(3) + "\"required\" : ["); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 278 | for (auto req_prop = requiredProperties.cbegin(); |
| 279 | req_prop != requiredProperties.cend(); ++req_prop) { |
| 280 | required_string.append("\"" + (*req_prop)->name + "\""); |
| 281 | if (*req_prop != requiredProperties.back()) { |
| 282 | required_string.append(", "); |
| 283 | } |
| 284 | } |
| 285 | required_string.append("],"); |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 286 | code_ += required_string + NewLine(); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 287 | } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 288 | code_ += Indent(3) + "\"additionalProperties\" : false" + NewLine(); |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 289 | auto closeType(Indent(2) + "}"); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 290 | if (*s != parser_.structs_.vec.back()) { closeType.append(","); } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 291 | code_ += closeType + NewLine(); // close type |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 292 | } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 293 | code_ += Indent(1) + "}," + NewLine(); // close definitions |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 294 | |
| 295 | // mark root type |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 296 | code_ += Indent(1) + "\"$ref\" : \"#/definitions/" + |
| 297 | GenFullName(parser_.root_struct_def_) + "\"" + NewLine(); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 298 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 299 | code_ += "}" + NewLine(); // close schema root |
| 300 | return true; |
| 301 | } |
| 302 | |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 303 | bool save() const { |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame^] | 304 | const auto file_path = GeneratedFileName(path_, file_name_, parser_.opts); |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 305 | return SaveFile(file_path.c_str(), code_, false); |
| 306 | } |
| 307 | |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame] | 308 | const std::string getJson() { return code_; } |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 309 | }; |
| 310 | } // namespace jsons |
| 311 | |
| 312 | bool GenerateJsonSchema(const Parser &parser, const std::string &path, |
| 313 | const std::string &file_name) { |
| 314 | jsons::JsonSchemaGenerator generator(parser, path, file_name); |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 315 | if (!generator.generate()) { return false; } |
| 316 | return generator.save(); |
| 317 | } |
| 318 | |
| 319 | bool GenerateJsonSchema(const Parser &parser, std::string *json) { |
| 320 | jsons::JsonSchemaGenerator generator(parser, "", ""); |
| 321 | if (!generator.generate()) { return false; } |
| 322 | *json = generator.getJson(); |
| 323 | return true; |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 324 | } |
| 325 | } // namespace flatbuffers |