spring - 替换 Kotlin 中的长注释
问题描述
我正在使用 Kotlin 开发 Spring Boot。现在我想创建 API 文档,但是它们的注释很笨拙而且罗嗦。
当前的:
@ApiResponses(
ApiResponse(responseCode = "200", description = "Result depending on the role of the user", content = [Content(schema = Schema(oneOf = [AdminResponse::class, UserResponse::class]))])
)
fun get(authentication: Authentication): Any {
[...]
}
我想要的看起来像:
@Api(
Response(200, "Result depending on the role of the user", [AdminResponse::class, UserResponse::class])
)
fun get(authentication: Authentication): Any {
[...]
}
我可以用一些东西来存档吗?一些想法是预处理和类型别名。
解决方案
为了符合 OpenAPI 3 规范,swagger 注释已经存在多年,稳定并保证了很好的结果。
据说,您可以创建自己的注释并重新发明轮子...
推荐阅读
- javascript - 谷歌recaptcha登录抛出错误'error-codes':['invalid-input-secret']
- bash - 为什么 $# 总是返回 0?
- flutter - 颤振警报对话框
- oauth-2.0 - 如何使用 Gmail REST API 发送电子邮件
- python - 尝试用所有列表替换我的文本
- reactjs - 使用 React Router 时传递状态的最简单方法是什么?
- python - 在具有 GPU 支持的 Tensorflow 中创建自定义 LSTMCell
- java - 试图限制基于图块的游戏中的移动
- mysql - 如何将索引添加到 mysql 数据库以提高性能?
- mysql - 如何从 MySQL 表中的列中删除以某些特定单词开头和结尾的部分文本/段落?