uzi*_*lan 6 java rest annotations resteasy swagger
在我的项目中,我们使用RestEasy创建REST接口,并使用Swagger来记录它们.问题是这需要许多注释,可能如下所示:
@ApiOperation(value = "Create a person object",
notes = "Create a person object" +
"Return the newley created person object",
response = Person.class)
@ApiResponses({
@ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "Internal server error"),
@ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = "Unauthorized"),
@ApiResponse(code = HttpStatus.SC_PRECONDITION_FAILED, message = "Precondition failed"),
@ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = "Bad request"),
@ApiResponse(code = HttpStatus.SC_UNPROCESSABLE_ENTITY, message = "Unprocessable entity")
})
@POST
@Path("rest/v1/persons")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
Person createPerson(
@HeaderParam("SecurityToken") String token,
@ApiParam(value = "person", defaultValue = "{ \"name\": = \"Bart Simpson\", \"age\": = 9 }") Person person);
Run Code Online (Sandbox Code Playgroud)
在我们所有的方法中,大多数注释看起来或多或少相同.所以我们复制并粘贴了很多,所有这些注释使得我们的接口非常难以理解,很难确切地说出这些方法在做什么.
所以我想知道是否有人知道我们如何能够拥有相同的功能,但以某种方式隐藏所有这些注释,或至少隐藏其中一些注释.
创建自定义注释并使用 jaxrs 和 swagger 注释对其进行注释。Spring\xe2\x80\x99s RestController是一个很好的例子:
\n\n@Controller\n@ResponseBody\npublic @interface RestController {\n\n}\nRun Code Online (Sandbox Code Playgroud)\n\n编辑:如果 Swagger 和/或 RestEasy 不支持元注释,您可以随时尝试APT作为解决方案。
\n| 归档时间: |
|
| 查看次数: |
433 次 |
| 最近记录: |