【问题标题】:Micronaut: Authentication Principal generated into request bodyMicronaut:身份验证主体生成到请求正文中
【发布时间】:2023-03-27 20:00:01
【问题描述】:

我正在尝试从 Micronaut 服务器使用 swagger-codegen 生成客户端代码。经过身份验证的 POST 和 PUT 路由会出现问题(它适用于 GET an DELETE)。

当我在控制器中有这样的方法时:

@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: {}

因此,Authentication Principal 已内置到请求正文中,并且在生成的客户端代码中,该方法的参数将是一个具有 Authentication 和 GameReference 的对象。

我尝试解决此问题的方法:

  • 在身份验证参数之前添加@Parameter(hidden = true)。没有改变任何东西。
  • 使用大张旗鼓的注释进行身份验证,例如@SecuritySchema 和@SecurityDeftion。身份验证原则仍会生成到 swagger yaml 中。

这是 Micronauts Swagger 实现中的一个错误,还是有办法解决这个问题?请注意,这适用于 GET 和 DELETE。那里的身份验证原则被忽略了。

【问题讨论】:

标签: swagger openapi micronaut


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-07
    相关资源
    最近更新 更多