与Spring数据Rest集成的Swagger中的请求标头设置

与Spring数据Rest集成的Swagger中的请求标头设置,swagger,spring-data-rest,springfox,Swagger,Spring Data Rest,Springfox,我在SpringBoot项目中为SpringDataREST生成的端点设置了一个虚张声势的集成。以下是我在项目中的相关依赖关系: compile "io.springfox:springfox-swagger2:2.6.1" compile "io.springfox:springfox-swagger-ui:2.6.1" compile "io.springfox:springfox-data-rest:2.6.1" compile "io.springfox:springfox-bean-v

我在SpringBoot项目中为SpringDataREST生成的端点设置了一个虚张声势的集成。以下是我在项目中的相关依赖关系:

compile "io.springfox:springfox-swagger2:2.6.1"
compile "io.springfox:springfox-swagger-ui:2.6.1"
compile "io.springfox:springfox-data-rest:2.6.1"
compile "io.springfox:springfox-bean-validators:2.6.1"
这些端点在Swagger中的收割台设置是不同的。例如,我有

curl -X GET --header 'Accept: application/x-spring-data-compact+json' 'http://localhost:8080/accounts'

其中,头中的accept或content类型应为application/json。如何设置正确的标题?

您可以使用@ApiOperation-Swagger注释告诉Swagger端点可以返回的内容类型。比如,

@ApiOperation(products=“application/json,application/x-spring-data-compact+json”)

完整示例:

@RestController
class ExampleController
{
    @ApiOperation(produces = "application/json,application/x-spring-data-compact+json")
    @RequestMapping(value = "/byId", method = RequestMethod.GET)
    public ExampleResponse getById(@RequestParam String id)
    {
         ...
    }
}

这样,它们就会出现在下拉列表中。

是否有一个下拉框,您可以在其中选择
application/json
application/x-spring-data-compact+json
?是的,有一个下拉列表。但是application/json或application/+json并不存在。