OpenAPITools / OpenAPITools/openapi-generator
[BUG] com.ly.doc.utils.HttpStatusUtil.getStatusCode is correct only in static import
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
For follow code can generate exception response correct:
@ExceptionHandler(value = DirectException.class)
@ResponseStatus(BAD_REQUEST)
public ResponseEntity<String> exceptionHandler(DirectException e) {
return new ResponseEntity<>(e.getBody(), e.getHttpStatus());
}
But not correct when use:
@ExceptionHandler(value = DirectException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<String> exceptionHandler(DirectException e) {
return new ResponseEntity<>(e.getBody(), e.getHttpStatus());
}
Because JavaAnnotation.getNamedParameter method return value "HttpStatus.BAD_REQUEST", but HttpStatusEnum.valueOf can't find it
Another bug is get status desc
in IRestDocTemplate
String statusCode = HttpStatusUtil.getStatusCode(adviceMethod.getStatus());
if (statusSet.contains(statusCode)) {
continue;
}
statusSet.add(statusCode);
ApiExceptionStatus apiExceptionStatus = new ApiExceptionStatus();
apiExceptionStatus.setStatus(statusCode);
apiExceptionStatus.setDesc(HttpStatusUtil.getStatusDescription(statusCode));
apiExceptionStatus.setAuthor(docJavaMethod.getAuthor());
apiExceptionStatus.setDetail(docJavaMethod.getDetail());
the input for HttpStatusUtil.getStatusDescription is a String of the number of the Code, for example "400"
public static String getStatusDescription(String statusCode) {
try {
HttpStatusEnum httpStatusEnum = HttpStatusEnum.valueOf(statusCode);
return String.valueOf(httpStatusEnum.getReasonPhrase());
}
catch (IllegalArgumentException e) {
return HttpStatusEnum.INTERNAL_SERVER_ERROR.getReasonPhrase();
}
}
so this method throw IllegalArgumentException forever, the correct usage is public static HttpStatusEnum valueOf(int statusCode). So need to convert code to int
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 by locating HttpStatusUtil, JavaAnnotation.getNamedParameter, HttpStatusEnum, and the IRestDocTemplate code shown in the issue. Trace both qualified HttpStatus annotation values and numeric status descriptions, then verify that status codes and reason phrases are resolved correctly in the affected API documentation flow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design, documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100