Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

spring mvc - Swagger - Springfox always generates some response messages (401,403...) by default. How can I remove them?

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...