OpenAPITools / OpenAPITools/openapi-generator

Java generator (jersey2) does not serialize object query parameters according to OAS3

Open
#8,475 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

Description

Hello,

We'd like our generated API to use objects to store query parameters rather than a list of arguments. Mostly for readability and to avoid long argument lists with a lot of nullable string parameters (eg. list(null, null, null, str1, null, str1, null...) vs list(new QueryParameters().setStr1(str1).setStr2(str2))

The OAS3 spec docs give examples where you can do this with an object + schema, plus having explode=true and style=form (the defaults). A la:

/hmf/v1/runs:
    get:
      tags:
        - run
      operationId: list
      parameters:
        - in: query
          name: params
          schema:
            type: object
            properties:
              status:
                type: string
              ini:
                type: string
          explode: true
          style: form

In the end this code creates the Java API we want, but under the hood creates a query parameter, params="class Parameters...".

We're using version 5.0.0.

Apologies if I've misunderstood the spec, hopefully this is supported somehow as it would lead to more elegant generated API code.

openapi-generator version

5.0.0

OpenAPI declaration file content or url
/hmf/v1/runs:
    get:
      tags:
        - run
      operationId: list
      parameters:
        - in: query
          name: params
          schema:
            type: object
            properties:
              status:
                type: string
              ini:
                type: string
          explode: true
          style: form

Generation Details

Maven plugin 5.0.0

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 Jersey2 Java generator's handling of the supplied OpenAPI query object, using the declaration and Maven plugin version in the report as the reproduction case. Trace how the object becomes a query parameter; done means generated requests serialize its fields according to OAS3 form-style, exploded query parameters rather than the object's class string.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
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.