Skip to content

GH-53 Empty array schema #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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