swagger-api / swagger-api/swagger-codegen
[JAVA][SPRING BOOT] Feature generic Error code stubs in spring boot
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Please add error code stubs for spring boot code generation for the various error responses specified in the swagger json. Currently, it just adds the import statements for the models used in the error responses.
Swagger-codegen version
version 2.2.2
Swagger declaration file content or url
The code generator should add something like the following from the Uber api example
For the default response to return an Error model object.
paths:
/estimates/time::
get:
responses:
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
In EstimatesApi.java add a method to return BAD_REQUEST.
@ExceptionHandler(TypeMismatchException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public Error handleTypeMismatchException(HttpServletRequest req, TypeMismatchException ex);
@Override
public Error handleTypeMismatchException(HttpServletRequest req, TypeMismatchException ex)
return new Error();
}
Then throw the TypeMismatchException in the estimatesTimeGet method.
Command line used for generation
I did not look into the command line.
Steps to reproduce
Not a bug.
Related issues
Don't know if this has been suggested before.
Suggest a Fix
Side feature may be a way to map exception classes to error responses in the swagger.json file. See above code as a loose framework of the idea.
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 Swagger JSON response definitions and the generated EstimatesApi.java example described in the issue. Inspect the Spring Boot server generator templates and determine how default and typed error responses should map to exception handlers; done means generated code includes the requested error stubs and throws or handles the corresponding exceptions consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- api, backend, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100