OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] request body parameter with explode=true need to generate separate parameters for each value of the array

Open
#11,256 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Example API
paths:
  /translate:
    post:
      operationId: translate
      summary: Translate text
      requestBody:
        content:
          application/x-www-form-urlencoded:
            encoding:
              text:
                explode: true
                style: form
            schema:
              type: object
              properties:
                text:
                  type: array
                  items:
                    type: string
      responses:
        '200':
          description: translations
        default:
          description: error

The code generated from the above spec should yield following request.
expected request(values form separate parameters:

curl -X 'POST' \
  'https://example.com/translate' \
  -H 'accept: */*' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'text=string&text=string'

actual request (values are joined into one parameter):

curl -X 'POST' \
  'https://example.com/translate' \
  -H 'accept: */*' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'text=string,string'

Please refer OAS v3 Encoding object section for more details:
https://swagger.io/specification/

openapi-generator version

5.3.1

OpenAPI declaration file content or url

See the example above.

Generation Details

Java API client generation

Steps to reproduce

Generate Java API client from the aboe spec, and send a request with that and check the request body of it.

Related issues/PRs

None

Suggest a fix

at least api.mustache template need to be fixed:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/api.mustache#L98

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/Java/api.mustache, the template identified in the report, and review the OpenAPI v3 Encoding object rules for form-style exploded arrays. Generate a Java API client from the supplied specification and inspect the request body. Done means the array values are emitted as repeated text parameters such as text=string&text=string rather than one comma-joined parameter.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.