Skip to content

Absolute path in $ref resolving errors are not helpful #76

Closed
APIDevTools/json-schema-ref-parser
#75
@alasdairhurst

Description

@alasdairhurst

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).

  1. swaggerParser.validate('', swagger, ... gives me Error 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.
  2. swaggerParser.validate('foo', swagger, ... gives me Error 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.
  3. swaggerParser.validate('d:/git/node-app/test/files/invalid-refs.json', swagger, ... gives me the expected Error resolving $ref pointer "d:/git/node-app/test/files/invalid-refs.json#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.
  4. swaggerParser.validate('./test/files/invalid-refs.json', swagger, ... gives me Error resolving $ref pointer "d:/git/node-app/test/files/invalid-refs.json#/definitions/ApiResponse". \nToken "ApiResponse" does not exist. when i was expecting Error resolving $ref pointer "./test/files/invalid-refs.json#/definitions/ApiResponse". \nToken "ApiResponse" does not exist.

TLDR:

  1. The use of process.cwd() for the default path seems wrong
  2. I can't seem to specify a custom path without it trying to resolve it. This may be expected behaviour if it's trying to use the path to get the swagger, but if the swagger is already provided, this seems to only be used for logging so should be customizable.
  3. It's difficult to test error messages now since I now need to convert the path using the same logic as swagger-parser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions