lerouxrgd / rsgen-avro

Command line and library for generating Rust types from Avro schemas
MIT License
36 stars 29 forks source link

Union with a single type #62

Closed martin-g closed 8 months ago

martin-g commented 8 months ago

I wanted to test https://issues.apache.org/jira/browse/AVRO-3946 and I observe a strange behavior.

avro-3946.avsc:

{
  "type": "record",
  "name": "Issue",
  "namespace": "invalid.example",
  "fields": [
    {
      "name": "myField",
      "type": ["long"]
    }
  ]
}
$ ./target/release/rsgen-avro avro-3946.avsc -

#[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize, serde::Serialize)]
pub struct Issue {
    #[serde(rename = "myField")]
    pub my_field: UnionLong,
}

UnionLong enum is not declared! Neither any of the From/TryFrom impls.

In addition, I agree with the reporter of https://issues.apache.org/jira/browse/AVRO-3946 that such single type unions should be simplified to non-union, if possible.

lerouxrgd commented 8 months ago

Thanks, for reporting this. I have fixed it.

martin-g commented 8 months ago

Confirmed! All looks good now!