gpt4 book ai didi

rest - OpenApi 3 从外部文件导入模式

转载 作者:行者123 更新时间:2023-12-03 15:21:59 27 4
gpt4 key购买 nike

我正在为 Web 服务定义通用模式,并且我想将它们导入到规范的组件/模式部分。
我想创建一个跨多个服务通用的规范数据模型,以避免在每个服务定义中重新定义相似的对象。

有没有办法做到这一点?
是否有与 XSD 对其导入标签所做的类似的机制?

最佳答案

您可以 $ref直接使用绝对或相对 URL 的外部 OpenAPI 模式对象:

responses:
'200':
description: OK
schema:
$ref: './common/Pet.yaml'
# or
# $ref: 'https://api.example.com/schemas/Pet.yaml'

其中 Pet.yaml 包含,例如:
type: object
properties:
id:
type: integer
readOnly: true
petType:
type: string
name:
type: string
required:
- id
- petType
- name

Using $ref想要查询更多的信息。

关于rest - OpenApi 3 从外部文件导入模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50179541/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com