Forum Discussion

amarroqu's avatar
amarroqu
Frequent Visitor
2 years ago

Swagger $ref gives "Could not resolve reference: undefined undefined"

so I'm trying to separate the objects that we give in the responses body into separate yaml, or json, files and it gives all the time the same error.

Errors Resolver error at paths./api/thing.get.responses.200.content.application/json.schema.$ref Could not resolve reference: undefined undefined

 

This is my Main.yaml file:

openapi: 3.0.0
info:
 version: '0.0.1'
 title: 'thing-services'
 license:
   name: MIT
tags:
 - name: thingReturn
   description: ''"
paths:
 /api/thing:
   get:
     tags:
       - thingReturn
     description: 'Recovers things'
     responses:
       '200':
         description: 'Returns a list of things.'
         content:
           application/json:
             schema:
               $ref: 'ThingList.yaml#components/schemas/ThingList'
       '204':
         description: No Content. There was no content found.

This is my ThingList.yaml file:

components:
  schemas:
    ThingList:
      type: array
      items:
        $ref: 'Thing.yaml#/components/schemas/Thing'

This is my Thing.yaml file:

components:
  schemas:
    Thing:
      type: object
      properties:
        id:
          type: string
        property1:
          type: integer
          format: int32
        property2:
          type: integer
          format: int32

Lets just say that everything is in the same folder (the original idea is to have the objects in a "object-schemas" folder), it doesn't work either. If I put the objects inside the Main.yaml file with the "#/components/schemas/...", it works fine but it beats the purpose of having everything organized in separate files. I don't know if I'm overlooking something. Any help is appreciated.