question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Broken ref when using different file for request & response

See original GitHub issue

Describe the bug

I have spent many hours trying to get to the bottom of this with no luck, so I’m hoping I’ve found a bug and it’s not just my ineptness! 😃

I have a very minimal schema representing get & post methods on a /queries endpoint (see schema below). I’m getting some super weird errors when trying to use them. The problem appears to be related to the post portion of the schema, which has references to two different files, one for the request object and one for the response object (although for debugging purposes, the contents of both files is currently identical)

When I make a GET request, I receive:

{
    "error": {
        "message": "can't resolve reference #/paths/~1queries/post/responses/201/content/application~1json/schema from id #",
        "missingRef": "#/paths/~1queries/post/responses/201/content/application~1json/schema",
        "missingSchema": ""
    },
    "message": "can't resolve reference #/paths/~1queries/post/responses/201/content/application~1json/schema from id #"
}

I am confident the referenced file schemas/queryresponse.yaml is present:

~/ems-api/api_spec$ find
./ems.yaml
./schemas/queryrequest.yaml
./schemas/queryresponse.yaml
./schemas/queries.yaml

In fact, the queries.yaml schema for the get route references this file with no problems.

Bizarrely, in the spec, if I rename the the ref for the response object to schemas/queryrequest.yaml, it works, which is especially odd since both files are currently identical.

I’m surmising from all this that it’s something to do with having two differently named files for request & response refs, though in the OpenAPI 3 spec I’ve not been able to find anything that would prohibit that.

I’m completely out of ideas. My spec seems valid (according to https://editor.swagger.io/ anyway). Might this be a bug?

Examples and context

ems.yaml:

openapi: 3.0.0
info:
  title: EMS
  description: Spec for EMS API
  version: 1.0.0
servers:
  - url: /api/v1.0
paths:
  /queries:
    get:
      summary: Returns all queries
      operationId: getQueries
      parameters:
        - name: offset
          in: query
          required: false
          description: The record index to start returning (e.g. 1 = second record)
          schema:
            type: integer
      responses:
        '200':
          description: An array of query objects
          content:
            'application/json':
              schema:
                $ref: 'schemas/queries.yaml'
        '500':
          description: Server error
    post:
      summary: Create a new query
      operationId: createQuery
      requestBody:
        description: A JSON object describing a query
        required: true
        content:
          'application/json':
            schema:
              $ref: 'schemas/queryrequest.yaml'
      responses:
        '201':
          description: The created query object
          content:
            'application/json':
              schema:
                $ref: 'schemas/queryresponse.yaml'
        '404':
          description: Query not found
        '500':
          description: Server error

schemas/queries.yaml:

type: array
items:
  $ref: 'queryresponse.yaml'

schemas/queryrequest.yaml & schemas/queryresponse.yaml:

type: object
properties:
  id:
    type: integer
    nullable: true
  title:
    type: string
  folder:
    type: string
    nullable: true

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewIshcommented, Jun 29, 2020

Hi @cdimascio

Thanks so much for responding to this so quickly. Your fix in v3.16.4 appears to work perfectly!

Thanks for creating such a useful library, it’s made life much easier for me on my project 😃

0reactions
AndrewIshcommented, Jul 14, 2020

Hi @cdimascio

Thanks for the super speedy response. I just tried it and it works perfectly! Many thanks for fixing it, and for your continued work on this extremely useful package! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

warning: ignoring broken ref refs/remotes/origin/HEAD
This command output the name of the old development branch, which no longer exists. I fixed the warnings using this: $ git symbolic-ref...
Read more >
How to correct a #REF! error - Microsoft Support
The #REF! error shows when a formula refers to a cell that's not valid. This happens most often when cells that were referenced...
Read more >
Unhandled RefsWarningException "warning: ignoring broken ...
Current behaviour Occasionally, some of my GE repo's refs are overwritten with zeroes. (It resides on an external, self-encrypting SSD from ...
Read more >
Git - Unable to resolve reference 'refs/remotes/origin/master'
Solution. Unsure the root cause of the "reference broken". To fix it, delete this file .git/refs/remotes/origin ...
Read more >
MIME types (IANA media types) - HTTP - MDN Web Docs
Multipart types indicate a category of document broken into pieces, often with different MIME types; they can also be used — especially in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found