【问题标题】:swagger annotation content-type not set未设置招摇注释内容类型
【发布时间】:2019-01-26 17:59:19
【问题描述】:

我有这个弹簧休息控制器:

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

}

当我通过swagger-ui (springfox) 接口测试此端点时,我收到了415: content type invalid 错误。标题中似乎没有设置content-type: application/json

缺少什么?

【问题讨论】:

  • 你使用哪个版本的 swagger?
  • 我使用了 io.springfox:springfox-swagger2:2.9.2io.springfox:springfox-swagger-ui:2.9.2 但我最终删除了 de springfox 依赖项并使用了经典的 swagger 编辑器...
  • 我在 springfox-swagger2+springfox-swagger-ui v 2.9.2 遇到了同样的问题
  • 了解这是一个旧帖子,但有人刚刚发布了一个对我有用的答案,所以在这里发布以供参考:stackoverflow.com/questions/62078786/…

标签: spring spring-boot kotlin swagger-ui springfox


【解决方案1】:

在 HTTP GET 请求中没有消耗任何东西。我认为您应该从@GetMapping@ApiOperation 中删除consumes

【讨论】:

  • 这是有道理的,因为没有 json 请求有效负载。谢啦。没想到
猜你喜欢
  • 2017-06-24
  • 1970-01-01
  • 2018-11-07
  • 1970-01-01
  • 2023-01-03
  • 1970-01-01
  • 2019-01-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多