Skip to content

[BUG] [Java] Client resttemplate and webclient. Form Params are badly added when they are lists #4383

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

Closed
5 of 6 tasks
jorgerod opened this issue Nov 5, 2019 · 1 comment
Closed
5 of 6 tasks

Comments

@jorgerod
Copy link
Contributor

jorgerod commented Nov 5, 2019

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Plugin will generate DefaultApi.java and when the element to be inserted to formParams is a list ... instead of an formParams.addAll it makes an formParams.add

openapi-generator version

4.1.3, 4.2.0

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: My Api
  version: 0.0.1
paths:
  /api/v1/article/id/exist:
    post:
      description: my endpoint
      operationId: checkArticle
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                articleIds:
                  description: article ids
                  type: array
                  items:
                    type: integer
                    format: int32
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                type: integer
Command line used for generation

java -jar openapi-generator-cli.jar generate -g java -i openapi-rest.yml -o openapi --library resttemplate

Steps to reproduce

Run the above command.

Actual

    /**
     * 
     * my endpoint
     * <p><b>200</b> - successful operation
     * @param articleIds article ids (optional)
     * @return ResponseEntity&lt;Integer&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ResponseEntity<Integer> checkArticleWithHttpInfo(List<Integer> articleIds) throws RestClientException {
     //...
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        if (articleIds != null)
            formParams.add("articleIds", articleIds);
     //...
   }

Expected:

    /**
     * 
     * my endpoint
     * <p><b>200</b> - successful operation
     * @param articleIds article ids (optional)
     * @return ResponseEntity&lt;Integer&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ResponseEntity<Integer> checkArticleWithHttpInfo(List<Integer> articleIds) throws RestClientException {
     //...
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        if (articleIds != null)
            formParams.addAll("articleIds", articleIds);
     //...
   }
Related issues/PRs
Suggest a fix
@auto-labeler
Copy link

auto-labeler bot commented Nov 5, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant