使用 OpenAPI 3.0 有没有办法 link 一个特定示例的布尔查询参数

Using OpenAPI 3.0 is there a way to link a boolean query param to a specific example

我在 swagger.com 中对此进行了模拟,因此与我一起工作的前端人员有一个模拟的 api 他们可以在我构建端点时向其发送查询。

是否可以通过改变参数来过滤给定端点上的示例?如果可以,您该怎么做?

更具体地说,我想 return #components/examples/default_vansall_system_vans = false or null

同时 returning #components/examples/all_system_vans-is-trueall_system_vans = true

下面是我的开放api架构。

openapi: 3.0.0
info:
  title: "Van life"
  description: "VANS"
  version: "1.0.0"

tags:
- name: "van"
  description: "All things Van (life)."

paths:
  /vans:
    get:
      tags:
      - "van"
      summary: ""
      operationId: "getVan"
      parameters:
      - in: "query"
        name: "all_system_vans"
        description: "Default of false will get vans in ready to go, true will get all system vans." 
        required: false
        schema: 
          type: "boolean"
          default: false
      responses:
        "200":
          description: "Ok"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Vans"
              examples:
                buffer_only_vans:
                  $ref: "#/components/examples/default_vans"
                all_system_vans:
                  $ref: "#/components/examples/all_system_vans-is-true"
        "400":
          $ref: "#/components/responses/400"
        "404":
          $ref: "#/components/responses/404"

components:
  responses: 
    "400":
      description: "Invalid status value"
    "404":
      description: "Whatever you were looking for is not found."
  examples:
    default_vans:
      summary: ""
      value: {"vans": ["van_2", "van_3", "van_5", "van_7", "van_11"]}
    all_system_vans-is-true:
      summary: ""
      value: {"vans": ["van_1", "van_2", "van_3", "van_4", "van_5", "van_6", "van_7", "van_9", "van_10", "van_11"]}
      
  schemas:
    Vans:
      type: "object"
      properties: 
       vans: 
          type: "array"
          items: 
            type: "string"

externalDocs:
  description: "Find out more about Swagger"
  url: "http://swagger.io"

OpenAPI 规范没有任何将响应定义与特定输入值相关联的语法。这是 OpenAPI 规范存储库中的相关功能请求:
Request/response correlation

但是一些 OpenAPI 模拟/服务虚拟化工具支持这种 request/response 关联。例如ReadyAPI Virtualization (made by the company I work for) has various response dispatch options,包括顺序响应和随机响应选择以及根据请求数据选择响应。