I have this spring rest controller:
@RestController
@RequestMapping("/communications")
class CommunicationController(private val service: CommunicationService) {
@ApiOperation(
produces = APPLICATION_JSON_VALUE,
consumes = APPLICATION_JSON_VALUE
)
@GetMapping(
consumes = [APPLICATION_JSON_VALUE],
produces = [APPLICATION_JSON_VALUE]
)
fun findAll(
criterias: CommunicationCriterias,
page: Pageable
): List<CommunicationDTO> = service.findCommunications(criterias, page)
}
When I test this endpoint via the swagger-ui
(springfox) interface, i got a 415: content type invalid
error. It seems that content-type: application/json
is not set in the header.
What is missing ?
Annotation Type Api. @Target(value=TYPE) @Retention(value=RUNTIME) @Inherited public @interface Api. Marks a class as a Swagger resource. By default, Swagger-Core will only include and introspect only classes that are annotated with @Api and will ignore other resources (JAX-RS endpoints, Servlets and so on).
The @EnableSwagger2 annotation is used to enable the Swagger2 for your Spring Boot application.
The @ApiModelProperty annotation allows us to control Swagger-specific definitions such as description (value), name, data type, example values, and allowed values for the model properties. Also, it offers additional filtering properties in case we want to hide the property in certain scenarios.
There is nothing to consume in HTTP GET request. I think you should remove the consumes
from @GetMapping
and @ApiOperation
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With