Skip to content

Commit e706e02

Browse files
authored
fix(jsonSchemas): raise error when items property not provided (#14018)
1 parent c8d58e8 commit e706e02

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

airbyte-commons/src/main/java/io/airbyte/commons/json/JsonSchemas.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,13 @@ private static void traverseJsonSchemaInternal(final JsonNode jsonSchemaNode,
190190
// case BOOLEAN_TYPE, NUMBER_TYPE, STRING_TYPE, NULL_TYPE -> do nothing after consumer.accept above.
191191
case ARRAY_TYPE -> {
192192
final List<FieldNameOrList> newPath = MoreLists.add(path, FieldNameOrList.list());
193-
// hit every node.
194-
traverseJsonSchemaInternal(jsonSchemaNode.get(JSON_SCHEMA_ITEMS_KEY), newPath, consumer);
193+
if (jsonSchemaNode.has(JSON_SCHEMA_ITEMS_KEY)) {
194+
// hit every node.
195+
traverseJsonSchemaInternal(jsonSchemaNode.get(JSON_SCHEMA_ITEMS_KEY), newPath, consumer);
196+
} else {
197+
throw new IllegalArgumentException(
198+
"malformed JsonSchema array type, must have items field in " + jsonSchemaNode);
199+
}
195200
}
196201
case OBJECT_TYPE -> {
197202
final Optional<String> comboKeyWordOptional = getKeywordIfComposite(jsonSchemaNode);

airbyte-commons/src/test/java/io/airbyte/commons/json/JsonSchemasTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package io.airbyte.commons.json;
66

77
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertThrows;
89
import static org.mockito.Mockito.mock;
910

1011
import com.fasterxml.jackson.databind.JsonNode;
@@ -132,4 +133,13 @@ void testTraverseMultiTypeComposite() throws IOException {
132133
inOrder.verifyNoMoreInteractions();
133134
}
134135

136+
@SuppressWarnings("unchecked")
137+
@Test
138+
void testTraverseArrayTypeWithNoItemsThrowsException() throws IOException {
139+
final JsonNode jsonWithAllTypes = Jsons.deserialize(MoreResources.readResource("json_schemas/json_with_array_type_fields_no_items.json"));
140+
final BiConsumer<JsonNode, List<FieldNameOrList>> mock = mock(BiConsumer.class);
141+
142+
assertThrows(IllegalArgumentException.class, () -> JsonSchemas.traverseJsonSchema(jsonWithAllTypes, mock));
143+
}
144+
135145
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": ["object", "array"],
3+
"properties": {
4+
"company": {
5+
"type": "string",
6+
"description": "company name"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)