swagger-api / swagger-api/swagger-codegen
[PHP] Generating empty switch statements
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I'm using springfox-swagger-2.9.2 to generate my automated swagger documentation for my spring mvc project. When defining an OPTIONS http method I always return status code 204 on success, no 200 involved. The swagger codegen now shows empty switch statement blocks in the ControllerApi files when catching exceptions:
catch (ApiException $e) {
switch ($e->getCode()) {
}
throw $e;
}
This leads to warnings on my side.
Swagger-codegen version
swagger-codegen-cli-2.4.7.jar
Swagger declaration file content or url
Snipped part:
{
"operationId": "showOptionsCollectionUsingOPTIONS_9",
"consumes": ["application/json"],
"produces": ["*/*"],
"responses": {
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
(Side question: How can I get rid of the consumes? It does not consume anything.)
Command line used for generation
java -jar ../swagger-codegen-cli-2.4.7.jar generate -l php -i {url} -a "Authorization:Basic {base64}"
Steps to reproduce
Create a controller method like this:
@RequestMapping(value = "", method = RequestMethod.OPTIONS)
@ResponseStatus(code = HttpStatus.NO_CONTENT)
public void showOptionsCollection(HttpServletResponse response) {
response.setHeader("Allow", "GET, OPTIONS");
}
Suggest a fix/enhancement
Do not include the statements if empty.
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 swagger-codegen-cli-2.4.7.jar using the documented generate command and inspect the generated PHP ControllerApi files. Trace the generator template or entry point that emits the ApiException switch; done means an OPTIONS operation with only a 204 response no longer produces an empty switch block.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, php
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100