-
Notifications
You must be signed in to change notification settings - Fork 117
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
feat: openapiv3 cli-ng codegen #506
Conversation
8229355
to
b8310db
Compare
Hey, I just wanted so say that I'm super excited by this change, especially considering the templates! I wanted to test it out, but alas I see that you use a custom version of the ramhorns crate, so I can't install from this branch:
|
Great, glad someone else took an interest! Ah sorry yes I had to add a few features/fixes on both ramhorns and openapiv3.. I'm super busy with work right now, I'll try to make this branch usable for anyone to try when a get a little slack and ping you. |
No problem, thanks! If you also need some help with implementing some features/testing or whatever that's necessary to get it merged I can help get it done. Just need to familiarize myself a bit with the paperclip codebase :D |
Sounds good! |
b8310db
to
509379f
Compare
@zeerooth alright, you should be able to run it now, example:
|
@tiagolobocastro, I'm also happy to see these changes. Can't wait to test this! |
Hey @tiagolobocastro thanks for the work on that! i've tested it for a bit and unfortunately sometimes I'll get
I've uploaded the example schema that the stack overflow happens with to https://gist.github.com/Zeerooth/45d8c6d0beaa6a4f5e47918e5b0c41f8 |
BTW, you're using the |
Thanks I'll test with this api when I get a chance 👍
Thanks a lot I hadn't spotted that, seems I may need to move away from ramhorns as I wouldn't want to change paperclip's license :( |
Ok, looking at the traceback it becomes clear that the problem lies with circular references. In the schema that I referenced above there is a |
Besides that there is also this:
Edit: seems like this is an issue with my schema as per openAPI spec, every endpoint should list at least one response, but this one does't. Still, there should be some info about that displayed. |
Sorry haven't had time lately to catch up on this, circular references should work indeed, I'll try to take a quick look tonight. |
Yeah so for the responses we're only currently expecting 200 and 204 as valid responses, probably we need to also consider the other 201,202,203 codes and consider if we want to support multiple possible success response codes. As for the circular reference yeah there's nothing to handle that at the moment, I'm trying to figure out how best to do it since the children properties will basically have to point to a parent (or grandparent, etc) which isn't fully constructed yet. I think solvable with some indirection. |
That'd definitely be awesome, but that might mean that we need to have multiple different models per each operation, which probably wouldn't be possible to model easily in rust, right?
I agree, that's what I figured out too, I tried to make a global HashMap of props mapped to each schema in the Another thing I considered is that we could have a method that recursively asks each parent of the prop if it has discovered a model mapped to the certain schema and if it has, then use a reference to it instead of constructing it again. This is probably still quite inefficient as we might need to compute a model multiple times (it it has different roots) but wouldn't require as many changes in the code at this point. |
So I think I was actually looking at this wrong... struct Parent {
a: Option<model::Parent>
} So we need the variable name, the |
OMG thanks, it works splendidly! I was able to generate rust models now, but it seems like paperclip doesn't handle reserved rust keywords, so if I have a |
@tiagolobocastro any news 😊 |
Hey, haven't really had the time to look at this any further. |
@zeerooth thank you for pinging ram horns about the license, you're awesome! Also my PR there got merged, so I'll resume work in this PR to tidy it up. I'm at Kubecon this week so won't have time or energy but maybe on the next one I'll start! |
6a3854c
to
1cdadc3
Compare
Started tidying up this and making it available as experimental feature. |
3acc2a2
to
591af3a
Compare
c5cc47d
to
d54bb25
Compare
3cc67ea
to
0f2ebfc
Compare
Adds a new cli capability to generate code from openapiv3 As a start try to generate the same code as https://github.com/openebs/openapi-generator/blob/rust_mayastor/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustMayastorCodegen.java From then on we can improve on this code generation, making it more similar to the current v2 generation. Signed-off-by: Tiago Castro <[email protected]>
paperclip cli main was not exiting with error code. Signed-off-by: Tiago Castro <[email protected]>
On a new published release, build and upload the cli's as static binaries in a tar file. Signed-off-by: Tiago Castro <[email protected]>
0f2ebfc
to
8bb90b7
Compare
Signed-off-by: Tiago Castro <[email protected]>
This adds a template based code generator for openapi v3 using mustache.
Why a new generator?
It didn't seem entirely straightforward changing the current v2 generator to work with the v3 api. Also I like the idea of using templates and putting much of the generator on the templates.
Templates would allow users to add their own and control code generation to match their needs and opinions :)
Why mustache?
I have a generator on a fork of openapi-generator:
https://github.com/openebs/openapi-generator/blob/rust_mayastor/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustMayastorCodegen.java which is based on another generator from the same project.
This would allow me to use it as a drop-in replacement.
In many ways it's not as nice as the the current v2 generator but... we can change that easily (I hope) simply by writing some mustache!