OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] Using an object to pass query params ends up using the toString of that class
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the supplied OpenAPI v3 snippet, the Java generator, and the openapi-generator-cli command. Inspect the generated Java SDK request path for object query parameters; done means the endpoint receives the object's individual properties rather than the QueryParams toString value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100