You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在OpenAPI响应中引用Customer Schema的customer_id字段?

可以引用Customer Schema的customer_id属性

当然可以,在OpenAPI 3.1中,你可以通过JSON Schema的$ref语法直接引用已有Schema里的具体属性。具体做法是使用$ref指向Customer schema中customer_id属性的路径:#/components/schemas/Customer/properties/customer_id。

修改后的接口定义如下:

paths:
  /customer/all:
    get:
      tags:
        - customer
      summary: Retrieve list of customer IDs
      description: Retrieve the IDs of all existing customers
      operationId: getCustomersById
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Customer/properties/customer_id'

这么做的好处是:

  • 避免重复定义customer_id的类型、格式、描述等信息
  • 当你后续修改Customer schema中customer_id的定义时,这个响应的schema会自动同步更新,保证一致性

内容的提问来源于stack exchange,提问作者Saurabh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 08:47:06