Skip to content

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

Closed

Description

@jorgerod

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

Activity

  1. auto-labeler commented on Nov 5, 2019

    @auto-labeler

    👍 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions