OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.58k stars 6.52k forks source link

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

Open periardy opened 1 year ago

periardy commented 1 year ago
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

randeepbydesign commented 1 year ago

facing a blocker due to this as well. We'll be manually editing our spec for now

wing328 commented 1 year ago

can you try the native or apache-httpclient library instead? i think these 2 support this use case.