From 3210f66e1670e977f2164d4e7c8a2dc30d588943 Mon Sep 17 00:00:00 2001 From: ooz Date: Wed, 7 Jul 2021 09:20:14 +0200 Subject: [PATCH 1/2] GH-178 Add test reproducing issue --- .../JsonSchemaFromFieldDescriptorsGeneratorTest.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 2e4b1c00..308e5524 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 @@ -209,6 +209,18 @@ class JsonSchemaFromFieldDescriptorsGeneratorTest { thenSchemaValidatesJson("""{ some: [ { "a": "b" } ] }""") } + @Test + fun should_generate_schema_for_mixture_of_array_and_array_wildcard_paths() { + fieldDescriptors = listOf( + FieldDescriptor("some[].foo", "some", "Object"), + FieldDescriptor("some[*].bar", "some", "Object") + ) + + whenSchemaGenerated() + + thenSchemaIsValid() + } + @Test fun should_generate_schema_for_enum_values() { givenFieldDescriptorWithEnum() From 287ed9ec5a2b767769b6bea89022009ef55d0ca3 Mon Sep 17 00:00:00 2001 From: ooz Date: Tue, 13 Jul 2021 13:57:43 +0200 Subject: [PATCH 2/2] Extend test to cover all three cases --- ...SchemaFromFieldDescriptorsGeneratorTest.kt | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) 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 308e5524..db990643 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 @@ -211,14 +211,29 @@ class JsonSchemaFromFieldDescriptorsGeneratorTest { @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") ) - whenSchemaGenerated() + generateAndValidateSchema() - thenSchemaIsValid() + // Mixture of both + fieldDescriptors = listOf( + FieldDescriptor("some[].foo", "some", "Object"), + FieldDescriptor("some[*].bar", "some", "Object") + ) + + generateAndValidateSchema() } @Test @@ -388,4 +403,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) + } }