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"

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)
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.0but I’ve not updatedswayyet. 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
definitionshad a slash/after#, i.e. : like$ref: "#/definitions/Address"instead ofConclusion : Solution is adding the slash$ref: "#definitions/Address"/in the reference todefinitions:$ref: #/definitions...NB: the bug showing up was :
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.