问题描述
我有一个要求,我必须动态加载Swagger api url参数,即在项目编译时加载。这是一个Spring Boot项目。因此,例如,如果有这样的事情:-
当我运行swaggerUi时,此api的外观应为“ / pet / 1” 。我了解我们必须在项目本身内提供包含“ petId” 的数据/文件,以便仅在编译时获取petId的值。我只是不知道在Spring Boot Java项目中在何处以及如何执行此操作,在这些项目中,这些Swagger Apis是通过启用Swagger的REST注释(如下所示)创建的:- @RequestMapping(值=“ / pet / {petId}”,消耗= {“ text / plain”},方法= RequestMethod.POST) 。再次总结一下-当我为我的项目运行Swagger UI时,上面给出的api应该看起来像“ / pet / 1” (petId = 1)而不是“ / pet / {petId}” 。非常感谢您的帮助。
解决方法
您必须使用@ApiParam注释,如以下示例所示:
@GetMapping(BASE_URL_USERS + "/{id}")
@ApiOperation(value = "getUserById() - Retrieves a user by ID",authorizations = {@Authorization(value = "basicAuth")}
)
@ApiResponses(value = {
@ApiResponse(code = 200,message = "Success"),@ApiResponse(code = 401,message = "Invalid credentials"),@ApiResponse(code = 404,message = "User not found"),@ApiResponse(code = 500,message = "Internal server error")
})
@ResponseStatus(value = HttpStatus.OK)
UserDTO getUserByIdUsingGET(
@ApiParam(value = "ProcessID",required=false) @RequestHeader(value="processID",required=false) String processID,@ApiParam(value = "User ID",required=true) @PathVariable("id") Long id
);