-
Notifications
You must be signed in to change notification settings - Fork 95
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
Is there any way to generate avro schema file using go struct? #263
Comments
Nothing like this existing in this library. A method would be to use |
I have a code for that. From Go Struct to avro.Schema and vice versa. By the way, in my implementation I'm loosing the properties. |
@TuSKan The library already has Schema -> Struct in
The fields should maintain the properties as it inherits the |
can anyone share any example? |
My problem is different from avrogen, I need to generate a Go Struct as a reflect.Type dynamically to Encode or Decode in runtime, rather than have a code gen to use further. I looked to MarshalJSON, as you mention there is no properties there. Why a avro.Field is not a avro.Schema ? Just missings a Fingerprint... |
These are the properties on the Field: https://github.com/hamba/avro/blob/main/schema.go#L537
The Field is not a Schema by spec. There is no need to create a struct on the fly, and you can just decode/encoder from a |
I build a recursive func for avro.Schema, so for avro.RecordSchema I lose the properties of the Field. A Fingerprint method for Field doesn't make sense?
|
Fields are not Schemas, regardless of the fingerprint. Assuming you parsed a non-canonical schema, any properties of the Field still exist and are accessible in the same way they are on a Schema. |
@iyashjayesh let me know if this code helps you |
Closing as this is not a planned feature of the library. |
@TuSKan , do you mind providing the definition of |
I just update the gist with avroDefaultField method |
I'm currently working on a project where I need to generate an Avro schema file from a Go struct. I want to know if there is any existing solution that can assist me in achieving this.
Ideally, I would like to find a way to automatically generate the Avro schema based on the defined struct in Go. This would greatly simplify the process of defining and maintaining the schema separately.
If anyone has any insights, recommendations, or example code snippets on how to accomplish this task, I would greatly appreciate your help!
Example:
For instance, consider the following Go struct:
I would like to generate an Avro schema file that reflects the structure and field types of this Go struct automatically. This would enable me to share the schema with other systems.
Any guidance or suggestions on how to achieve this would be greatly appreciated. Thank you in advance for your help!
The text was updated successfully, but these errors were encountered: