Fix problem with code redeclarations#436
Conversation
|
Hi, @popsu @amanbolat , Could you check if this fixes your problem? |
|
Hi, @deepmap-marcinr Could you review this PR? It's a small change and doesn't introduces any breaking changes. Btw, I'm aware there seems to be a |
eab1942 to
ee5ee05
Compare
|
This PR generated the firefly-iii types fine. This does seem to generate the code in a different order, so I'm struggling to find the main differences between the two generated codes, but looking at the original issue it's: Using this PR, the second RuleTrigger is not there. What determines which type is correct? From the code it looks like it could be based on first type found? These two are referenced like so: I could be mistaken, but it looks like both types might be correct, one referenced at Planning utilise the client soon-ish, so who knows, it may just work. |
|
Oh! Looking at the openapi spec (below, some code removed for brevity), it seems that yes, |
|
Hi @hoshsadiq , from your code example the type itself ( I will have a look at the output diff from master compared to my branch. |
|
@hoshsadiq note that |
|
@migueleliasweb thanks! I'm not sure that's true. See my second comment, looking at the spec, it seems |
I think what happened was I was typing and you've edited your comment. Yeah, I see the different types now. So in regards the generated code: I had a quick look at the I also tried to run locally the code generation and it failed with this msg: Maybe you posted the wrong link? Or maybe you're generating the code with a changed local version of that yaml? 🤷♂️ Anyway, the more examples we can test this PR the better. Keep it up. |
That's right! This property: gets generated as: Which doesn't seem correct. The struct is correctly generated though.
Aah yes, the original spec seems to not be fully accepted by oapi-codegen. I ran the following sed on the yaml prior to running it through oapi-codegen: |
|
I had to make a slight change for the Yeah, the output is odd. I reckon I didn't even change anything where the |
|
Ok, I'm 90% certain I've found the problem. Struct enums are prefixed by the struct name. In your case, the A quick fix is: I might also create a PR later for this separately. It could be useful in scenarios like this one to have |
|
That works for me, and yeah I agree, this specific issue I had is probably unrelated to this PR. |
|
Thank you for doing this. Do you have time to rebase and resolve conflicts? I'll happily merge it. |
|
Hi @deepmap-marcinr , awesome! I will fix the conflicts and will let you know. Cheers 🎉 |
a7aba0e to
a6a2909
Compare
|
Hi @deepmap-marcinr , I've updated this PR and now, for some reason, it's complaining about a change in the generated code that seems unrelated to my changes. (see Travic CI output) Any ideas? |
|
I'll merge and fix. |
This should resolve oapi-codegen#386 which is still an issue for clients, the changes in oapi-codegen#436 fixed it for types and server but not clients. This small change enables users to override the suffix where it could clash with existing names.
This should resolve oapi-codegen#386 which is still an issue for clients, the changes in oapi-codegen#436 fixed it for types and server but not clients. This small change enables users to override the suffix where it could clash with existing names.
This should resolve oapi-codegen#386 which is still an issue for clients, the changes in oapi-codegen#436 fixed it for types and server but not clients. This small change enables users to override the suffix where it could clash with existing names.
This should resolve oapi-codegen#386 which is still an issue for clients, the changes in oapi-codegen#436 fixed it for types and server but not clients. This small change enables users to override the suffix where it could clash with existing names.
Fixes: #256 #200 and might also fix: #386.
This PR addresses the problems when the generated code contains multiple redeclarations of
methods,constantsandtypes.You can verify this problem with the Docker OpenAPI reference yaml:
Run the generation with
v1.8.2:oapi-codegen -package openapigen -generate types > types.goRun
staticchecklinter:Outputs:
Run
staticchecklinter again:Outputs: