OpenAPITools / OpenAPITools/openapi-generator

[BUG] Generated Jersey1 client does not explode query parameters of type object

Open
#5,841 1 comment 0 reactions 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)?
  • What's the version of OpenAPI Generator used? 4.3.0
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

In a generated Jersey1 client a query parameter object is not serialized into multiple parameters if explode is set to true.

openapi-generator version

4.3.0, also tested with 4.3.1-SNAPSHOT (master branch)

OpenAPI declaration file content or url

https://github.com/trettstadtnlb/openapi-object-java-jersey1/blob/master/src/main/resources/openapi.yaml

Command line used for generation
            <configuration>
              <inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
              <generatorName>java</generatorName>
              <generateModelTests>false</generateModelTests>
              <generateApiTests>false</generateApiTests>
              <configOptions>
                <java8>true</java8>
                <library>jersey1</library>
                <dateLibrary>java8-localdate</dateLibrary>
              </configOptions>
            </configuration>
Steps to reproduce

I have created a minimal project that shows the problem: https://github.com/trettstadtnlb/openapi-object-java-jersey1

  1. Run mvn clean package
  2. Run DefaultApiTest and check the generated URL in the debugger

The generated URL is

//example?params=class%20Params%20%7B%0A%20%20%20%20name%3A%20name%0A%20%20%20%20street%3A%20street%0A%7D

but I would expect the parameters to be exploded:

/example?name=name&street=street

Related issues/PRs

none

Suggest a fix

In the generated client the parameter is converted to pairs using ApiClient.parameterToPair method, but instead ApiClient.parameterToPairs should be used. This could be done by returning true for collectionFormat in the template if the parameter is an object. Also ApiClient.parameterToPairs would have to support object parameters.

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 the Jersey1 generator template and the generated ApiClient methods parameterToPair and parameterToPairs, using the linked openapi.yaml and the minimal Maven project as the reproduction. Run mvn clean package and DefaultApiTest, then verify that an exploded object query produces separate name and street parameters instead of the object's string representation.

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.