在招摇,是否可以在一个文件中导入多个yaml文件?

时间:2017-09-08 11:47:58

标签: swagger swagger-editor openapi

对于客户端,这个客户端位于client.yaml

const el = document.getElementById('conteudo_pagina_quantidade' + i);
const clr = window.getComputedStyle(el).getPropertyValue("color");

对于USER,这是在user.yaml

/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: []

2 个答案:

答案 0 :(得分:1)

您不能$ref整条路径,但可以$ref个别路径的内容。在您的示例中,您可以使用:

paths:
  /clients:
    $ref: clients.yaml#/~1clients
  /users:
    $ref: users.yaml#/~1users

clients.yaml#/~1clients表示我们获取clients.yaml文件,然后读取该文件中/clients节点的内容,并用$ref替换该内容。根据JSON指针规则,~1clients/clients/转义为~1


要简化引用,您可以从/clients:/users:文件中删除clients.yamlusers.yaml个节点

# clients.yaml
get:
  description: "List Clients The list capability"
  ...
post:
  summary: "Create client if address is enabled"
  ...

然后使用

paths:
  /clients:
    $ref: clients.yaml
  /users:
    $ref: users.yaml

答案 1 :(得分:0)

OpenAPI 3允许使用$ ref关键字:

https://swagger.io/docs/specification/using-ref/