godatadriven / pydantic-avro

This library can convert a pydantic class to a avro schema or generate python code from a avro schema.
https://github.com/godatadriven/pydantic-avro
MIT License
63 stars 30 forks source link

add namespace as optional paramater #49

Closed DaanRademaker closed 2 years ago

DaanRademaker commented 2 years ago

This pull request adds the possibility to add namespace parameter to avro schema generation.

codecov-commenter commented 2 years ago

Codecov Report

Merging #49 (f3e10c0) into main (bb4b95a) will increase coverage by 0.17%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #49      +/-   ##
==========================================
+ Coverage   89.77%   89.94%   +0.17%     
==========================================
  Files           2        2              
  Lines         176      179       +3     
==========================================
+ Hits          158      161       +3     
  Misses         18       18              
Impacted Files Coverage Δ
src/pydantic_avro/base.py 97.70% <100.00%> (+0.08%) :arrow_up:

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

ffinfo commented 2 years ago

can you add some testing for this?

bedilbek commented 9 months ago

Hi, I was curious that why optional field namespace was being encoded into final avro schema json representation. Because even in the Apache Avro specification it is written explicitly that namespace field is optional so it may not even exist inside the final avro schema json representation. Only required fields that should exist are name and fields. So, I think it is a bad idea to have name as a default value for namespace if it is not given.

bedilbek commented 9 months ago

They also gave sample avro schema json representation where there is no namespace field:

{
  "type": "record",
  "name": "LongList",
  "aliases": ["LinkedLongs"],                      // old name for this
  "fields" : [
    {"name": "value", "type": "long"},             // each element has a long
    {"name": "next", "type": ["null", "LongList"]} // optional next element
  ]
}