如何提供文本以在属性文件中大摇大摆地提供 Spring Restful 服务? [英] How to provide texts to swagger in a properties file for spring restful service?

查看:45
本文介绍了如何提供文本以在属性文件中大摇大摆地提供 Spring Restful 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 swagger 创建 Spring Restful 服务文档.

I am creating my spring restful service documentation with swagger.

示例请求处理程序方法及其文档如下.它有效:

Sample request handler method and its documantation below. It works:

@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 文档时,没有显示文本.

But I want to provide text of the request handler methods into swagger annotations from a properties file (It is being done to not increase the class size with documentation text).
Therefore I have created a properties file called "application-swagger.properties" and enabled it in "application.properties" (spring.profiles.active=swagger). When I create api documentation as below, Text is not being displayed.

 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 注释?感谢您的帮助.

Is there a way of putting text to swagger annotation from a properties file? Thanks for your help.

推荐答案

回答这个问题已经很晚了,但如果有人需要同样的帮助,可以参考它.

It has been quiet late to answer the question but in case anyone needs help regarding the same may refer it.

步骤:

  1. 创建一个属性文件,例如swagger.properties
  2. 输入您想要的消息作为键值对,其中键将用作占位符 - 例如person.id=此人的唯一标识符
  3. 插入占位符而不是注释文本 - 例如${person.id}
  4. 在类级别的配置中注册属性文件 - 例如.@PropertySource("classpath:swagger.properties")

使用 Spring Boot 1.5 和 Swagger 2.8,不确定以前的版本.

Worked with Spring Boot 1.5 and Swagger 2.8, not sure about the previous versions.

参考来自详细的文章差不多.

Reference taken from a detailed article about the same.

这篇关于如何提供文本以在属性文件中大摇大摆地提供 Spring Restful 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆