【问题标题】:Multiple refs in YAML duplicated mapping key at line 43 errorYAML 中的多个引用在第 43 行重复映射键错误
【发布时间】:2020-06-23 21:31:47
【问题描述】:

我正在尝试将多个 refs 放入 YAML 文档中以分解大小,但在第 43 行错误处得到重复的映射键,有没有办法做到这一点?或者我只是想把它分解成很多,初始入口文件进入路径 '''

paths:
  $ref: "./paths/_index.yaml"

然后从那里分开到:

/Users:
  get:
    $ref: "./user/listUsers.yaml"
  post:
    $ref: "./user/createUsers.yaml"
/Users/{UserId}:
  get:
    $ref: "./user/showUserById.yaml"

列出用户然后进入用户模式:

    content:
      application/json:
        schema:
          ArrayOfUsers:
            type: array
            items:
          $ref: '../../schemas/User.yaml'
  '404':
    description: no users were found
  default:
    $ref: "../../responses/UnexpectedError.yaml"

然后我想分解用户模型中的部分,以便我可以再次使用它们而不是拥有一个巨大的块

type: object
description: random corp
properties:
  # contact_info:
  #   description: contact information
  #   type: object
  #   properties:
  #     firstName:
  #       type: string
  #     lastName:
  #       type: string
  #     companyName:
  #         type: string
  #     email:
  #       type: string
  #     phone:
  #       type: string
  # address_info:
  #   description: address information of the alitus customer
  #   type: object
  #   properties:
  #     firstName:
  #       type: string
  #     lastName:
  #       type: string
  #     companyName:
  #       type: string
  #     email:
  #       type: string
  #     phone:
  #       type: string
  # account_reference:
  #   description: Alitus customers number and id for referencing
  #   type: object
  #   properties:
  #     id:
  #       type: integer
  #       format: int64
  #     accountNumber:
  #       type: integer
  #       format: int64
  $ref: "/Login/LoginDetails.yaml"
  $ref: "/packageDetails/PackageDetails.yaml"
example:
  type: array
  items:
    anyOf:
      $ref: "../examples/UserExample.yaml"

xml:
  name: User

我是想把它分开还是可以在 3.0 中完成 这是错误 处理您的文件时出错。请修复错误并保存文件。

#/paths/~1Users/get/responses/200/content/application~1json/schema: duplicated mapping key at line 43, column 3:
      $ref: ../../schemas/User.yaml
#/paths/~1Users~1{UserId}/get/responses/200/content/application~1json/schema: duplicated mapping key at line 43, column 3:
      $ref: ../../schemas/User.yaml
#/components/schemas/User: duplicated mapping key at line 43, column 3:
      $ref: ./User.yaml

【问题讨论】:

标签: yaml swagger openapi


【解决方案1】:

我想通了,我只需要一个对包含多个元素的对象的引用

所以现在我只打电话给一个

$ref: "/test.yaml"

在测试文件中,我们只是像这样引用所有对象

Login:
   $ref: "/Login/LoginDetails.yaml"
Package:
   $ref: "/packageDetails/PackageDetails.yaml"

【讨论】:

    猜你喜欢
    • 2017-04-29
    • 2020-04-20
    • 1970-01-01
    • 2023-03-15
    • 2018-12-31
    • 2015-12-27
    • 2014-07-22
    • 2021-04-29
    • 2016-03-03
    相关资源
    最近更新 更多