-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support Spec Generation #20
Comments
This is a very interesting idea. Although I will say that its something that would have to come after v1 as a helper package and not part of Zog Core. Have you given some thought as to how this could be implemented? Zog is http framework agnostic. Generally OpenAPI schema generation wraps around a HTTP framework or uses something like code annotations. There doesn't seem to be many good solutions in GO though, this is what I could find: |
Huma is really good. It think it should be possible to do json schema gen or openapi just based on the validation schemas, but yeah maybe as a plugin. |
Yes it should be possible to create Json schemas based on Zog schemas but only for the API request data. But openapi is so much more than just request data, it displays:
Edit: up on further thought. I think the best way to solve this is to create a plugin/package that allows for the conversion of Zog schemas into an intermediate textual or json representation which can then be converted to openapi, swagger or any other. Additionally, like @mkadirtan mentioned this would open up the possibility to generate Zog schemas from things like openapi. Let me consider this further as we move towards v1. If you have any additional thoughts/ideas related to this do leave them here! But with the knowledge that I will probably not be working on this until v1 is out. |
You are right, and if you would think about using zog schemas for json serialization ( probably due to performance reasons, instead of validation ), you could have access to response schemas, too. |
On second thought, this would not be a good idea. I come from a Node.js background, and I realized my thought process follows the ideas from the Node.js ecosystem, which doesn't make sense here. |
@mkadirtan no worries. Mind sharing how you came to that conclusion? Mostly my thoughts were "sure, but generally you need to validate data coming in, not going out. That would be quite a bit of additional overhead for little gain specially since go is already statically typed. But if you really wanted to enforce a specific contract I guess you could do it". Not sure if I am missing something |
Haha, exactly these thoughts! In addition, that could also be useful in terms of performance. However, the gain is much bigger on Node.js projects, I don't know if it makes any significant difference in Go. |
Another nice idea that came up is that this would open the door to importing schemas from Zod which I think is very nice. Just dropping it here so I don't forget when I decide to work on this |
I may be able to work on this if you want to. No promises but we might use this for a project at work, and I can convince my manager 🤞 |
That would be awesome. If there is anything I can do to help please let me know! |
Another very nice possibility this would open up is to generate the structs based on the zog schemas through some kind of CLI |
@Oudwins not at the moment, I took a quick look into the codebase and it seems like schema generation would be pretty straightforward, but this is software development so nothing is certain upfront 😅 And CLI features are always awesome, too. I am glad you consider this feature request valuable 🙌🏻 |
Brilliant. I do think Zog is made in such a way as to be quite simple to extend and understand the code! I'm looking forward to seeing this develop then! The main things I would want from this are:
|
Spec generation for both OpenAPI and JSON Schema would be great. This might also open the door for generating code from those specs.
The text was updated successfully, but these errors were encountered: