Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swagger annotation content-type not set

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 ?

like image 897
louis amoros Avatar asked Aug 20 '18 15:08

louis amoros


People also ask

What is @API annotation in Swagger?

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).

What is the annotation required to enable the Swagger?

The @EnableSwagger2 annotation is used to enable the Swagger2 for your Spring Boot application.

What is ApiModelProperty in Swagger?

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.


1 Answers

There is nothing to consume in HTTP GET request. I think you should remove the consumes from @GetMapping and @ApiOperation.

like image 120
Tuomo Kestilä Avatar answered Sep 21 '22 01:09

Tuomo Kestilä