Swagger - Springfox 默认总是生成一些响应消息(401,403...).我怎样才能删除它们? [英] Swagger - Springfox always generates some response messages (401,403...) by default. How can I remove them?

查看:43
本文介绍了Swagger - Springfox 默认总是生成一些响应消息(401,403...).我怎样才能删除它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have controller as simple as this:

@RequestMapping(value="/async/data", method=RequestMethod.GET, produces="application/json")
@ApiOperation(value = "Gets data", notes="Gets data asynchronously")
@ApiResponses(value={@ApiResponse(code=200, message="OK")})
public Callable<List<Data>> getData(){
    return ( () -> {return dataService.loadData();} );
}

I was expecting to have only a response message for HTTP status 200. However springfox always generates the ones below (401, 403, 404). How can I disable (not show) them?

async-rest-controller Show/Hide List Operations Expand Operations
GET /async/data Gets data

Implementation Notes
Gets data asynchronously

Response Class (Status 200)
ModelModel Schema
{}

Response Content Type 

Response Messages
HTTP Status Code    Reason  Response Model  Headers
401 Unauthorized        
403 Forbidden       
404 Not Found

解决方案

You should be able to set up the plugin to not use the default response messages. Follow below instructions for different versions.

For 1.0.2 or prior

  new SwaggerSpringMvcPlugin(...)
        //More config
        .useDefaultResponseMessages(false) //<-- this should be false
  ...;

For 2.x

  new Docket()
        //More config
        .useDefaultResponseMessages(false) //<-- this should be false
  ...;

这篇关于Swagger - Springfox 默认总是生成一些响应消息(401,403...).我怎样才能删除它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆