I am upgrading my swagger config from 2.9 to 3.0.0 via springfox-boot-starter and I am following https://springfox.github.io/springfox/docs/snapshot/ - very useful.
I am stuck at upgrading below method:
Current implementation:
private ResponseMessage badRequestErrorResponse() {
return new ResponseMessageBuilder().code(HttpServletResponse.SC_BAD_REQUEST)
.message(HttpStatus.BAD_REQUEST.getReasonPhrase())
.responseModel(
new ModelRef(ErrorResponse.class.getSimpleName()))
.build();
}
Upgraded code
private Response badRequestErrorResponse() {
return new ResponseBuilder().code(String.valueOf(HttpServletResponse.SC_BAD_REQUEST))
.description(HttpStatus.BAD_REQUEST.getReasonPhrase())
. /* How to assign error Model here*/
.build();
}
Please help to map responseModel(marked in code above).
My ErrorResponse class is:
@Getter
public class ErrorResponse {
@JsonProperty("error-code")
private final int errorCode;
@JsonIgnore
private final HttpStatus status;
@JsonProperty("error-message")
private final String errorMessage;
@JsonProperty("timestamp")
private final Instant timestamp = Instant.now();
@JsonInclude(JsonInclude.Include.NON_NULL)
private Map<String, Map<String, List<String>>> requestParameterErrors;
public ErrorResponse(final ErrorCode errorCodes,
final HttpStatus status,
final Map<String, Map<String, List<String>>> errors) {
this.errorCode = errorCodes.getCode();
this.status = status;
this.errorMessage = errorCodes.getDefaultErrorMessage();
if (MapUtils.isNotEmpty(errors)) {
this.requestParameterErrors = errors;
}
}
public ErrorResponse(final ErrorCode errorCode,
final HttpStatus status) {
this.errorCode = errorCode.getCode();
this.status = status;
this.errorMessage = errorCode.getDefaultErrorMessage();
}
public ErrorResponse(final int errorCode,
final HttpStatus status,
final String errorMessage) {
this.errorCode = errorCode;
this.status = status;
this.errorMessage = errorMessage;
}
public ErrorResponse(final HttpStatus status,
final AbstractRPRuntimeException exception) {
this(exception.getErrorCode().getCode(), status, exception.getMessage());
}
}