【问题标题】:OpenAPI spec for reactive REST service using Quarkus使用 Quarkus 的反应式 REST 服务的 OpenAPI 规范
【发布时间】:2020-08-07 04:28:37
【问题描述】:

到目前为止的旅程

我正在尝试使用 RESTEasy 和 JSON-B,按照 official guide 启动并运行反应式 REST 服务。 我还添加了对 OpenAPI 的支持,用于测试 this guide 之后的服务。

这两个部分独立工作,服务正确返回硬编码的演示数据。 Swagger UI 显示可用的路由并允许调用它们。

然而,它并不像我喜欢的那样流畅......

从简单的非反应式路由中,模式已被正确提取:

Fruit:
  type: object
  properties:
    description:
      type: string
    name:
      type: string

但是从响应式路由中提取了空模式。比如介绍

@GET
@Path("/{name}")
public Uni<Fruit> getOne(@PathParam(value = "name") String name) {
}

导致架构:

UniFruit:
  type: object

有没有办法重用现有的Fruit 架构?

我尝试注释路线,但没有任何效果:

@GET
@Path("/{name}")
// @Schema(ref = "#/components/schemas/Fruit")  // Nope...
// @Schema(ref = "Fruit")                       // Nope...
public Uni<Fruit> getOne(@PathParam(value = "name") String name) {
}

理想情况下,无论如何我都不想单独注释每个反应式方法。

问题

当路由返回Uni&lt;T&gt;Multi&lt;T&gt; 时,有没有办法配置项目范围 使用T 的架构?

【问题讨论】:

标签: openapi quarkus


【解决方案1】:

我已经浏览了 MicroProfile OpenAPI 规范 https://github.com/eclipse/microprofile-open-api/blob/master/spec/src/main/asciidoc/microprofile-openapi-spec.adoc,但找不到一种方法来执行您请求的项目范围的架构更改。您可以对给定的类执行此操作,但这里的类是 Uni,并且您需要根据参数化类型不同的模式。

因此,Quarkus 中的修复似乎是可行的方法,除非 SmallRye OpenAPI(实现)有一些特定的方法来做到这一点。

【讨论】:

    【解决方案2】:

    同时可以使用@Schema注解的implementation属性:

    @GET
    @Path("/{name}")
    @APIResponse(
                content = @Content(mediaType = MediaType.APPLICATION_JSON,
                        schema = @Schema(implementation = Fruit.class)))
        public Uni<Fruit> getOne(@PathParam(value = "name") String name) {
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-07
      • 2021-03-07
      • 1970-01-01
      • 2022-11-18
      • 2021-01-17
      • 2021-08-06
      • 1970-01-01
      • 2021-12-06
      相关资源
      最近更新 更多