Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON References aren't properly URL-decoded #871

Closed
JamesMessinger opened this issue Apr 15, 2016 · 8 comments
Closed

JSON References aren't properly URL-decoded #871

JamesMessinger opened this issue Apr 15, 2016 · 8 comments

Comments

@JamesMessinger
Copy link

Swagger Editor erroneously shows "Reference could not be resolved" errors for JSON references that contain URL-encoded characters. For example, "#/definitions/foo%20bar" instead of "#/definitions/foo bar". According to RFC 6901, sections 5 & 6, JSON pointers should be URL-encoded.

Here's a simplistic example: https://gist.github.com/BigstickCarpet/5ad1a760acbb598d38c5dbba223eb9bd

And here's a more real-world example: https://gist.github.com/BigstickCarpet/e867ccd425e730634ee71f43c462a34f

As far as I know, Swagger Editor uses json-refs under the hood to do its JSON Pointer decoding. json-refs has the correct logic for decoding URL-encoded JSON Pointers, so maybe Swagger Editor is just using an older version of json-refs? Maybe @whitlockjc can provide more info.

@glen-84
Copy link

glen-84 commented Apr 15, 2016

I think this is affecting Swagger UI as well.

@saharj
Copy link
Contributor

saharj commented Apr 20, 2016

This is a Sway issue.

@glen-84
Copy link

glen-84 commented Apr 23, 2016

@saharj Thanks, I've submitted apigee-127/sway#72.

@shockey
Copy link
Contributor

shockey commented Mar 1, 2018

The resolution is fixed in 3.x, but there's an incorrect "Definition is never used" warning when using the correctly escaped $ref (with %20).

@glen-84
Copy link

glen-84 commented May 13, 2018

When this is fixed, I can bundle my spec and reduce the file size by over 50%.

@glen-84
Copy link

glen-84 commented May 13, 2018

Actually no, I'm still seeing:

Semantic error at paths./blogs/{id}/posts.get.responses.200.schema.items.$ref
$refs must reference a valid location in the document

With this file.

Is https://editor.swagger.io/ using the latest version?

@shockey
Copy link
Contributor

shockey commented May 15, 2018

Yeah, you're right @glen-84, this has cropped back up.

Reopening!

@shockey shockey closed this as completed May 15, 2018
@shockey shockey reopened this May 15, 2018
@shockey shockey modified the milestones: Backlog, May 18, 2018 May 15, 2018
@shockey
Copy link
Contributor

shockey commented May 18, 2018

This is going to land in a few parts (this week):

  1. Extending Swagger-Client to handle percent-encoded $refs, while still allowing unescaped values* so that we don't break anyone's documents
  2. Adding validators for unescaped $ref values in Swagger-Editor
  3. Taming the validators that complain about escaped $ref values

*I usually don't allow non-spec behavior to hang around, but since the correct way to do this has been broken and the incorrect way has been working, I imagine we have a lot of this in the wild. I've made a note in the codebase to consider dropping this behavior in v4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants