【发布时间】:2017-06-03 21:58:01
【问题描述】:
我正在大摇大摆地创建我的 Spring Restful 服务文档。
示例请求处理程序方法及其文档如下。它有效:
@ApiOperation(value = "Returns user details", notes = "Returns a complete list of users details with a date of last modification.", response = User.class)
public Response getUser(@ApiParam(name = "userName", value = "Alphanumeric login to the application", required = true) @PathParam("userName") String userName) {
...
}
但我想将请求处理程序方法的文本提供到属性文件中的 swagger 注释中(这样做是为了不使用文档文本增加类大小)。
因此,我创建了一个名为“application-swagger.properties”的属性文件并在“application.properties”(spring.profiles.active=swagger)中启用它。
当我如下创建 api 文档时,没有显示文本。
application-swagger.properties:
value=Returns user details
notes=Returns a complete list of users details with a date of last modification.
控制器类:
@Controller
@Profile("swagger")
public class UserController{
.
.
@ApiOperation(value = "${value}", notes = ${notes}", response = User.class)
public Response getUser(@ApiParam(name = "userName", value = "Alphanumeric login to the application", required = true) @PathParam("userName") String userName) {
...
}
.
.
}
有没有办法从属性文件中将文本放入 swagger 注释?感谢您的帮助。
【问题讨论】:
-
Swagger 注释不允许使用变量设置“值、注释、昵称”键。所以我使用静态类和静态最终变量而不是属性文件解决了这个问题。例如,在请求处理程序方法中,“reqMethod1”值设置为:@ApiOperation(value = "SwaggerProps.REQMETHOD1_Value")
-
更多信息:这不仅是大摇大摆的注释,而是一般的所有注释。
-
@ApiResponses(value = { @ApiResponse(code = 200, message = "已成功填充员工详细信息",response = Employee.class), - 是否有任何选项可以传递代码,来自应用程序的消息值.properties 而不是硬编码?我使用的是 springfox 2.9.x 和 Spring 4.3.15 - REST API