在swagger中,是否可以在一个文件中导入多个yaml文件?
对于客户端,这一个位于Client.yaml中在swagger中,是否可以在一个文件中导入多个yaml文件?,swagger,swagger-editor,openapi,Swagger,Swagger Editor,Openapi,对于客户端,这一个位于Client.yaml中 /clients: get: tags: - "Clients" description: "List Clients The list capability" produces: - "application/json" parameters: - name: "tenantIdentifier" in: "query" r
/clients:
get:
tags:
- "Clients"
description: "List Clients The list capability"
produces:
- "application/json"
parameters:
- name: "tenantIdentifier"
in: "query"
required: true
type: "array"
items:
type: "string"
enum:
- "default"
responses:
200:
description: "successful operation"
400:
description: "Invalid status value"
security:
- basicAuth: []
post:
tags:
- "Clients"
summary: "Create client if address is enabled"
description: ""
operationId: "addClient"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: "tenantIdentifier"
in: "query"
description: ""
required: true
type: "array"
items:
type: "string"
enum:
- "default"
- in: "body"
name: "body"
description: "Add what do you wnat to add "
required: true
schema:
allOf:
- $ref: '#/definitions/ClientStructure1'
- $ref: '#/definitions/ClientStructure2'
- $ref: '#/definitions/ClientStructure3'
responses:
405:
description: "Invalid input"
security:
- basicAuth: []
对于用户,这在USER.yaml中
/users:
get:
tags:
- "Users"
summary: "Retrieve list of users"
produces:
- "application/json"
parameters:
- name: "tenantIdentifier"
in: "query"
required: true
type: "array"
items:
type: "string"
enum:
- "default"
responses:
200:
description: "successful operation"
400:
description: "Invalid status value"
security:
- basicAuth: []
post:
tags:
- "Users"
summary: "Adds new application user."
description: "Note: Password information is not required (or processed). Password details at present are auto-generated and then sent to the email account given (which is why it can take a few seconds to complete)."
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: "tenantIdentifier"
in: "query"
description: ""
required: true
type: "array"
items:
type: "string"
enum:
- "default"
- in: "body"
name: "body"
description: "Mandatory Fields: username, firstname, lastname, email, officeId, roles, sendPasswordToEmail"
required: true
schema:
$ref: "#/definitions/StructureForCreateUSer"
responses:
400:
description: ""
404:
description: ""
security:
- basicAuth: []
OpenAPI 3允许使用$ref关键字:
您不能
$ref
整个路径,但可以$ref
单个路径的内容。在您的示例中,您可以使用:
路径:
/客户:
$ref:clients.yaml#/~1客户
/用户:
$ref:users.yaml#/~1users
clients.yaml#/~1clients
意味着我们获取clients.yaml
文件,然后读取该文件中/clients
节点的内容,并用该内容替换$ref
<根据JSON指针规则,code>~1客户端是/clients
,其中/
转义为~1
为了简化引用,您可以从
clients.yaml
和users.yaml
文件中删除/clients:
和/users:
节点
#clients.yaml
获取:
描述:“列出客户机列表功能”
...
职位:
摘要:“如果地址已启用,则创建客户端”
...
然后使用
路径:
/客户:
$ref:clients.yaml
/用户:
$ref:users.yaml
恐怕你的问题不清楚。您可以添加多个YAML文件的示例,以及您希望得到的结果文件吗?细节越多越好。感谢naswer。例如,我有两个标签,一个是用户,另一个是客户端:“和”。对于客户端,我在client.yaml中编写了Put、Get、Delete和Post操作,对于user.yaml中的user操作,现在我想在swagger编辑器中连接它们。可能吗?请发布client.yaml和user.yaml的示例内容。我添加了。它们在不同的文件中。可以像$ref:client.yaml和$ref:user.yaml一样导入它们吗?我找到了。它正在工作。这是错误的。1) #/definitions/…
语法用于引用同一文件中的数据模型。2) allOf
仅用于数据模型(架构),不用于操作定义。已删除该示例。指向文档的链接应该足以为用户指明正确的方向。