Issue
I'm using Spring Boot v2.6.0 to create a simple hosting service. For Swagger I'm using SpringFox version 3.0.0, and Swagger2.
As I've never used Swagger or OpenAPI inside my Spring projects I'm out of ideas. I'm having an issue with this method:
@CrossOrigin
@Operation(summary = "Check if a resourcepack exists with the specified id.")
@ApiResponse(responseCode = "200", description = "Resourcepack found", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExistsResponse.class))
})
@ApiResponse(responseCode = "400", description = "Bad Request", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))
})
@ApiResponse(responseCode = "403", description = "Blacklisted IP", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))
})
@ApiResponse(responseCode = "429", description = "Too Many Requests (rate-limited)", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = RateLimitResponse.class))
})
@ApiResponse(responseCode = "500", description = "Internal Error (unseen exceptions)", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))
})
@GetMapping(value = "/api/exists/{id:.+}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ExistsResponse> exists(@Parameter(description = "Id of the resourcepack to be checked") @PathVariable String id, HttpServletRequest request) throws InternalErrorException {
I get the following error when navigating to swagger-ui, for all models except the ExistsResponse one.
2022-08-05 17:29:18.057 ERROR 17372 --- [nio-8080-exec-1] nceModelSpecificationToPropertyConverter : Unable to find a model that matches key ModelKey{qualifiedModelName=ModelName{namespace='net.iceyleagons.resourcehost.responses', name='ErrorResponse'}, viewDiscriminator=null, validationGroupDiscriminators=[], isResponse=true}
2022-08-05 17:29:18.058 ERROR 17372 --- [nio-8080-exec-1] nceModelSpecificationToPropertyConverter : Unable to find a model that matches key ModelKey{qualifiedModelName=ModelName{namespace='net.iceyleagons.resourcehost.responses', name='ErrorResponse'}, viewDiscriminator=null, validationGroupDiscriminators=[], isResponse=true}
2022-08-05 17:29:18.058 ERROR 17372 --- [nio-8080-exec-1] nceModelSpecificationToPropertyConverter : Unable to find a model that matches key ModelKey{qualifiedModelName=ModelName{namespace='net.iceyleagons.resourcehost.responses', name='RateLimitResponse'}, viewDiscriminator=null, validationGroupDiscriminators=[], isResponse=true}
2022-08-05 17:29:18.059 ERROR 17372 --- [nio-8080-exec-1] nceModelSpecificationToPropertyConverter : Unable to find a model that matches key ModelKey{qualifiedModelName=ModelName{namespace='net.iceyleagons.resourcehost.responses', name='ErrorResponse'}, viewDiscriminator=null, validationGroupDiscriminators=[], isResponse=true}
I'm using Lombok on my models. As an example here is my RateLimitResponse class:
@Data
@RequiredArgsConstructor
public class RateLimitResponse {
private final long refill;
private final String error;
public static RateLimitResponse from(RateLimitedException e) {
return new RateLimitResponse(e.getRefill(), e.getMessage());
}
}
As a comparison here's the ExistsResponse:
@Data
@RequiredArgsConstructor
public class ExistsResponse {
private final String downloadUrl;
private final boolean exists;
private final long available;
private final long remainingTokens;
public static ExistsResponse found(String downloadUrl, long available, long remainingTokens) {
return new ExistsResponse(downloadUrl, true, available, remainingTokens);
}
public static ExistsResponse empty(long remainingTokens) {
return new ExistsResponse("", false, -1, remainingTokens);
}
}
I have no idea why this does not affect the ExistsResponse model, as it's constructed in a totally equal way.
Solution
As I was searching through the internet I found, that SpringFox's current version doesn't really support @ControllerAdvice
(or rather Exceptions) and there's an open issue related to this on GitHub. (https://github.com/springfox/springfox/issues/521)
I was able to fix my problem by using springdoc instead of Springfox.
Answered By - TOTHTOMI
Answer Checked By - Willingham (JavaFixing Volunteer)