-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from potfur/properties-with-list-of-values
properties with list of values
- Loading branch information
Showing
7 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroJsonPropSchemaTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.github.avrokotlin.avro4k.schema | ||
|
||
import com.github.avrokotlin.avro4k.Avro | ||
import com.github.avrokotlin.avro4k.AvroJsonProp | ||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.matchers.shouldBe | ||
import kotlinx.serialization.Serializable | ||
|
||
class AvroJsonPropSchemaTest : WordSpec() { | ||
|
||
enum class Colours { | ||
Red, Green, Blue | ||
} | ||
|
||
init { | ||
"@AvroJsonProp" should { | ||
"support props annotation on class" { | ||
|
||
val expected = org.apache.avro.Schema.Parser() | ||
.parse(javaClass.getResourceAsStream("/props_json_annotation_class.json")) | ||
val schema = Avro.default.schema(TypeAnnotated.serializer()) | ||
schema.toString(true) shouldBe expected.toString(true) | ||
} | ||
"support props annotation on field" { | ||
|
||
val expected = org.apache.avro.Schema.Parser() | ||
.parse(javaClass.getResourceAsStream("/props_json_annotation_field.json")) | ||
val schema = Avro.default.schema(AnnotatedProperties.serializer()) | ||
schema.toString(true) shouldBe expected.toString(true) | ||
} | ||
"support props annotations on enums" { | ||
|
||
val expected = org.apache.avro.Schema.Parser() | ||
.parse(javaClass.getResourceAsStream("/props_json_annotation_scala_enum.json")) | ||
val schema = Avro.default.schema(EnumAnnotated.serializer()) | ||
schema.toString(true) shouldBe expected.toString(true) | ||
} | ||
} | ||
} | ||
|
||
@Serializable | ||
@AvroJsonProp("guns", """["and", "roses"]""") | ||
data class TypeAnnotated(val str: String) | ||
|
||
@Serializable | ||
data class AnnotatedProperties( | ||
@AvroJsonProp("guns", """["and", "roses"]""") val str: String, | ||
@AvroJsonProp("jean", """["michel", "jarre"]""") val long: Long, | ||
@AvroJsonProp( | ||
key = "object", | ||
jsonValue = """{ | ||
"a": "foo", | ||
"b": 200, | ||
"c": true, | ||
"d": null, | ||
"e": { "e1": null, "e2": 429 }, | ||
"f": ["bar", 404, false, null, {}] | ||
}""" | ||
) | ||
val int: Int | ||
) | ||
|
||
@Serializable | ||
data class EnumAnnotated(@AvroJsonProp("guns", """["and", "roses"]""") val colours: Colours) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"type": "record", | ||
"name": "TypeAnnotated", | ||
"namespace": "com.github.avrokotlin.avro4k.schema.AvroJsonPropSchemaTest", | ||
"fields": [ | ||
{ | ||
"name": "str", | ||
"type": "string" | ||
} | ||
], | ||
"guns": ["and", "roses"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"type": "record", | ||
"name": "AnnotatedProperties", | ||
"namespace": "com.github.avrokotlin.avro4k.schema.AvroJsonPropSchemaTest", | ||
"fields": [ | ||
{ | ||
"name": "str", | ||
"type": "string", | ||
"guns": ["and", "roses"] | ||
}, | ||
{ | ||
"name": "long", | ||
"type": "long", | ||
"jean": ["michel", "jarre"] | ||
}, | ||
{ | ||
"name": "int", | ||
"type": "int", | ||
"object": { | ||
"a": "foo", | ||
"b": 200, | ||
"c": true, | ||
"d": null, | ||
"e": { "e1": null, "e2": 429 }, | ||
"f": [ "bar", 404, false, null, {} ] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"type": "record", | ||
"name": "EnumAnnotated", | ||
"namespace": "com.github.avrokotlin.avro4k.schema.AvroJsonPropSchemaTest", | ||
"fields": [ | ||
{ | ||
"name": "colours", | ||
"type": { | ||
"type": "enum", | ||
"name": "Colours", | ||
"symbols": [ | ||
"Red", | ||
"Green", | ||
"Blue" | ||
] | ||
}, | ||
"guns": ["and", "roses"] | ||
} | ||
] | ||
} |