0

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
Gerry
  • 65
  • 8
  • Related (or duplicate): [Swagger: How to have a property reference a model in OpenAPI (i.e. nest the models)?](https://stackoverflow.com/q/26287962/113116) – Helen Jun 24 '20 at 07:02
  • Not sure if its a duplicate, the other question is asking about standard nesting using an array or object, this was about using the references and how to get round it saying they were duplicates, it had nothing to do with if it were array or object, as you can see from my answer – Gerry Jun 24 '20 at 13:39

1 Answers1

1

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"
Gerry
  • 65
  • 8