swagger-api / swagger-api/swagger-codegen
Swagger generated code now silently ignores invalid values for enumerated types
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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.
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
Start with the Java, Jersey 2, jaxrs generation path and the generated XXXEnum.fromValue(String) method shown in the issue. Reproduce an invalid enumerated value and trace how the generated server handles the returned value. Done means invalid enum input is rejected again with an HTTP 400 response, with coverage added where the generation behavior is tested.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100