Skip to content

Swagger generated code now silently ignores invalid values for enumerated types #4119

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

Open
scannerscan opened this issue Nov 3, 2016 · 3 comments

Comments

@scannerscan
Copy link
Contributor

Description

Swagger generated code now silently ignores invalid values for enumerated types.

We used to have 400 exception which was perfect:
HTTP/1.1 400 Bad Request
X-Powered-By: Servlet/3.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Access-Control-Allow-Headers: Content-Type
Content-Length: 533
Content-Type: text/plain
Content-Language: en-AU
Connection: Close
Date: Thu, 03 Nov 2016 05:38:45 GMT

The supplied JSON was not well formed: Can not construct instance of.....

Swagger-codegen version

2.2.2-SNAPSHOT

Command line used for generation

Java, Jersey 2, jaxrs

Steps to reproduce

that code is the issue I think.
@JsonCreator
public static XXXEnum fromValue(String text) {
for (XXXEnum b : XXXEnum.values()) {
if (String.valueOf(b.value).equals(text)) {
return b;
}
}
return null;
}

Suggest a Fix

I think this is a key functionality that cannot be changed. Several projects relying on that validation
Please revert the changes.

@wing328
Copy link
Contributor

wing328 commented Nov 4, 2016

@scannerscan instead of returning null, what about throwing an exception instead?

@scannerscan
Copy link
Contributor Author

@wing328, what do you think about just reverting that template back to the previous implementation without that code snapshot? our user stories relied on the 400 status code coming from the original implementation if the value was not in the enum set.

@wing328
Copy link
Contributor

wing328 commented Nov 7, 2016

The change is needed to fix #3509

As a workaround, you can update the template to remove the code snippet and use the -t option with the customized templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants