我正在尝试使用 swagger-codegen 从 Micronaut 服务器生成客户端代码。经过身份验证的 POST 和 PUT 路由会出现问题(对于 GET 和 DELETE 效果很好)。
当我在 Controller 中有这样的方法时:
@Override
@Post("/")
public Single<? extends HttpResponse> updateStatus(Authentication authentication, GameReference gameReference) {
// ...
}
该方法的最终结果如下所示:
post:
tags:
- /presence
description: Updates status
operationId: updateStatus
parameters: []
requestBody:
content:
application/json:
schema:
type: object
properties:
authentication:
$ref: '#/components/schemas/Authentication'
gameReference:
$ref: '#/components/schemas/GameReference'
required: true
responses:
default:
description: HTTP 204 for successful updates.
content:
application/json: {}
因此,身份验证主体已内置到请求正文中,并且在生成的客户端代码中,该方法的参数将是具有身份验证和 GameReference 的对象。
我尝试解决此问题的方法:
- 在身份验证参数前添加@Parameter(hidden = true)。没有改变任何东西。
- 使用 swagger 注释进行身份验证,例如 @SecuritySchema 和 @SecurityDeftion。身份验证原理仍然会生成到 swagger yaml 中。
这是 Micronauts Swagger 实现中的一个错误还是有办法解决这个问题?请注意,这对于 GET 和 DELETE 非常有效。验证原则被忽略。
最佳答案
Micronaut 团队将其视为错误: https://github.com/micronaut-projects/micronaut-core/issues/1155
关于swagger - Micronaut:生成到请求正文中的身份验证主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54295894/