lerouxrgd / rsgen-avro

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

Unable to generate proper rust code for the record #53

Closed bwsw closed 1 year ago

bwsw commented 1 year ago

Hello, Thank you for your efforts. This is a very promising crate.

I just tried to use the generator for a record like that:


{
    "name": "Attribute",
    "namespace": "vision.module",
    "type": "record",
    "fields": [
        {
            "name": "element_name",
            "type": "string",
            "doc": "Element name that created this attribute, e.g. 'age-gender'."
        },
        {
            "name": "name",
            "type": "string",
            "doc": "Attribute name, e.g. 'age'."
        },
        {
            "name": "value",
            "type": [
                "string",
                "int",
                "float",
                {
                    "type": "array",
                    "items": "float"
                }
            ],
            "doc": "Attribute value, e.g. ReID array, class label/ID, age, etc."
        },
        {
            "name": "confidence",
            "type": [
                "null",
                "float"
            ],
            "default": null
        }
    ]
}

Unfortunately, the generator cannot generate proper code.


/// Auto-generated type for unnamed Avro union variants.
#[derive(Debug, PartialEq, Clone, serde::Serialize)]
pub enum UnionStringIntFloatArrayOk("Float") {
    String(String),
    Int(i32),
    Float(f32),
    ArrayFloat(Vec<f32>),
}

impl From<String> for UnionStringIntFloatArrayOk("Float") {
    fn from(v: String) -> Self {
        Self::String(v)
    }
}
bwsw commented 1 year ago

Well, there are other errors when trying to generate the code for all schemas as well: https://github.com/insight-platform/Savant/tree/develop/savant/api/avro-schemas

Take a look if you find time for that.

lerouxrgd commented 1 year ago

Hello,

Thank you for reporting this. I have released version 0.11.10 that should fix it.

As for your other schemas I can generate valid code for them provided that in vision.module.BBox.avsc angle's default value is set to 0.0 instead of just 0. I used the the following command:

rsgen-avro path/to/avro-schemas/**/*.avsc path/to/generated.rs

Let me know how all this goes for you.

bwsw commented 1 year ago

Yes 0.0 need to be fixed.

bwsw commented 1 year ago

@lerouxrgd It works like a charm!