swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

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

Open SwarnenduDasKW opened this issue 3 years ago • 0 comments

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

SwarnenduDasKW avatar Aug 05 '22 14:08 SwarnenduDasKW