-
Notifications
You must be signed in to change notification settings - Fork 101
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
Generate structs from schema #159
Generate structs from schema #159
Conversation
Wow, this looks awesome. I am hoping to have some time to dig into it this weekend. To answer one question off the top of my head, I think there should be a |
Dropped dave/dst because it was not printing the imports. Tried using the DecoratorWithImports but eventually it was just faster to write a printer than to figure out how to deal with dst and ast.FileSet type.
RefSchemas are just references so we need only extract the type of the field. The actual type declaration will eventually be generated.
Thank you. After you've looked into this, it looks good, I think the step to move out of draft could be:
If after you've looked into this you feel like its not worth adding this to I had thought about generating the I've never used "internal cmds" I think, but if that means we can defer the CLI to a separate PR, maybe that's better, up to you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firstly, awesome work 🎉 . I have added some suggestions and thoughts. In general I think this is on an amazing track.
This option should live in the command line interface when it exists.
This approach is simpler and serves the needs for now. ast.File would allow for more powerful features in the future, but we don't need it yet.
Added a few commits to address the comments. Thinking on adding now:
But let me know if you have more things to be addressed first. |
Noticed the actions failed. I was trying to run |
It is using |
Installed |
I would personally be happy to merge this here and do the rest as additional PRs. What do you think? |
Sounds good. I'll add a few tests for the failure cases and that should make coveralls happy |
After this merge I will sort out the Makefile and rebase on master. |
gen/gen.go
Outdated
) | ||
|
||
// Conf exposes the options available for the code generation. | ||
type Conf struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick: Could this perhaps be Config
rather?
When ready to merge let me know if you prefer I squash all commits into 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
Merging now as is. |
@nrwiersma here's a sample of what the generation feature could be, let me know what you think.
Considerations:
RefSchema
isn't handled yet, understanding it firstPulled indst
for some comodity when printingIf the core looks ok, we could discuss which options the generator should support (other tags like
json
or different casing for example) and where to place it. Usually code generation runs as part of my build phase, so I'd expect a command line utility to be the interface for this feature, open to suggestions.The generation can be done in a separate repo, but keeping them together might reduce the possibility of a change in the core lib (some change in the Schema interface for example) breaking the generator.
You can run
TestGenFromRecordSchema
and see the result as that test is currently printing the Go codeTODO:
Casing in package nameAdding the imports to the generated fileSupportRefSchema
Future possible improvements
avro.Register
)Thoughts on avro use cases not covered in the test are welcome
(aside from theRefSchema
)#119 (comment)