首页 > 解决方案 > 使用 Quarkus 的反应式 REST 服务的 OpenAPI 规范

问题描述

到目前为止的旅程

我正在尝试按照官方指南,使用 RESTEasy 和 JSON-B 启动并运行反应式 REST 服务。我还添加了对 OpenAPI 的支持,以按照本指南测试服务。

两个部分都独立工作,服务正确返回硬编码的演示数据。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) {
}

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

问题

有没有办法在项目范围内配置以使用T路由返回时的模式Uni<T>Multi<T>

标签: openapiquarkus

解决方案


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

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

推荐阅读