question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$refs to local filesystem paths are URL encoded, resulting in no such file or directory error

See original GitHub issue

Checklist

  • Conversion: I have checked my source definition is valid OpenAPI 2.0
  • Conversion: On valid OpenAPI 2.0 input, the conversion looks wrong
  • Validation: I believe my source definition is valid OpenAPI 3.0.x but the validator complains
  • Validation: I believe my source definition is invalid OpenAPI 3.0.x but the validator does not complain
  • Linting issue
  • Resolver issue

Detailed Description

When resolving $refs, if the local filesystem path contains spaces (e.g. /some/path/with spaces/swagger.json) the paths are incorrectly URL encoded, resulting in the following error:

ENOENT: no such file or directory, open '/some/path/with%20spaces/ref.json'

It would appear the problem is being caused by URL encoding that is being performed by URL, which translates the spaces to %20 and ultimately results in the files not being found on the local filesystem. With the white-space removed from the path, the parser works fine and our project is validated correctly.

This issue was discovered when we started using speccy to validate our swagger documentation as part of our CI pipeline where the Jenkins job name contained a space. We have worked around it for the time being by renaming the job, but thought we should bring this to your attention.

Other stuff

We are using speccy to validate our OpenAPI 3.0 documentation.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MikeRalphsoncommented, Apr 23, 2019

No problem, should be covered by tests such as test/resolver/speccy 141.

0reactions
umeshp7commented, Jun 3, 2020

We are also facing this issue. when trying to use oas-resolver for folder containing spaces it tends to fail with ENOENT: no such file or directory, open '/Users/umesh/<more-folders>/petstore%20separate%20yaml/spec/Pet.yaml petstore separate yaml.zip Please try to resolve the above folder and let me know if it is failing for you as well.

@MikeRalphson

Edit: After increasing the level of verbosity I found out the exact place where this is happening: Rewriting external ref Pet.yaml as /Users/umesh/<more-folders>/petstore%20separate%20yaml/spec/Pet.yaml

https://github.com/Mermade/oas-kit/blob/master/packages/oas-resolver/index.js#L89

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Is there a convenient way to map a file uri to os.path?
Use urllib.parse.urlparse to get the path from the URI: ... using unquote to escape/decode the URL percent-encoding, which your filesystem ...
Read more >
Working with file system paths and file URLs on Node.js - 2ality
In this blog post, we learn how to work with file system paths and file URLs on Node.js.
Read more >
API Reference — fsspec 2022.11.0+13.g0974514.dirty ...
Given a path or paths, return a list of OpenFile objects. ... An empty directory on the local file-system where the contents of...
Read more >
Path Traversal | OWASP Foundation
Overview. A path traversal attack (also known as directory traversal) aims to access files and directories that are stored outside the web root...
Read more >
RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
This specification does not define a generative grammar for URIs; ... Local names, such as file system names, are stored with a local...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found