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

[Java][Retrofit] fix wrong order of path params #6796

Conversation

giuliopulina
Copy link
Contributor

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming langauge.

Fixes #6391: retrofit2 is crashing when @query params are defined before @path param in the api.
With this change, params are correctly reordered (@path param are always defined before @query param).

(details of the change, additional tests that have been done, reference to the issue for tracking, etc)

@bbdouglas @JFCote @sreeshas @jfiala @lukoyanov @cbornet

@giuliopulina giuliopulina force-pushed the bugfix/6391-retrofit-wrong-order-of-params branch from 03bdd6b to a93bd54 Compare October 25, 2017 09:19
@@ -76,33 +76,6 @@ public void testFindPetsByStatus() throws Exception {
}

@Test
public void testFindPetsByTags() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

@giuliopulina May I know why the test cases for findPetsByTags are removed? Is it throwing errors when run locally?

Copy link
Contributor Author

@giuliopulina giuliopulina Oct 25, 2017

Choose a reason for hiding this comment

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

@wing328 Yes, I confirm that mvn integration-test was throwing error.

In fact, if I try to call the service: http:https://petstore.swagger.io/v2/pet/findByTags?tags=friendly

I receive this error:

  <apiResponse>
      <message>something bad happened</message>
      <type>unknown</type>
  </apiResponse>

And also, if I look in swagger UI, I see that this endpoint is deprecated:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

The CIs (Travis, CircleCI) are running a local copy of the Petstore server as the public petstore server contains invalid pet data from time to time (since anyone can update the record).

Please add those tests back and the CI tests should pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done 👍

@giuliopulina giuliopulina force-pushed the bugfix/6391-retrofit-wrong-order-of-params branch from 8506f7a to 9126ed6 Compare October 26, 2017 22:29
@wing328
Copy link
Contributor

wing328 commented Oct 27, 2017

@giuliopulina I did some tests locally and the result is good. Thanks for the PR.

@wing328 wing328 merged commit f14e072 into swagger-api:master Oct 27, 2017
@wing328 wing328 changed the title Bugfix/6391 retrofit wrong order of params [Java][Retrofit] fix wrong order of path params Oct 27, 2017
@florent37
Copy link

thanks a lot for your work :)

@mmallis87
Copy link

I have a related question regarding operations path params specifically: does anyone think that we should enforce path params order based on how they appear in on the URL path instead of relying on the order in the parameters array?

For instance when the URL path is "/accounts/{accountId}/users/{userId}" and

"parameters": [
          {
            "name": "userId",
            "in": "path",
            "description": "The external user number (int) or user ID Guid.",
            "required": true,
            "type": "string"
          },
          {
            "name": "accountId",
            "in": "path",
            "description": "The external account number (int) or account ID Guid.",
            "required": true,
            "type": "string"
          }
]

the generated method will have a signature that looks like public void myMethod(String userId, String accountId);. I think it makes more sense to have public void myMethod(String accountId, String userId);. Curious to see what you guys think!

@giuliopulina
Copy link
Contributor Author

I have a related question regarding operations path params specifically: does anyone think that we should enforce path params order based on how they appear in on the URL path instead of relying on the order in the parameters array?

For instance when the URL path is "/accounts/{accountId}/users/{userId}" and

"parameters": [
          {
            "name": "userId",
            "in": "path",
            "description": "The external user number (int) or user ID Guid.",
            "required": true,
            "type": "string"
          },
          {
            "name": "accountId",
            "in": "path",
            "description": "The external account number (int) or account ID Guid.",
            "required": true,
            "type": "string"
          }
]

the generated method will have a signature that looks like public void myMethod(String userId, String accountId);. I think it makes more sense to have public void myMethod(String accountId, String userId);. Curious to see what you guys think!

Hi @mmallis87 for what my opinion may be worth, I think it can make sense: however, I think this behavior should be aligned between all the different generators, not just for the Retrofit one, so it should be an higher level design decision.

@mmallis87
Copy link

@giuliopulina I agree that this type of change should be aligned across all generators since it's not specific to Java or Retrofit.

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.

[Android] Retrofit CodeGen : @Path must be before @Query
4 participants