-
-
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
Absolute path in $ref resolving errors are not helpful #76
Absolute path in $ref resolving errors are not helpful #76
Comments
Swagger-Parser relies on having absolute paths/URLs to each file in the schema, so it can accurately resolve If you don't want Swagger-Parser to use the CWD, then you can pass in any absolute path or URL. swaggerParser.validate('/some/absolute/path', myApiDefinition, ...);
swaggerParser.validate('http://example.com', myApiDefinition, ...); |
Ok fair enough. Something smells odd about it though.
|
@BigstickCarpet Seems related but ran into another issue with absolute paths and refs when writing a custom resolver.
my resolver looks up the schema via the $ref. This ref doesn't seem like it is avaialble to the resolver though... If the ref is url-like it works ok, and i get back Surely only the file resolver should be working this way? any other resolver should just get the raw ref to handle as it needs to. |
I just ran into this issue trying to update apiaryio/fury-adapter-swagger to version 4. Would it be possible to add an option to get the old behaviour back? |
I'd be happy to accept a PR that safely brings back the old behavior without breaking any of the existing functionality. Resolving and normalizing relative paths was the only way I could come up with to reliably and consistently resolve references. For example, consider that all of the following references could possibly point to the same file:
|
Pre- 4.0.0 when failing to parse a $ref, the error would come out like this:
Error resolving $ref pointer "#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.
Now it's kinda annoying since the cwd is added to the beginning by default. This path seems to be mostly useless since the document doesn't exist there and it's just guessing.
Error resolving $ref pointer "d:/git/node-app/#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.
(actual location)
d:/git/node-app/test/files/invalid-refs.json#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.'
It should probably just default to an empty string if the path is not provided, and output the same as it used to do. Then if a path is provided when calling validate/dereference, it uses that.
When calling
swaggerParser.validate(file, swagger, ...
I also see inconsistent results based on the value of the first parameter (path).swaggerParser.validate('', swagger, ...
gives meError resolving $ref pointer "d:/git/node-app/#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.
when i was expecting
Error resolving $ref pointer "#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.
swaggerParser.validate('foo', swagger, ...
gives meError resolving $ref pointer "d:/git/node-app/foo#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.
when i was expecting
Error resolving $ref pointer "foo#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.
swaggerParser.validate('d:/git/node-app/test/files/invalid-refs.json', swagger, ...
gives me the expectedError resolving $ref pointer "d:/git/node-app/test/files/invalid-refs.json#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.
swaggerParser.validate('./test/files/invalid-refs.json', swagger, ...
gives meError resolving $ref pointer "d:/git/node-app/test/files/invalid-refs.json#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.
when i was expectingError resolving $ref pointer "./test/files/invalid-refs.json#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.
TLDR:
The text was updated successfully, but these errors were encountered: