Skip to content
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

Merged
merged 3 commits into from
Jan 19, 2023

Conversation

icubbon
Copy link
Contributor

@icubbon icubbon commented Jan 13, 2023

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

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    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.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@antihax @grokify @kemokemo @jirikuncar @ph4r5h4d @wing328

…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.
@wtrocki wtrocki mentioned this pull request Jan 17, 2023
5 tasks
@wtrocki
Copy link
Contributor

wtrocki commented Jan 17, 2023

Would it be possible to add unit test from linked PR?
There are couple duplicate issues for the same bug - all now closed.

@icubbon
Copy link
Contributor Author

icubbon commented Jan 17, 2023

Do you mean the example added to modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml? I don't see a unit test in #14159

@wtrocki
Copy link
Contributor

wtrocki commented Jan 17, 2023

Yes. It will be good for the problem to not reoccur. Example/integration test will guarantee that

@wtrocki
Copy link
Contributor

wtrocki commented Jan 17, 2023

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

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"
Copy link
Contributor

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

@wtrocki
Copy link
Contributor

wtrocki commented Jan 18, 2023

Awesome work! this in fact fixes all the issues we seen. Created separate bug to remove this dangling file #14479

FYI: @antihax @grokify @kemokemo @jirikuncar @ph4r5h4d @wing328

@@ -2176,6 +2179,13 @@ components:
type: string
type: object
example: null
AllOfPrimitiveTypes_allOf:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link

@wtrocki
Copy link
Contributor

wtrocki commented Jan 18, 2023

🤞 for fast merge. This change is going to resolve number of github issues for golang generator

@wing328 wing328 added this to the 6.3.0 milestone Jan 19, 2023
@wing328 wing328 merged commit 6e78021 into OpenAPITools:master Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants