lerouxrgd / rsgen-avro

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

Templating error: Io error while writing rendered value to output: NotADirectory #49

Closed dario-davi closed 1 year ago

dario-davi commented 1 year ago

Hi,

whene I run the following command ./.cargo/bin/rsgen-avro ./RawResponse_1.json - I get the following error Templating error: Io error while writing rendered value to output: NotADirectory

My Avro schemma is preatty long, if you need I can link it, but it seems a problem with paths, not with schema content.

Thanks, Dario

lerouxrgd commented 1 year ago

Hello, I think ./RawResponse_1.json is interpreted as a directory.

Could you try like that:

./.cargo/bin/rsgen-avro RawResponse_1.json -
lerouxrgd commented 1 year ago

Could you provide your schema if this is not the issue ?

dario-davi commented 1 year ago

Hi, with ./.cargo/bin/rsgen-avro RawResponse_1.json - I have the same result. The schema is here: https://pastebin.com/nXku4LNN

Thanks

lerouxrgd commented 1 year ago

Thank you for the schema.

First of all you need to change a bit the structure for it to be valid. Currently you have something like this:

{
  "schema" : {},
  "schemaType" : "AVRO",
  "references" : [ ]
}

But you have to extract only the "schema" part and put it in a file, so that the content is like this:

{
    "type" : "record",
    "name" : "RawResponseToUploadDtoV1d0",
    "namespace" : "com.enel.sb.ms.normalizer.dto.events.output",
    [...]
}

With this correct schema I gave it a try with the latest rsgen-avro which is 0.11.8 (downloaded from the release page) :

rsgen-avro schema.avsc -

But it fails with:

thread 'main' panicked at 'Ref `Name { name: "RegisterValueDto", namespace: None }` is not resolved. Schema: Ref { name: Name { name: "RegisterValueDto", namespace: None } }', src/templates.rs:298:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I will investigate it further ...

dario-davi commented 1 year ago

Ok thanks

lerouxrgd commented 1 year ago

I have released version 0.11.9 that you can download from the release page that fixes the issues you encountered.

However there is 1 change required to your schema. When you use RegisterValueDto as a value in a map you currently have:

{
  "type" : "map",
  "values" : "RegisterValueDto"
}

But for rsgen-avro to work you need to write its fully-qualified name as follows:

{
  "type" : "map",
  "values" : "com.enel.sb.ms.normalizer.dto.events.output.common.RegisterValueDto"
}

Let me know if that works for you.

dario-davi commented 1 year ago

OK ,thank you very much, I will try! The only strange thing is that I generate that avro schema from existing java classes using avro official java library: it's very strange that it creates an out of standard schema.

lerouxrgd commented 1 year ago

The schema is standard as is (I tried to use it to generate some random data in avro format). But for apache-avro in Rust to parse the schema correctly it seems necessary to have fully-qualified names here.

dario-davi commented 1 year ago

Hi, I think it's working correctly, thanks