-
Notifications
You must be signed in to change notification settings - Fork 37
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
properties with list of values #152
Changes from 2 commits
351f706
3d9e4c2
c1e5e80
9897cda
def06bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add some tests for object properties? Just to make sure that this is also correctly processed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean adding tests for a JSON value that is an object with properties? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ask because there's already the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Exactly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I simply extended that test by annotating a property using a JSON object with heterogeneous property types. |
||
|
||
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, | ||
val int: Int | ||
) | ||
|
||
@Serializable | ||
data class EnumAnnotated(@AvroJsonProp("guns", """["and", "roses"]""") val colours: Colours) | ||
} |
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"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"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" | ||
} | ||
] | ||
} |
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"] | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function renamed