-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
Fails to resolve file-based $refs with definitions #8
Comments
Hi, thanks for opening this issue. Swagger Parser doesn't currently support deep-linking into files using hash fragments, but I can definitely add that. Expect it soon. Also, when referencing an external file, you don't need to start the file name with a period ( |
Thanks, that would be great if you could add it! I've been playing around with trying to get it to work and can get the // resolve.js:76
resolve$Ref(value.$ref.split("#/")[0], $refPath, state, callback); Produces refs with: '$refs': {
"./core.yaml": { definitions: [Object] },
"/home/core.yaml": { definitions: [Object] }
} and this doesn't seem to produce any errors. However, modifying
That's interesting, in some of my earlier tests I didn't have any file extension on the referenced file which I guess is why it didn't like it. |
As a workaround for now, I can get it to work by splitting each definition into a separate file e.g. # error.yaml
type: object
properties:
error:
type: string
required: ["error"] |
I found this in swagger documentation: |
I actually started working on this last night. (sorry for taking so long, but I've been totally swamped at work for the past few weeks) This fix is part of a larger refactoring that will fix a few related bugs as well, so it's going to take a few days to finish. I'm hoping to finish it by next week. As a side-bonus, it should also improve performance - especially on Internet Explorer. |
Hey @BigstickCarpet just wondering how that linking is going and if there's anything I could do to help! I was stumped by this error when running I understand if you're busy at work. I have to do some swagger definitions for my own job so if you'd like to set up a feature branch and give me some guidance I could tackle this issue on Monday. |
@mrkev @jkordas @kegsay - I'm making good progress on this, but it's a major refactoring, since Swagger Parser doesn't properly adhere to the JSON Reference and JSON Pointer specs. To be fair, this is because the early drafts of the Swagger 2.0 spec also didn't comply fully with JSON Reference and JSON Schema, but the current version of the Swagger 2.0 spec is compliant with both, so now I'm making Swagger Parser compliant as well. This refactoring consists of two parts: Part 1Split Swagger Parser into two different projects, one for JSON Schema logic and one for Swagger logic. The new project — which deals with all the JSON Schema logic — is called JSON Schema $Ref Parser. I just released Part 2Refactor Swagger Parser to use JSON Schema $Ref Parser for all of its JSON Schema logic. This will make Swagger Parser's code much cleaner, easier to understand, and easier to maintain. It will also make it fully-compliant with the JSON Reference and JSON Pointer specs. I just started this task today, and I should have Swagger Parser |
👍 |
I've created a v3.0.0 branch for this refactoring. It's still in progress, but here's some documentation to get you started. You can install the new version by explicitly specifying the npm install swagger-parser@alpha The API is totally different from v2.5. Here are the key changes:
|
@BigstickCarpet I need the dereferencing, so I guess I'll need to wait a bit longer. 😃 |
@glen-84 - DISCLAIMER: When I say it's "already working", I mean that I manually tested it on a few sample files, and the output looked as expected. I'm still in the process of refactoring all of my unit tests from the old API to the new API, so it's possible that I'll discover bugs in the code once the unit tests are working. |
http://pastie.org/private/0ozh5wm8li9qrrifl9cbua (swagger.yaml) |
@glen-84 - What operating system are you on? Based on the error message, it looks like Windows. I haven't tested the new code on Windows yet, but I can do that tonight. |
Windows 7. |
It seems to work on Linux, so it must be a Windows issue. Did you find anything last night? |
@glen-84 - Yeah, I found the issue. The code is mistakenly parsing Windows paths as URLs, so |
Awesome, thank you! 😃 |
Alright, it works on Windows now. Update to |
❤️ BTW, I'm using relative references now, but in my old version, I was using remote refs, which don't seem to work:
I just thought I'd mention it. |
@glen-84 - Thanks for catching that. Dumb oversight on my part. It's fixed now (upgrade to |
👍 |
FYI - Swagger 3.0.0 is now officially released, and it includes this fix |
If you reference a definition in another file, the parser fails to load it because it doesn't strip before the
#
.Fails with:
As an aside, I believe that when
$ref
references files, it is not compulsory to put a starting.
(this threw me off for a while as I was tryingfoo.yaml#/definitions/Error
instead of./foo.yaml#/definitions/Error
. It was only when debuggingresolve.js
did I notice:The text was updated successfully, but these errors were encountered: