Skip to content
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

Force avro String type in generated schema #730

Merged
merged 4 commits into from
Apr 26, 2023
Merged

Conversation

RustedBones
Copy link
Contributor

scala/java String will be represented in with the "avro.java.string": "String" property in the avro schema.

Logical types baked by avro string should be created using the CharSequence type as the property is forbidden there (exception is thrown when building the schema)

implicit val afString: AvroField[String] = new Aux[String, String, String] {
override protected def buildSchema(cm: CaseMapper): Schema = {
val schema = Schema.create(Schema.Type.STRING)
GenericData.setStringType(schema, GenericData.StringType.String)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about this method! nice

Comment on lines -200 to -201
implicit val afUnit =
aux2[Unit, JsonProperties.Null](Schema.Type.NULL)(_ => ())(_ => JsonProperties.NULL_VALUE)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why we had this. The generated data looked incorrect and having a data model containing a Unit field looks wrong to me. I replaced with a afNull in case we want to get a schema with null type.

@codecov
Copy link

codecov bot commented Apr 25, 2023

Codecov Report

Merging #730 (03aa1e1) into main (a5affff) will decrease coverage by 0.03%.
The diff coverage is 96.15%.

@@            Coverage Diff             @@
##             main     #730      +/-   ##
==========================================
- Coverage   94.99%   94.97%   -0.03%     
==========================================
  Files          52       52              
  Lines        1779     1790      +11     
  Branches      169      171       +2     
==========================================
+ Hits         1690     1700      +10     
- Misses         89       90       +1     
Impacted Files Coverage Δ
avro/src/main/scala/magnolify/avro/AvroType.scala 95.90% <95.65%> (-0.50%) ⬇️
...rc/main/scala/magnolify/avro/logical/package.scala 93.33% <100.00%> (ø)
...ls/src/main/scala/magnolify/tools/AvroParser.scala 96.15% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants