swagger-api / swagger-api/swagger-codegen

[PHP] Generating empty switch statements

Open
#9,628 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.