OpenAPITools / OpenAPITools/openapi-generator

[JAVA] @Parameter( explode = Explode.FALSE, style = ParameterStyle.FORM) does not generate query parameters as unescaped csv format

Open
#14,526 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

[Java]
Using the io.swagger.v3.oas.annotations.Parameter annotation with Explode.FALSE and ParameterStyle.FORM does not generate URL in the correct format for query parameters

@Path("/foos")
public Response findFoos(
            @Parameter(description = "filter based on foos", explode = Explode.FALSE, style = ParameterStyle.FORM)
            @QueryParam("keys") List<String> foos) {
        return super.findFoos(foos);
    }

Gives us the following URL in the generated Java client when called with this list (A,B,C)
https://localhost/foos?foos=A%2CB%2CC instead of https://localhost/foos?foos=A,B,C

Commas should not be escaped in this case as the use of form/explode=false is described in https://swagger.io/docs/specification/serialization/

form false /users{?id} /users?id=5 /users?id=3,4,5 /users?id=role,admin,firstName,Alex
openapi-generator version

Version 6.2.1

OpenAPI declaration file content or url
Command line used for generation

docker run --name openapi-generator-cli -v "${PWD}:/local" openapitools/openapi-generator-cli:6.2.1 generate -i input.json -g java -o /local/out/java --additional-properties library="jersey2",dateLibrary="joda"

Steps to reproduce

Generate swagger to java, look at the generated java classes, in invokeAPI method the queryParam is always escaped.

if (queryParams != null) {
      for (Pair queryParam : queryParams) {
        if (queryParam.getValue() != null) {
          target = target.queryParam(queryParam.getName(), escapeString(queryParam.getValue()));
        }
      }
    }
Related issues/PRs

N/A

Suggest a fix/enhancement

Unknown

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

Reproduce the issue with the provided OpenAPI parameter, Java generator command, and jersey2 library, then inspect the generated client's invokeAPI method and its escapeString call. Verify how form-style, non-exploded array query parameters are serialized, and consider the work complete when the generated request preserves the documented comma-separated format without breaking other query escaping.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.