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

[BUG] [client] [java] [native] [csharp-netcore] Multi use of schema params within deepobjects #13662

Merged

Conversation

Reinhard-PTV
Copy link
Contributor

@mandrean (2017/08) @frankyjuang (2019/09) @shibayan (2020/02) @Blackclaws (2021/03) @lucamazzanti (2021/05) @wing328

If a schema is used multiple times as a parameter with different namesin deepObjects, then the parameters have all the same name.

Fixes Issue: #13658

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.1.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.

@wing328
Copy link
Member

wing328 commented Oct 20, 2022

@Reinhard-PTV thanks for the PR. Can you please PM me via Slack when you've time?

https://join.slack.com/t/openapi-generator/shared_invite/zt-12jxxd7p2-XUeQM~4pzsU9x~eGLQqX2g

@@ -5077,7 +5077,6 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
properties.entrySet().stream()
.map(entry -> {
CodegenProperty property = fromProperty(entry.getKey(), entry.getValue(), requiredVarNames.contains(entry.getKey()));
property.baseName = codegenParameter.baseName + "[" + entry.getKey() + "]";
Copy link
Member

Choose a reason for hiding this comment

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

FYI @OpenAPITools/generator-core-team change to baseName has been rolled back.

@wing328
Copy link
Member

wing328 commented Oct 31, 2022

I did a test with java (native) client but got the following:

HTTP: GET /v2/fake/deep_object_test?test_pet=class%20Pet%20%7B%0A%20%20%20%20id%3A%20123%0A%20%20%20%20category%3A%20null%0A%20%20%20%20name%3A%20Hello%20World%0A%20%20%20%20photoUrls%3A%20%5B%5D%0A%20%20%20%20tags%3A%20null%0A%20%20%20%20status%3A%20null%0A%7D&inputOptions=class%20Category%20%7B%0A%20%20%20%20id%3A%20456%0A%20%20%20%20name%3A%20new%20category%0A%7D HTTP/1.1

I added the following to petstore spec:

  /fake/deep_object_test:
    get:
      tags:
        - fake
      operationId: test_query_deep_object
      parameters:
        - name: test_pet
          in: query
          required: false
          style: deepObject
          schema:
            $ref: '#/components/schemas/Pet'
          explode: true
        - name: inputOptions
          in: query
          required: false
          style: deepObject
          schema:
            $ref: '#/components/schemas/Category'
          explode: true
      responses:
        '200':
          description: OK

Does it work for you locally?

@Reinhard-PTV
Copy link
Contributor Author

Does it work for you locally?

I couldn't reproduce your result locally.
In my env the generated URL looks like this:

https://petstore.swagger.io:443/v2/fake/deep_object_test?testPet[id]=123&testPet[name]=Hello World&inputOptions[id]=456&inputOptions[name]=new category

This looks ok for me. Another problem is the category object. This does not work, because nested object does not work in deep objects. See :

deepObject – simple non-nested objects are serialized as paramName[prop1]=value1&paramName[prop2]=value2&.... The behavior for nested objects and arrays is undefined.

https://swagger.io/docs/specification/serialization/

This is our generated code for the query parameters:

List<Pair> localVarQueryParams = new ArrayList<>();
if (testPet != null) {
  localVarQueryParams.addAll(ApiClient.parameterToPairs("testPet[id]", testPet.getId()));
  localVarQueryParams.addAll(ApiClient.parameterToPairs("testPet[category]", testPet.getCategory()));
  localVarQueryParams.addAll(ApiClient.parameterToPairs("testPet[name]", testPet.getName()));
  localVarQueryParams.addAll(ApiClient.parameterToPairs("csv", "testPet[photoUrls]", testPet.getPhotoUrls()));
  localVarQueryParams.addAll(ApiClient.parameterToPairs("csv", "testPet[tags]", testPet.getTags()));
  localVarQueryParams.addAll(ApiClient.parameterToPairs("testPet[status]", testPet.getStatus()));
}
if (inputOptions != null) {
  localVarQueryParams.addAll(ApiClient.parameterToPairs("inputOptions[id]", inputOptions.getId()));
  localVarQueryParams.addAll(ApiClient.parameterToPairs("inputOptions[name]", inputOptions.getName()));
}

if (!localVarQueryParams.isEmpty()) {
  StringJoiner queryJoiner = new StringJoiner("&");
  localVarQueryParams.forEach(p -> queryJoiner.add(p.getName() + '=' + p.getValue()));
  localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath + '?' + queryJoiner.toString()));
} else {
  localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
}

We generated our code with
./bin/generate-samples.sh bin/configs/java-native*
and used the 3_0/petstore-with-fake-endpoints-models-for-testing.yaml

@wing328
Copy link
Member

wing328 commented Nov 29, 2022

I did another test using Pet as the deepObject query parameter but got:

/query/style_deepObject/explode_true/Pet?queryObject%5Bid%5D=12345&queryObject%5Bname%5D=Hello%20World&queryObject%5Bcategory%5D=class%20Category%20%7B%0A%20%20%20%20id%3A%20987%0A%20%20%20%20name%3A%20new%20category%0A%7D&queryObject%5BphotoUrls%5D=http%3A%2F%2Fa.com%2Chttp%3A%2F%2Fb.com

This looks ok for me. Another problem is the category object. This does not work, because nested object does not work in deep objects. See :

Right. That's another issue.

#13909 (for Go client) can be served as a reference

@wing328
Copy link
Member

wing328 commented Nov 29, 2022

@Reinhard-PTV I think we'll accept this test for the time being as it reverts changes to baseName until someone comes up with a better fix.

@wing328
Copy link
Member

wing328 commented Nov 29, 2022

cc @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10)

cc @mandrean (2017/08) @frankyjuang (2019/09) @shibayan (2020/02) @Blackclaws (2021/03) @lucamazzanti (2021/05)

@wing328 wing328 added this to the 6.3.0 milestone Nov 29, 2022
@wing328 wing328 merged commit 6c9246c into OpenAPITools:master Nov 29, 2022
@wing328
Copy link
Member

wing328 commented Nov 29, 2022

FYI. I've filed #14142 to add a test to cover the baseName change in the future.

@wing328
Copy link
Member

wing328 commented Jan 10, 2023

@Reinhard-PTV FYI. I've merged #14378 to support deepObject in java native client. Please pull the latest to give it a try when you've time.

@MachineUserPTV
Copy link
Contributor

@wing328, sorry for the delay. The 6.3.0-SNAPHOT version does not work for our API. I will build a small example to show our problem.

@Reinhard-PTV
Copy link
Contributor Author

Reinhard-PTV commented Jan 18, 2023

@wing328
There is a different behavior now with the 6.3.0_Snapshot effecting arrays in deep objects.
If I test the client generation wit the test yaml file modules\openapi-generator\src\test\resources\3_0\deepobject.yaml,
Arrays in deepObjects are not "," seperated as before. Now they are indexed.
These are examples for the generated GET request with the generated clients:

Before (for example with version 6.0)
http://localhost/test?inputOptions[c]=cItem1,cItems2

Now with version 6.3.0 (there is a [0])
http://localhost/test?inputOptions[c][0]=cItem1&inputOptions[c][1]=cItems2

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