diff --git a/build.gradle.kts b/build.gradle.kts index c938e2ba..4f57530c 100755 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -103,7 +103,7 @@ subprojects { } } } - + apply(plugin = "com.jfrog.bintray") configure { user = project.findProperty("bintrayUser") as String? ?: System.getenv("BINTRAY_USER") diff --git a/restdocs-api-spec-jsonschema/src/main/kotlin/com/epages/restdocs/apispec/jsonschema/JsonSchemaFromFieldDescriptorsGenerator.kt b/restdocs-api-spec-jsonschema/src/main/kotlin/com/epages/restdocs/apispec/jsonschema/JsonSchemaFromFieldDescriptorsGenerator.kt index c8372e36..8d584f31 100644 --- a/restdocs-api-spec-jsonschema/src/main/kotlin/com/epages/restdocs/apispec/jsonschema/JsonSchemaFromFieldDescriptorsGenerator.kt +++ b/restdocs-api-spec-jsonschema/src/main/kotlin/com/epages/restdocs/apispec/jsonschema/JsonSchemaFromFieldDescriptorsGenerator.kt @@ -229,7 +229,14 @@ class JsonSchemaFromFieldDescriptorsGenerator { "null" -> NullSchema.builder() "empty" -> EmptySchema.builder() "object" -> ObjectSchema.builder() - "array" -> ArraySchema.builder() + "array" -> ArraySchema.builder().allItemSchema(CombinedSchema.oneOf( + listOf( + ObjectSchema.builder().build(), + BooleanSchema.builder().build(), + StringSchema.builder().build(), + NumberSchema.builder().build() + ) + ).build()) "boolean" -> BooleanSchema.builder() "number" -> NumberSchema.builder() "string" -> StringSchema.builder() 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 34510e56..439f1d9a 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 @@ -183,6 +183,17 @@ class JsonSchemaFromFieldDescriptorsGeneratorTest { then(JsonPath.read(schemaString, "properties.id.description")).isNotEmpty() } + @Test + fun should_generate_schema_for_unspecified_array_contents() { + givenFieldDescriptorUnspecifiedArrayItems() + + whenSchemaGenerated() + + then(schema).isInstanceOf(ObjectSchema::class.java) + thenSchemaIsValid() + thenSchemaValidatesJson("""{ some: [ { "a": "b" } ] }""") + } + private fun thenSchemaIsValid() { val report = JsonSchemaFactory.byDefault() @@ -213,6 +224,10 @@ class JsonSchemaFromFieldDescriptorsGeneratorTest { fieldDescriptors = listOf(FieldDescriptor("[][]", "some", "ARRAY")) } + private fun givenFieldDescriptorUnspecifiedArrayItems() { + fieldDescriptors = listOf(FieldDescriptor("some[]", "some", "ARRAY")) + } + private fun givenFieldDescriptorWithInvalidType() { fieldDescriptors = listOf(FieldDescriptor("id", "some", "invalid-type")) }