Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
(fix/json) drop ArrayElement items without value nor fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanc committed Aug 10, 2018
1 parent 53e0e9a commit dae7430
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 14 deletions.
47 changes: 43 additions & 4 deletions src/refract/JsonValue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ namespace
void renderProperty(so::Object& obj, const ExtendElement& e, TypeAttributes options);
void renderProperty(so::Object& obj, const IElement& e, TypeAttributes options);

void renderItem(so::Array& obj, const RefElement& e, TypeAttributes options);
void renderItemSpecific(so::Array& obj, const RefElement& e, TypeAttributes options);
void renderItemSpecific(so::Array& obj, const NumberElement& e, TypeAttributes options);
void renderItemSpecific(so::Array& obj, const StringElement& e, TypeAttributes options);
void renderItemSpecific(so::Array& obj, const BooleanElement& e, TypeAttributes options);
void renderItem(so::Array& obj, const IElement& e, TypeAttributes options);

so::Object renderValueSpecific(const ObjectElement& e, TypeAttributes options);
Expand All @@ -102,7 +105,7 @@ namespace
}

template <typename T>
void renderItem(so::Array& a, const T& e, TypeAttributes options)
void renderItemSpecific(so::Array& a, const T& e, TypeAttributes options)
{
LOG(debug) << "rendering item " << e.element() << "Element as JSON Value";
a.data.emplace_back(renderValue(e, inherit_or_pass_flags(options, e)));
Expand Down Expand Up @@ -487,7 +490,7 @@ namespace
});
}

void renderItem(so::Array& a, const RefElement& e, TypeAttributes options)
void renderItemSpecific(so::Array& a, const RefElement& e, TypeAttributes options)
{
LOG(debug) << "rendering item RefElement as JSON Value";

Expand All @@ -501,11 +504,47 @@ namespace
}
}

void renderItemSpecific(so::Array& a, const NumberElement& e, TypeAttributes options)
{
LOG(debug) << "rendering item " << e.element() << "Element as JSON Value";

options = updateTypeAttributes(e, options);

if ((options.test(FIXED_FLAG) || definesValue(e)))
a.data.emplace_back(renderValue(e, inherit_or_pass_flags(options, e)));
else
LOG(debug) << "skipping empty non-fixed primitive element in ArrayElement";
}

void renderItemSpecific(so::Array& a, const StringElement& e, TypeAttributes options)
{
LOG(debug) << "rendering item " << e.element() << "Element as JSON Value";

options = updateTypeAttributes(e, options);

if ((options.test(FIXED_FLAG) || definesValue(e)))
a.data.emplace_back(renderValue(e, inherit_or_pass_flags(options, e)));
else
LOG(debug) << "skipping empty non-fixed primitive element in ArrayElement";
}

void renderItemSpecific(so::Array& a, const BooleanElement& e, TypeAttributes options)
{
LOG(debug) << "rendering item " << e.element() << "Element as JSON Value";

options = updateTypeAttributes(e, options);

if ((options.test(FIXED_FLAG) || definesValue(e)))
a.data.emplace_back(renderValue(e, inherit_or_pass_flags(options, e)));
else
LOG(debug) << "skipping empty non-fixed primitive element in ArrayElement";
}

void renderItem(so::Array& a, const IElement& e, TypeAttributes options)
{
auto aPtr = &a;
refract::visit(e, [aPtr, options](const auto& el) { //
renderItem(*aPtr, el, options);
renderItemSpecific(*aPtr, el, options);
});
}
} // namespace
2 changes: 1 addition & 1 deletion test/fixtures/mson/fixed-type-array-primitive-nested.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"content": "application/json"
}
},
"content": "{\n \"s\": [\n \"\"\n ]\n}"
"content": "{\n \"s\": []\n}"
},
{
"element": "asset",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/render/object-array-string.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"content": "application/json"
}
},
"content": "{\n \"a\": [\n \"\",\n \"b\",\n \"c\"\n ]\n}"
"content": "{\n \"a\": [\n \"b\",\n \"c\"\n ]\n}"
},
{
"element": "asset",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/schema/array-fixed-types-only.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"content": "application/json"
}
},
"content": "{\n \"tags\": [\n \"\",\n 0\n ]\n}"
"content": "{\n \"tags\": []\n}"
},
{
"element": "asset",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/schema/array-of-types-only.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"content": "application/json"
}
},
"content": "{\n \"tags\": [\n \"\",\n 0\n ]\n}"
"content": "{\n \"tags\": []\n}"
},
{
"element": "asset",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/schema/array-with-nested-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"content": "application/json"
}
},
"content": "{\n \"address\": [\n 0,\n 4,\n 2,\n 42\n ]\n}"
"content": "{\n \"address\": [\n 4,\n 2,\n 42\n ]\n}"
},
{
"element": "asset",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/schema/array-with-nested-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"content": "application/json"
}
},
"content": "{\n \"address\": [\n 0,\n \"\",\n \"4\",\n \"2\",\n \"hello\",\n \"42\"\n ]\n}"
"content": "{\n \"address\": [\n \"4\",\n \"2\",\n \"hello\",\n \"42\"\n ]\n}"
},
{
"element": "asset",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/schema/boolean-literal.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"content": "application/json"
}
},
"content": "{\n \"street\": [\n false,\n true,\n false\n ]\n}"
"content": "{\n \"street\": [\n true,\n false\n ]\n}"
},
{
"element": "asset",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/schema/number-literal.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"content": "application/json"
}
},
"content": "{\n \"street\": [\n 0,\n 0,\n 1.5,\n 340\n ]\n}"
"content": "{\n \"street\": [\n 0,\n 1.5,\n 340\n ]\n}"
},
{
"element": "asset",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/schema/required-array.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"content": "application/json"
}
},
"content": "{\n \"digits\": [\n 0\n ]\n}"
"content": "{\n \"digits\": []\n}"
},
{
"element": "asset",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/schema/string-literal.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"content": "application/json"
}
},
"content": "{\n \"street\": [\n \"\",\n \"bye bye\",\n \"san francisco\"\n ]\n}"
"content": "{\n \"street\": [\n \"bye bye\",\n \"san francisco\"\n ]\n}"
},
{
"element": "asset",
Expand Down

0 comments on commit dae7430

Please sign in to comment.