json-schema-ref-parser icon indicating copy to clipboard operation
json-schema-ref-parser copied to clipboard

Incorrect path resolving for absolut paths under windows

Open ScienceOfficer opened this issue 2 years ago • 0 comments

Hello everyone,

unfortunately I noticed that the resolving of absolute paths under windows is not working for me. The code doesn't seem to recognize that a absolute path is entered and prepends another absolute path.

I tracked the error down to this function (https://github.com/APIDevTools/json-schema-ref-parser/blob/main/lib/util/url.ts#L177). Both checks hasProjectDir and hasProjectUri evaluate to false as my api.yaml isn't part of this project. projectDir evaluates to C:\Projekte\projectname\node_modules\@apidevtools\json-schema-ref-parser\dist\ in my setup but only C:\Projekte\projectname is shared between the library and the source code of the project.

It would be great if the problem could be fixed!

Here is also the stacktrace where you can see, what happend to the absolute path.

{
  "stack":"JSONParserError: Error opening file "C:\Projekte\projectname\node_modules\@apidevtools\json-schema-ref-parser\dist\C:\Projekte\projectname\dist\server\api.yaml" ENOENT: no such file or directory, open 'C:\Projekte\projectname\node_modules\@apidevtools\json-schema-ref-parser\dist\C:\Projekte\projectname\dist\server\api.yaml' at Object.<anonymous> (C:\Projekte\projectname\node_modules\@apidevtools\json-schema-ref-parser\dist\lib\resolvers\file.js:72:23) at Generator.throw (<anonymous>) at rejected (C:\Projekte\projectname\node_modules\@apidevtools\json-schema-ref-parser\dist\lib\resolvers\file.js:29:65)",
  "code":"ERESOLVER",
  "name":"ResolverError",
  "message":"Error opening file "C:\Projekte\projectname\node_modules\@apidevtools\json-schema-ref-parser\dist\C:\Projekte\projectname\dist\server\api.yaml" ENOENT: no such file or directory, open 'C:\Projekte\projectname\node_modules\@apidevtools\json-schema-ref-parser\dist\C:\Projekte\projectname\dist\server\api.yaml'",
  "source":"C:\Projekte\projectname\node_modules\@apidevtools\json-schema-ref-parser\dist\C:\Projekte\projectname\dist\server\api.yaml",
  "path":null,
  "ioErrorCode":"ENOENT",
  "footprint":"null+C:\Projekte\projectname\node_modules\@apidevtools\json-schema-ref-parser\dist\C:\Projekte\projectname\dist\server\api.yaml+ERESOLVER+Error opening file "C:\Projekte\projectname\node_modules\@apidevtools\json-schema-ref-parser\dist\C:\Projekte\projectname\dist\server\api.yaml" ENOENT: no such file or directory, open 'C:\Projekte\projectname\node_modules\@apidevtools\json-schema-ref-parser\dist\C:\Projekte\projectname\dist\server\api.yaml'"
}

Used version of apidevtools: "@apidevtools/json-schema-ref-parser": "10.1.0"

ScienceOfficer avatar Mar 08 '23 07:03 ScienceOfficer