首页 > 解决方案 > 替换 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 {
[...]
}

我可以用一些东西来存档吗?一些想法是预处理和类型别名。

标签: springspring-bootkotlinannotationsspringdoc

解决方案


为了符合 OpenAPI 3 规范,swagger 注释已经存在多年,稳定并保证了很好的结果。

据说,您可以创建自己的注释并重新发明轮子...


推荐阅读