Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
}