-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[Go] Client Models using AllOf, OneOf, or AnyOf Correctly Include time and os imports (Attempt 2) #14459
[Go] Client Models using AllOf, OneOf, or AnyOf Correctly Include time and os imports (Attempt 2) #14459
Conversation
…rectly added to the generated file. This was introduced recently with a fix to not include those imports when the model is a composedSchema OpenAPITools#13833. The logic in that fix was just slightly off as an allOf should be treated the same as a standard model. If a model is an AllOf or does not have any composed schemas at all, the sub-models are in-lined defined in the struct. In this case, the standard logic of including the time and os imports apply. If a model is a OneOf or AnyOf, the sub-models are included as pointers to the defined model. In this case, do not include those items in the logic of including time and os imports.
Would it be possible to add unit test from linked PR? |
...es/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java
Show resolved
Hide resolved
Do you mean the example added to |
Yes. It will be good for the problem to not reoccur. Example/integration test will guarantee that |
IMHO that is core of the problem. Inlining operation does also generate separate the submodelsAlOf object. Right now they are still generated but not used. Time import will be added properly to inlined resource but missing on the AlOf one. Adding test will show us if fix covered this case as well |
|
||
import ( | ||
"encoding/json" | ||
"time" |
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.
Problem solved. Creating issue to seed disscusion if we need this object
@@ -2176,6 +2179,13 @@ components: | |||
type: string | |||
type: object | |||
example: null | |||
AllOfPrimitiveTypes_allOf: |
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.
Link
🤞 for fast merge. This change is going to resolve number of github issues for golang generator |
Addresses #13959
Currently, if a Model is an allOf the time and os imports are not correctly added to the generated file. This was introduced recently with a fix to not include those imports when the model is a composedSchema #13833. The logic in that fix was just slightly off as an allOf should be treated the same as a standard model.
If a model is an AllOf or does not have any composed schemas at all, the sub-models are in-lined defined in the struct. In this case, the standard logic of including the time and os imports apply.
If a model is a OneOf or AnyOf, the sub-models are included as pointers to the defined model. In this case, do not include those items in the logic of including time and os imports.
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(6.3.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)@antihax @grokify @kemokemo @jirikuncar @ph4r5h4d @wing328