Skip to content

Commit d956ebb

Browse files
committed
test: Cover implicit object and array dispatch in parseBaseIfPresent
1 parent f5def80 commit d956ebb

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/test/java/com/retailsvc/http/spec/schema/SchemaParserTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,32 @@ void notWithEmptyInnerSchemaWrapsPermissiveObject() {
347347
assertThat(((NotSchema) s).schema()).isInstanceOf(ObjectSchema.class);
348348
}
349349

350+
@Test
351+
void parsesImplicitObjectFromShapeKeywords() {
352+
// Schema with object-shape keywords but no explicit type still produces
353+
// an ObjectSchema (parseBaseIfPresent's implicit-object branch).
354+
Schema s =
355+
SchemaParser.parse(
356+
Map.of("required", List.of("x"), "properties", Map.of("x", Map.of("type", "string"))));
357+
assertThat(s).isInstanceOf(ObjectSchema.class);
358+
ObjectSchema obj = (ObjectSchema) s;
359+
assertThat(obj.types()).isEmpty();
360+
assertThat(obj.required()).containsExactly("x");
361+
assertThat(obj.properties().get("x")).isInstanceOf(StringSchema.class);
362+
}
363+
364+
@Test
365+
void parsesImplicitArrayFromShapeKeywords() {
366+
// Schema with array-shape keywords but no explicit type still produces
367+
// an ArraySchema (parseBaseIfPresent's implicit-array branch).
368+
Schema s = SchemaParser.parse(Map.of("items", Map.of("type", "integer"), "minItems", 1));
369+
assertThat(s).isInstanceOf(ArraySchema.class);
370+
ArraySchema arr = (ArraySchema) s;
371+
assertThat(arr.types()).isEmpty();
372+
assertThat(arr.items()).isInstanceOf(IntegerSchema.class);
373+
assertThat(arr.minItems()).isEqualTo(1);
374+
}
375+
350376
@Test
351377
void oneOfContainingNestedAnyOfRecurses() {
352378
// Pins that combinator branches are themselves passed through parse(),

0 commit comments

Comments
 (0)