mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-09 22:56:27 +00:00
Add support for fixed-size arrays (#5313)
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
0d2cebccfe
commit
e635141d5b
@@ -42,6 +42,7 @@ std::string GenNativeType(BaseType type) {
|
||||
case BASE_TYPE_FLOAT:
|
||||
case BASE_TYPE_DOUBLE: return "number";
|
||||
case BASE_TYPE_STRING: return "string";
|
||||
case BASE_TYPE_ARRAY: return "array";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
@@ -70,6 +71,7 @@ std::string GenType(const Type &type) {
|
||||
return GenTypeRef(type.enum_def);
|
||||
}
|
||||
switch (type.base_type) {
|
||||
case BASE_TYPE_ARRAY: FLATBUFFERS_FALLTHROUGH(); // fall thru
|
||||
case BASE_TYPE_VECTOR: {
|
||||
std::string typeline;
|
||||
typeline.append("\"type\" : \"array\", \"items\" : { ");
|
||||
@@ -156,8 +158,16 @@ class JsonSchemaGenerator : public BaseGenerator {
|
||||
const auto &properties = structure->fields.vec;
|
||||
for (auto prop = properties.cbegin(); prop != properties.cend(); ++prop) {
|
||||
const auto &property = *prop;
|
||||
std::string typeLine(" \"" + property->name + "\" : { " +
|
||||
GenType(property->value.type) + " }");
|
||||
std::string arrayInfo = "";
|
||||
if (IsArray(property->value.type)) {
|
||||
arrayInfo = ",\n \"minItems\": " +
|
||||
NumToString(property->value.type.fixed_length) +
|
||||
",\n \"maxItems\": " +
|
||||
NumToString(property->value.type.fixed_length);
|
||||
}
|
||||
std::string typeLine =
|
||||
" \"" + property->name + "\" : {\n" + " " +
|
||||
GenType(property->value.type) + arrayInfo + "\n }";
|
||||
if (property != properties.back()) { typeLine.append(","); }
|
||||
code_ += typeLine;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user