mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RUBY-23497: yaml by json schema - treat empty value as 'null' - properly handle in arrays
This commit is contained in:
@@ -89,7 +89,11 @@ public class YamlArrayAdapter implements JsonArrayValueAdapter {
|
||||
List<JsonValueAdapter> adapters = ContainerUtil.newArrayListWithCapacity(items.size());
|
||||
for (YAMLSequenceItem item: items) {
|
||||
YAMLValue value = item.getValue();
|
||||
if (value == null) continue;
|
||||
if (value == null) {
|
||||
JsonValueAdapter emptyAdapter = YamlPropertyAdapter.createEmptyValueAdapter(item.getFirstChild(), true);
|
||||
if (emptyAdapter != null) adapters.add(emptyAdapter);
|
||||
continue;
|
||||
}
|
||||
adapters.add(YamlPropertyAdapter.createValueAdapterByType(value));
|
||||
}
|
||||
return adapters;
|
||||
|
||||
@@ -38,10 +38,9 @@ public class YamlPropertyAdapter implements JsonPropertyAdapter {
|
||||
@Override
|
||||
public Collection<JsonValueAdapter> getValues() {
|
||||
YAMLValue value = myProperty.getValue();
|
||||
if (value != null) return Collections.singletonList(createValueAdapterByType(value));
|
||||
PsiElement nextSibling = myProperty.getNextSibling();
|
||||
PsiElement nodeToHighlight = PsiUtilCore.getElementType(nextSibling) == TokenType.WHITE_SPACE ? nextSibling : myProperty.getLastChild();
|
||||
return nodeToHighlight == null ? ContainerUtil.emptyList() : Collections.singletonList(new YamlEmptyValueAdapter(nodeToHighlight));
|
||||
return value != null
|
||||
? Collections.singletonList(createValueAdapterByType(value))
|
||||
: ContainerUtil.createMaybeSingletonList(createEmptyValueAdapter(myProperty, false));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -69,4 +68,13 @@ public class YamlPropertyAdapter implements JsonPropertyAdapter {
|
||||
if (value instanceof YAMLSequence) return new YamlArrayAdapter((YAMLSequence) value);
|
||||
return new YamlGenericValueAdapter(value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JsonValueAdapter createEmptyValueAdapter(@NotNull PsiElement context, boolean pinSelf) {
|
||||
PsiElement nextSibling = context.getNextSibling();
|
||||
PsiElement nodeToHighlight = PsiUtilCore.getElementType(nextSibling) == TokenType.WHITE_SPACE
|
||||
? nextSibling
|
||||
: (pinSelf ? context : context.getLastChild());
|
||||
return nodeToHighlight == null ? null : new YamlEmptyValueAdapter(nodeToHighlight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -826,4 +826,22 @@ public class YamlByJsonSchemaHighlightingTest extends JsonSchemaHighlightingTest
|
||||
" }\n" +
|
||||
"}", "x: ");
|
||||
}
|
||||
|
||||
public void testEmptyValueInArray() throws Exception {
|
||||
doTest("{\n" +
|
||||
" \"type\": \"object\",\n" +
|
||||
"\n" +
|
||||
" \"properties\": {\n" +
|
||||
" \"versionAsStringArray\": {\n" +
|
||||
" \"type\": \"array\",\n" +
|
||||
" \"items\": {\n" +
|
||||
" \"type\": \"string\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}", "versionAsStringArray:\n" +
|
||||
" -<warning descr=\"Schema validation: Type is not allowed. Expected: string.\"> </warning>\n" +
|
||||
" <warning descr=\"Schema validation: Type is not allowed. Expected: string.\">-</warning>\n" +
|
||||
" - a");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user