New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[java] response return does not generate properly #7743
Comments
I can confirm this issue. Complete spec to test it:
Defining different response types is quite new with Swagger v3, this might be not supported yet. |
The issue is in Swagger 2 too as well |
thanks @sashank , i'll address this. |
I am having a similar issue with two services, one is supposed to be returning 200 and 201, the other just 201. TL/DR: My take on what the generator should do set the return type of a resource method (and currently doesn't):
On order to return 201 correctly, I need to be able to return a location header (see Mozilla's take on 201): So if there's a 201 in the responses, I see no other choice for the generator to return a javax.ws.rs.core.Response instead of the actual response model type (no matter whether it's specified or not), because it is the only way to set the Location header. It also allows you to set any status. If you have multiple successful responses (more than one response in the 2xx range), the only way to set the actual status code is also to use Response as a return type (because you need to use Response.status([code]) to set the status code). In the case of a single 204 response, the return type that makes most sense is void, because that's what JAX RS will convert into 204 without any further coding. |
Description
Response return with a string parameter should ideally generate the code with String. But in certain scenario it does not generate. This is consistent behaviour , easily reproducible.
Swagger-codegen version
any latest version
Swagger declaration file content or url
If the below response code is written for "CreateUser"
then as expected
public String createUser(User body)
but where as if below response code is written for "CreateUser"
notice the subtle change in the above that the first response code 200 does not return anything but second response code 201 returns String
now when we generate the code
public void createUser(User body)
Command line used for generation
java -jar /usr/share/swagger/swagger-codegen.jar generate -l java -c config.json -i index.yaml
Steps to reproduce
Very easy , just replace the above in pet store example and generate the code
Related issues/PRs
Suggest a fix/enhancement
It is not clear what is expected behavior , should we mention only one return response code ? or will the generator always take the return type of first response code ?
What is the appropriate behavior ?
The text was updated successfully, but these errors were encountered: