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

Better importMapping handling when aliasing references #4350

Merged
merged 9 commits into from
Feb 13, 2020

Conversation

pe-st
Copy link
Contributor

@pe-st pe-st commented Nov 1, 2019

Fix from @bkoziak to make importMapping work for Java: #3589

All the code in this PR was contributed by @bkoziak, I did just the merging and added one unit test.

PR checklist

  • Read the contribution guidelines.
  • [n/a] If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • [n/a] Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language. Java: @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608

bkoziak and others added 6 commits August 9, 2019 09:51
- type of TypeAlias changed from 'string' to 'object'
  (not sure if importMapping is supposed also for 'string' types...)
- there might be better ways to write the test, it's kind of a brute
  force test (generate a file and parse it with a regexp)
@wing328 wing328 added this to the 4.2.1 milestone Nov 3, 2019
@wing328 wing328 modified the milestones: 4.2.1, 4.2.2 Nov 15, 2019
@wing328 wing328 modified the milestones: 4.2.2, 4.2.3 Dec 2, 2019
@pe-st
Copy link
Contributor Author

pe-st commented Dec 18, 2019

Do I need to do anything so that the PR can be merged? Should I declare the Bug #3589 as fixed now or only once this PR has been merged?

@wing328 wing328 modified the milestones: 4.2.3, 5.0.0, 4.3.0 Jan 31, 2020
@pe-st pe-st requested a review from jimschubert as a code owner February 2, 2020 15:37
@wing328
Copy link
Member

wing328 commented Feb 2, 2020

UDPATE: merged latest master into this branch but got the following error:

[main] ERROR org.openapitools.codegen.DefaultCodegen - body in fromRequestBody cannot be null!
[main] ERROR org.openapitools.codegen.utils.ModelUtils - Schema cannot be null in isFreeFormObject check
[ERROR] Tests run: 1032, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 36.385 s <<< FAILURE! - in TestSuite
[ERROR] modelTest(org.openapitools.codegen.python.PythonClientExperimentalTest)  Time elapsed: 0.058 s  <<< FAILURE!
java.lang.AssertionError: expected [V1beta3Binding] but found [v1beta3_binding.V1beta3Binding]
	at org.openapitools.codegen.python.PythonClientExperimentalTest.modelTest(PythonClientExperimentalTest.java:54)

Updated that test case but found that python experimental petstore samples will have some changes such as

--- a/samples/client/petstore/python-experimental/petstore_api/api/fake_api.py
+++ b/samples/client/petstore/python-experimental/petstore_api/api/fake_api.py
@@ -538,7 +538,7 @@ class FakeApi(object):
                 async_req (bool): execute request asynchronously
 
             Returns:
-                outer_number.OuterNumber
+                float
                     If the method is called asynchronously, returns the request
                     thread.
             """
@@ -565,7 +565,7 @@ class FakeApi(object):
 
         self.fake_outer_number_serialize = Endpoint(
             settings={
-                'response_type': (outer_number.OuterNumber,),
+                'response_type': (float,),

so I need some time to figure out why there's a change to codegenOperation.returnBaseType:

-        Assert.assertEquals(codegenOperation.returnBaseType, "V1beta3Binding");
+        Assert.assertEquals(codegenOperation.returnBaseType, "v1beta3_binding.V1beta3Binding");

@pe-st
Copy link
Contributor Author

pe-st commented Feb 9, 2020

UDPATE: merged latest master into this branch but got the following error:

[main] ERROR org.openapitools.codegen.DefaultCodegen - body in fromRequestBody cannot be null!
[main] ERROR org.openapitools.codegen.utils.ModelUtils - Schema cannot be null in isFreeFormObject check
[ERROR] Tests run: 1032, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 36.385 s <<< FAILURE! - in TestSuite
[ERROR] modelTest(org.openapitools.codegen.python.PythonClientExperimentalTest)  Time elapsed: 0.058 s  <<< FAILURE!
java.lang.AssertionError: expected [V1beta3Binding] but found [v1beta3_binding.V1beta3Binding]
	at org.openapitools.codegen.python.PythonClientExperimentalTest.modelTest(PythonClientExperimentalTest.java:54)

I found the reason for the test failure (my branch introduced a new method in an ancestor class of the PythonClientExperimentalCodegen class).

I'll have a fix shortly

pe-st added 2 commits February 9, 2020 20:05
Fixes broken unit test after merge from master
@wing328
Copy link
Member

wing328 commented Feb 11, 2020

@pe-st thanks for the quick fix. All tests passed. I'll take a look tomorrow and merge if no question from me or anyone.

Copy link
Member

@wing328 wing328 left a comment

Choose a reason for hiding this comment

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

Reviewed and I'm ok with the approach to use import mapping to change how unalias-reference works. Let's have this in 4.3.0 release and see if our users have other feedback on this.

@wing328 wing328 merged commit eecd8c0 into OpenAPITools:master Feb 13, 2020
@wing328 wing328 changed the title Java importmapping 3589 Better importMapping handling when aliasing references Feb 13, 2020
MikailBag pushed a commit to MikailBag/openapi-generator that referenced this pull request Mar 23, 2020
* type aliasing issue

* Add example OpenAPI document from issue 3589

OpenAPITools#3589

* Add test to reproduce the issue

- type of TypeAlias changed from 'string' to 'object'
  (not sure if importMapping is supposed also for 'string' types...)
- there might be better ways to write the test, it's kind of a brute
  force test (generate a file and parse it with a regexp)

* Remove duplicate test file

* Add new method override handleMethodResponse

Fixes broken unit test after merge from master

Co-authored-by: bkoziak <[email protected]>
Co-authored-by: William Cheng <[email protected]>
@wing328
Copy link
Member

wing328 commented Mar 27, 2020

@pe-st thanks for the PR, which has been included in the 4.3.0 release: https://twitter.com/oas_generator/status/1243455743937789952

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.

3 participants