Gerry
Gerry

Reputation: 65

Multiple refs in YAML duplicated mapping key at line 43 error

I am trying to get multiple refs into a YAML document to break down the size but get duplicated mapping key at line 43 error, is there a way to do this ? or am I just trying to break it down to much, the initial entry file goes to paths '''

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

then from there seperates to :

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

list users then goes onto users schema as so :

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

I then wanted to break up the parts in the users model so I could use them again instead of having a giant block

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

Am I trying to separate it to much or can this be done in 3.0 here is the error There was an error while processing your files. Please fix the error and save the file.

#/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

Upvotes: 0

Views: 2391

Answers (1)

Gerry
Gerry

Reputation: 65

I figured it out, I just had to have one reference to an object that contained the multiple elements

so now I just call one

$ref: "/test.yaml"

and in the test file we just reference all the objects like so

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

Upvotes: 1

Related Questions