Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Include schema in generated object #23

Closed
gudjonragnar opened this issue Sep 29, 2021 · 5 comments
Closed

Suggestion: Include schema in generated object #23

gudjonragnar opened this issue Sep 29, 2021 · 5 comments

Comments

@gudjonragnar
Copy link
Contributor

Would it be possible to include the schema in the generated struct? This could then be used to e.g. validate the struct against the schema or write the struct to avro file.

@lerouxrgd
Copy link
Owner

lerouxrgd commented Sep 30, 2021

It could be useful to add it indeed.

That could be gated by a flag (like your derive-builders param). I think someone made a prototype of it in the past but it didn't get contributed back here.

@gudjonragnar
Copy link
Contributor Author

I think that prototype could provide a good grounds for a solution. I especially like the use of lazy static.

@landreussi
Copy link

Apache Avro team recently added in apache/avro#1631 a derive macro that allows you to retrieve the Schema from the derived struct (IDK if this solves the issue):

#[derive(Debug, Serialize, AvroSchema)]
struct Test {
    a: i64,
    b: String,
}
// derived schema, always valid or code fails to compile with a descriptive message
let schema = Test::get_schema();

As I could see, you're already migrating to the apache version in #26, we could also derive AvroSchema in generated types, WDYT?

@jklamer
Copy link

jklamer commented May 25, 2022

For this, you absolutely could call the derive macro, but you don't need to! You could generate an implementation for the AvroSchema trait with the raw schema string much like I did here: https://github.com/apache/avro/blob/master/lang/rust/avro/src/writer.rs#L1084-L1111 .
I don't know what would be easier lift.
The advantage of implementing with that trait would be to get compatibility with the SpecificSingleObjectReader/Writer out of the box. (provided that the generated structs implement serde::Serialize/serde::Deserialize of course)
The newest crate should be released soon and will let you know when that happens.

@lerouxrgd
Copy link
Owner

Fixed in 0.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants