openapi-generator: [BUG] [JAVA] Using an object to pass query params ends up using the toString of that class

Description

When specifying the query parameters for an endpoint as an object and generate a Java SDK using openapi-generator-cli, it will actually use the class’s toString as the query parameter values instead. For example, here is a sample config I have for openapi version 3.

paths:
  /my_endpoint:
    get:
      tags:
        - "MyEndpoint"
      operationId: "getMyEndpoint"
      parameters:
        - in: query
          name: queryParams
          explode: true
          schema:
            type: object
            properties:
              to:
                type: string
              from:
                type: string

After generating the java SDK and make a request like so:

QueryParams queryParams = new QueryParams();
queryParams.setTo("Person");
MyEndpointSuccessResponse result = apiInstance.getMyEndpoint(queryParams);

The request is received by my endpoint, but this is what the query params look like: {"query_params"=>"class QueryParams {\n to: Person\n from: null\n}"}

openapi-generator version

4.2.1-SNAPSHOT

Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate
-i ./local/swagger.yaml
-g java
-o ./local/java
-c ./local/config.json

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 15
  • Comments: 24 (8 by maintainers)

Most upvoted comments

I am also experiencing this issue, is anybody trying to fix it with a PR?

If you’re using WebClient, you want the bug over at https://github.com/OpenAPITools/openapi-generator/issues/14691

I still see this issue in latest release. When will the fix be released?

I opened a PR that should fix this issue.

I’m experiencing the same issue, though I’m not sure what @mtohmaz would expect regarding the key. I would expect the client to translate it to /my_endpoint?from=zero&to=ten.

This lines up with how the parameters are serialized in a spring backend, since #2655 is fixed.

A recent issue is #8352, which addresses the same issue, but then without specifying explicit properties on the object. In that case a Map is generated. The PR over there won’t fix this issue.