swagger-api / swagger-api/swagger-codegen
[Spring Server] "default" response gets mapped to 200
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The documentations states that the default keyword can be used to describe errors collectively:
“Default” means this response is used for all HTTP codes that are not covered individually for this operation.
But the outcome for a spring server links my Error class to a 200 code.
@ApiOperation(value = "Obtém as unidades operacionais da empresa", nickname = "findOperUnits", notes = "Retorna as unidades operacionais (estações de tratamento) mantidas no [CESANLims](http://cesanlims.sistemas.cesan.com.br:8080/cesanlims/). Valores ausentes ou vazios são suprimidos.", response = OperUnit.class, tags={ "oper-units", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = OperUnit.class),
@ApiResponse(code = 200, message = "unexpected error", response = Error.class) })
@RequestMapping(value = "/oper-units",
produces = { "application/json" },
method = RequestMethod.GET)
ResponseEntity<?> findOperUnits(@ApiParam(value = "Nome da unidade operacional (`LIKE '%name%'`)") @Valid @RequestParam(value = "name", required = false) String name,@ApiParam(value = "ID da unidade organizacional responsável (vide [api-estorg](http://api-estorg.sistemas.cesan.com.br:8081/v1/swagger-ui.html))") @Valid @RequestParam(value = "orgUnitId", required = false) Integer orgUnitId,@ApiParam(value = "Label identificador da unidade operacional") @Valid @RequestParam(value = "label", required = false) String label,@ApiParam(value = "", allowableValues = "ETA, ETE") @Valid @RequestParam(value = "segment", required = false) String segment,@ApiParam(value = "Subdivisão administrativa (não é parâmetro `LIKE`)") @Valid @RequestParam(value = "system", required = false) String system,@ApiParam(value = "", allowableValues = "active, inactive") @Valid @RequestParam(value = "status", required = false) String status);
Since there's a 200 response described within the operation, shouldn't the error class be related to something else?
Swagger-codegen version
swagger-codegen-cli-3.0.0-SNAPSHOT
Swagger declaration file content or url
openapi: "3.0.0"
(...)
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/OperUnit'
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
Command line used for generation
java -jar swagger-codegen.jar generate -i ../../openapi.yaml -l spring -o ../..
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
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
Run the provided swagger-codegen command with the shown OpenAPI responses and inspect the generated Spring server's @ApiResponses output. Trace how the default response is mapped, then verify that the Error schema is no longer associated with HTTP 200 while the explicit 200 response remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100