java - 如何在 Spring Boot 中添加对 Swagger 的 I18N 支持
问题描述
我正在使用springdoc-openapi-ui swagger。我不想硬编码swagger documentation
. 我想从属性文件中读取这些值。
当我尝试出现编译错误时The value for annotation attribute Operation.summary must be a constant expression.
我知道它正在寻找常量表达式,但我不想在我的代码中硬编码这些值。
请在此处找到我的控制器代码
@RestController
@PropertySource("classpath:test.properties")
public class TestController {
@Autowired
private TestService testService;
@Autowired
private static Environment environment;
final String SUMMARY = environment.getProperty("operationSummary");
@Operation(summary = SUMMARY, description = "Returns a list", tags = { "Test" })
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Successful operation") })
@GetMapping(path = "/description/{id}")
public List<Test> getDescriptionById(@PathVariable String id) {
return testService.getDescriptionById(id);
}
}
有没有办法在端点注释中添加不同语言的消息属性?
解决方案
您拥有带有 swagger 注释的 spring 属性支持:
- Spring属性解析器对@Info的支持:title-description-version-termsOfService
- spring 属性解析器对@Info.license 的支持:name - url
- spring 属性解析器对@Info.contact 的支持:name - email - url
- @Operation 对 spring 属性解析器的支持:描述 - 总结
- Spring属性解析器对@Parameter的支持:描述-名称
- Spring 属性解析器对@ApiResponse 的支持:描述
- 也可以为@OAuthFlow 声明安全 URL:openIdConnectUrl - authorizationUrl - refreshUrl - tokenUrl
- 通过将 springdoc.api-docs.resolve-schema-properties 设置为 true 来支持 @Schema: name - title - description 的 spring 属性解析器
推荐阅读
- linux - 如何获取 LLVM IR 中共享库的基地址?
- c# - 无法更改文件的 mime 类型
- php - 如何正确保护 api 密钥?
- java - `Set 是什么意思
>> typeSet = resolverUtil.getClasses();` 是什么意思? - laravel - Laravel 6:文件夹内的命名路由没有获取用户对象
- reactjs - Formik 两种形式之间的错误初始值
- c# - Windows 10 最大路径长度限制
- php - Laravel/Eloquent 强制执行 findOrFail 和 safeOrFail
- c++ - 班级中的渐进数字
- flutter - 如何在飞镖中拥有一个时间不断变化的计时器?