diff --git a/restdocs-api-spec-jsonschema/src/test/kotlin/com/epages/restdocs/apispec/jsonschema/JsonSchemaFromFieldDescriptorsGeneratorTest.kt b/restdocs-api-spec-jsonschema/src/test/kotlin/com/epages/restdocs/apispec/jsonschema/JsonSchemaFromFieldDescriptorsGeneratorTest.kt index 9fdb947e..650a80b6 100644 --- a/restdocs-api-spec-jsonschema/src/test/kotlin/com/epages/restdocs/apispec/jsonschema/JsonSchemaFromFieldDescriptorsGeneratorTest.kt +++ b/restdocs-api-spec-jsonschema/src/test/kotlin/com/epages/restdocs/apispec/jsonschema/JsonSchemaFromFieldDescriptorsGeneratorTest.kt @@ -252,6 +252,33 @@ class JsonSchemaFromFieldDescriptorsGeneratorTest { thenSchemaValidatesJson("""{ some: [ { "a": "b" } ] }""") } + @Test + fun should_generate_schema_for_mixture_of_array_and_array_wildcard_paths() { + // Both without wildcard + fieldDescriptors = listOf( + FieldDescriptor("some[].foo", "some", "Object"), + FieldDescriptor("some[].bar", "some", "Object") + ) + + generateAndValidateSchema() + + // Both with wildcard + fieldDescriptors = listOf( + FieldDescriptor("some[*].foo", "some", "Object"), + FieldDescriptor("some[*].bar", "some", "Object") + ) + + generateAndValidateSchema() + + // Mixture of both + fieldDescriptors = listOf( + FieldDescriptor("some[].foo", "some", "Object"), + FieldDescriptor("some[*].bar", "some", "Object") + ) + + generateAndValidateSchema() + } + @Test fun should_generate_schema_for_enum_values() { givenFieldDescriptorWithEnum() @@ -597,4 +624,33 @@ class JsonSchemaFromFieldDescriptorsGeneratorTest { private fun thenSchemaDoesNotValidateJson(json: String) { thenThrownBy { thenSchemaValidatesJson(json) }.isInstanceOf(ValidationException::class.java) } + + private fun generateAndValidateSchema() { + val expectedSchema = """{ + "type" : "object", + "properties" : { + "some" : { + "type" : "array", + "items" : { + "type" : "object", + "properties" : { + "bar" : { + "description" : "some", + "type" : "object" + }, + "foo" : { + "description" : "some", + "type" : "object" + } + } + } + } + } +}""" + + whenSchemaGenerated() + + thenSchemaIsValid() + then(schemaString).isEqualTo(expectedSchema) + } }