swagger-api / swagger-api/swagger-codegen

The Client Generated from Swagger Codegen doesn't work when you pass complex object in the query parameter

Open
#11,849 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

The Client Generated from Swagger Codegen doesn't work when you pass complex object in the query parameter

3.0.9

Swagger declaration file content or url
Command line used for generation
Steps to reproduce

My API takes an Object in the query param.

  • name: q_client_params
    in: query
    description: Additional parameters for client request
    required: false
    style: deepObject
    explode: true
    schema:
    $ref: '#/components/schemas/client_request'

SCHEMA:-
client_request:
type: object
properties:
includ_profile_details:
type: boolean
default: false
include_client_xref:
type: boolean
default: false

When the model classes are generated it appends this "class ClientRequest" which creates problem while genrating the url.

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ClientRequest {\n");

sb.append("    includProfileDetails: ").append(toIndentedString(includProfileDetails)).append("\n");
sb.append("    includeClientXref: ").append(toIndentedString(includeClientXref)).append("\n");
sb.append("}");
return sb.toString();

}

ideally my URL should be
/client/?q_language=EN&q_client_params={“includ_profile_details”:true,”include_client_xref”:true”}

HOWEVER the code is generating something like this
/client/?q_language=EN&q_client_params=class+ClientRequest+{
includProfileDetails: true
includeClientXref: true
}

As the codegen appends this extra string like "class+ClientRequest+" the API call fails.
The Invocation.Builder is not able to build.

Related issues/PRs
Suggest a fix/enhancement

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

No source file, generator command, or test is named. Start by reproducing the generated Java client's handling of the deepObject query parameter and inspect how the ClientRequest model is converted before Invocation.Builder constructs the URL. Done means the request uses the expected object query representation without the class name or toString formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.