Java 如何将API文档移动到单独的类?

Java 如何将API文档移动到单独的类?,java,spring,annotations,swagger,swagger-2.0,Java,Spring,Annotations,Swagger,Swagger 2.0,Swagger提供了一种很好的方法来记录RESTAPI。但是,有一个问题-上述方法的文档文本使代码看起来很难看 E.x.我有一个方法: @RequestMapping(value = "/something", method = RequestMethod.POST) public void something(@Valid @RequestBody @ApiParam(value = "Something") SomethingQuery query, HttpServletRequest r

Swagger提供了一种很好的方法来记录RESTAPI。但是,有一个问题-上述方法的文档文本使代码看起来很难看

E.x.我有一个方法:

@RequestMapping(value = "/something", method = RequestMethod.POST)
public void something(@Valid @RequestBody @ApiParam(value = "Something") SomethingQuery query, HttpServletRequest request, HttpServletResponse response) {
    // ...
}
在添加一些描述后,它看起来像这样:

@ApiOperation(value = "Do something",
            consumes = "application/json",
            produces = "application/json",
            notes = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " +
                    "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " +
                    "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
@ApiResponses(value = {@ApiResponse(code = 400, message = "Bad request. " +
        "This response may be sent e.x. when request is malformed or not valid or something.")})
@RequestMapping(value = "/something", method = RequestMethod.POST)
public void something(@Valid @RequestBody @ApiParam(value = "Something") SomethingQuery query, HttpServletRequest request, HttpServletResponse response) {
    // ...
}
是否有办法将其更改为更清晰易读的内容

也许是这样的:

@ApiOperation(value = Docs.value, consumes = Docs.consumes, produces = Docs.produces, notes = Docs.notes)
@ApiResponses(value = Docs.responses)
@RequestMapping(value = "/something", method = RequestMethod.POST)
public void something(@Valid @RequestBody @ApiParam(value = "Something") SomethingQuery query, HttpServletRequest request, HttpServletResponse response) {
    // ...
}
@ApiOperationSomething
@ApiResponsesSomething
@RequestMapping(value = "/something", method = RequestMethod.POST)
public void something(@Valid @RequestBody @ApiParam(value = "Something") SomethingQuery query, HttpServletRequest request, HttpServletResponse response) {
    // ...
}
我尝试过这样做,但很难创建
apiressponse
s数组,因为这是注释

最好是在单独的文件中有自己的注释,每个字段都有适当的值,然后像这样使用它们:

@ApiOperation(value = Docs.value, consumes = Docs.consumes, produces = Docs.produces, notes = Docs.notes)
@ApiResponses(value = Docs.responses)
@RequestMapping(value = "/something", method = RequestMethod.POST)
public void something(@Valid @RequestBody @ApiParam(value = "Something") SomethingQuery query, HttpServletRequest request, HttpServletResponse response) {
    // ...
}
@ApiOperationSomething
@ApiResponsesSomething
@RequestMapping(value = "/something", method = RequestMethod.POST)
public void something(@Valid @RequestBody @ApiParam(value = "Something") SomethingQuery query, HttpServletRequest request, HttpServletResponse response) {
    // ...
}
但我不知道这是否可能

你们中有谁在将文档从实际方法中分离出来并使代码更干净方面有经验吗