Skip to content

Commit

Permalink
Merge 4391742 into 23c9d51
Browse files Browse the repository at this point in the history
  • Loading branch information
mduesterhoeft committed Dec 21, 2018
2 parents 23c9d51 + 4391742 commit 33ccea1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ subprojects {
}
}
}

apply(plugin = "com.jfrog.bintray")
configure<BintrayExtension> {
user = project.findProperty("bintrayUser") as String? ?: System.getenv("BINTRAY_USER")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ class JsonSchemaFromFieldDescriptorsGeneratorTest {
then(JsonPath.read<String>(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()
Expand Down Expand Up @@ -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"))
}
Expand Down

0 comments on commit 33ccea1

Please sign in to comment.