swagger-api / swagger-api/swagger-codegen
[JAVA] Java codegen apiClient with restTemplate 200 and 201 different response body
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When there are multiple 2xx responses with different model in response. It seems that only the first one is used for code generation.
So for example I call the api that returns 200 and 201, 203, the response will be cast to 200 response always.
The place where the code breaks when we receive 201 With 201Response:
ParameterizedTypeReference<200Response> returnType = new ParameterizedTypeReference<200Response>() {};
return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
Swagger-codegen version
2.2.3 (Same issue with the master version as well. I tried that :( )
Swagger declaration file content or url
I cant share my whole swagger file, but this is the relevant response body for 200 and 201
OK
Example Value
200Response Model
{
"Status": "Example Status"
}
201
Submit resource successfully created
Example Value
201Response Model
{
"State": "Submitted",
"Scheme": 1,
"Code": "13",
"NestedResponse": {
"Code": "1",
"CodeText": "One"
},
"Response": {
"Name": "SomeName",
"Code": "123",
"Text": "EFFICIENT DATA MODEL"
}
}
Command line used for generation
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i swagger.yaml -l java -o rest_client_dir -c client-config.json
client-config.json
{
"apiPackage" : "com.example",
"artifactId" : "client",
"artifactVersion":"0.0.3",
"modelPackage" : "com.example.model",
"library" : "resttemplate"
}
Steps to reproduce
use the generated client to call the api and expect 201 status and body
Related issues/PRs
Saw a similar case for the backend code, but not for client.
Suggest a fix/enhancement
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 generation command and a specification containing distinct 200 and 201 response models. Start at the generated RestTemplate client's ParameterizedTypeReference and apiClient.invokeAPI call, then trace how the response type is selected. Done means a 201 response is handled with its 201Response body rather than always using 200Response.
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