1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-09-27 14:39:02 +00:00

fix: allow different type inside array for GetJsonKey builtin fct

This commit is contained in:
The-Lum 2023-12-08 21:08:36 +00:00
parent 3a4c614fc1
commit 1cb61d5609
2 changed files with 7 additions and 5 deletions

View File

@ -76,9 +76,11 @@ public class GetJsonKey extends SimpleReturnFunction {
final JsonArray array = (JsonArray) json;
final JsonArray result = new JsonArray();
for (JsonValue tmp : array) {
final JsonObject object = (JsonObject) tmp;
for (String key : object.names())
result.add(key);
if (tmp.isObject()) {
final JsonObject object = (JsonObject) tmp;
for (String key : object.names())
result.add(key);
}
}
return TValue.fromJson(result);
}

View File

@ -61,11 +61,11 @@ class GetJsonKeyTest {
" '{\"a\":\"abc\"}' , [\"a\"]",
" '[{\"a\":[1, 2]}, {\"b\":[3, 4]}]' , '[\"a\",\"b\"]'",
" '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , '[\"a\",\"b\",\"b\"]'",
// TODO: Manage Array with different type inside
// DONE: Manage Array with different type inside
// Ref.:
// - https://datatracker.ietf.org/doc/html/rfc8259#section-5
// - https://json-schema.org/understanding-json-schema/reference/array.html
//" '[3, \"different\", { \"types\" : \"of values\" }]', [\"types\"]",
" '[3, \"different\", { \"types\" : \"of values\" }]', [\"types\"]",
})
void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated {
assertTimExpectedOutputFromInput(cut, input, expected);