Closed oshevtsov closed 1 year ago
Hello, thanks for reporting this.
Maybe you can keep the sanitize
call ?
Sure I can :slightly_smiling_face:. However, the variable s
has been already converted to upper camel case and sanitized, see https://github.com/lerouxrgd/rsgen-avro/blob/master/src/templates.rs#L1033. So, it should look exactly as the corresponding name inside the enum definition. Look at https://github.com/lerouxrgd/rsgen-avro/blob/master/src/templates.rs#L428.
IMHO it should be as it is right now. If you feel like it is necessary to sanitize it again (to be on a safe side), then I would do it at both places, but not only one. However, since it is already sanitized, there is no need to do it again.
Sure you are right, thanks for the fix ! I will make a release as soon as I can.
Thank you for looking at this so quickly :rocket:
Released in 0.12.2
When working on a project that performs code generation from Avro schema files, I have encountered an issue with enums. This seems to be an edge case that is easy to overlook, but the generated code does not compile. The problem is when an enum is defined as a struct field and has a default symbol that is only two characters long, starts with a small letter, and ends with a capital letter (e.g.
mJ
, see example below).Minimal example:
The issue manifests itself at line 1035 of
src/templates.rs
, wheres.to_upper_camel_case()
is called twice when constructing the default symbol name (in contrast, this method is called only once when generating the enum definition). For the example above, the sequence of modifications is as follows:mJ -> MJ -> Mj
.The generated code looks as follows:
See the difference between
MeasurementUnit::MJ
andMeasurementUnit::Mj
. The proposed change is minimal and makes sure thats.to_upper_camel_case()
is called only once both when generating the enum definition and when generating the default initializer function inside the record.