sway: Unknown error when invalid $ref is used

From @ePaul on May 31, 2016 17:1

My Swagger

swagger: '2.0'
info:
  version: 0.0.0
  title: Simple API
paths:
  /:
    get:
      responses:
        200:
          $ref: "#responses/example"

(Yes, I know that it is invalid, that’s the point.)

  • Swagger Editor version(from Help > About menu): 2.10.1 (currently on editor.swagger.io)
  • My browser: Chromium 50.0.2661.102 Ubuntu 16.04 (64-bit)

Issue

If I have an invalid JSON pointer in one of my $ref attribute, the editor shows an non-helpful error message:

✖ Unknown Error
ptr must be a JSON Pointer
Jump to line
Details
 Object
message:  "ptr must be a JSON Pointer"
code:  "UNCAUGHT_SWAY_WORKER_ERROR"
level: 900
type:  "Unknown Error"
description:  "ptr must be a JSON Pointer"

swagger-editor-error

The “Jump to line” link jumps to some random line (in the example above line 7, which has just the /).

Expected behavior

It would be nice if that error message showed in which $ref the error occurred (as a line number, and/or as a path to the problematic place, as for other validation errors), and maybe also said in which way the value is not a JSON pointer (in the case here, the / is missing after the #).

In a real-live API one can have hundreds of $refs, and many API designers even might not know that those are JSON pointers (i.e. that something is wrong with the $refs).

Copied from original issue: swagger-api/swagger-editor#955

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

The example above has a missing reference. I’m seeing the same behavior with a malformed reference:
$ref: '#definitions/County'

After struggling with the error, I finally figured out that I needed to put a slash before the word definitions. $ref: '#/definitions/County'

I hope your fix covers this case, too.

The issue is fixed in json-refs@v3.0.0 but I’ve not updated sway yet. I’m working on it.

I had the same bug and lack of details on what was going wrong in my Swagger Spec. I could only get out of trouble until I made sure that all references to definitions had a slash / after #, i.e. : like $ref: "#/definitions/Address" instead of $ref: "#definitions/Address" Conclusion : Solution is adding the slash / in the reference to definitions: $ref: #/definitions...

NB: the bug showing up was :

(node:25396) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error in plugin 'gulp-swagger'
Message:
    ptr must be a JSON Pointer
(node:25396) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I’m not sure if you realized it but I moved this issue from Swagger Editor using Github Issue Mover. Those are not my words in the original post.

Original poster is asking for line numbers etc but the real issue is that Sway was throwing an error instead of reporting one which I believe you’ve found the root cause of it and opened an issue in JSON Refs.

I realize that, which is why I said what I did. You said “It would be nice if that error message showed in which $ref the error occurred (as a line number, and/or as a path to the problematic place, as for other validation errors)” and so I just clearly explained that I can’t do that right now. I also said “As for the error you’re seeing, I’ve created a json-refs issue to remedy this.” I’m not sure how this wasn’t clear.

The line number and column number are not the issue here. The issue is that Sway throws error instead of giving us the proper error message.