-
Notifications
You must be signed in to change notification settings - Fork 401
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
cwd option creates invalid path #519
Comments
We're seeing this too, with or without the CWD option set, via the CLI Affects 12.0.0, 11.0.5, 11.0.4 - 11.0.3 - 11.01 seem fine |
👍🏼 on this
|
This is coming from the json-schema-ref-parser library. I put together a PR to fix it: APIDevTools/json-schema-ref-parser#315 not sure how quickly a maintainer will get to it. |
same here:
|
My current workaround is providing this to options: {
$refOptions: {
resolve: {
file: {
async read(file: FileInfo): Promise<string> {
if (
process.platform === 'win32' &&
file.url.split(':').length > 1
) {
[, file.url] = file.url.match(/(.:[^:]+)$/) ?? [, 'error'];
}
return await readFile(file.url, 'utf8');
},
},
},
} |
@matt1097 PRs for https://github.com/bcherny/json-schema-ref-parser are welcome. I also see a reasonable suggestion on your PR -- could using Node's |
I'll make a PR. @bcherny since you already use path in your library here, i am willing to switch that chunk of code over to using path. the tradeoff being your fork becoming more distant from the original. If you are ok with that, I will take a stab at it. |
Why not use a library like pathe? |
we experience this issue too |
Would love to see this resolved as while meepen's solution worked at first, having a schema reference a file in the same folder causes it to error again. |
I'm using I tried to debug and found some issues in
My temporary solution is to use For instance, I encountered an issue with this function: const path_1 = require("path");
…
function fromFileSystemPath(path) {
// Step 1: On Windows, replace backslashes with forward slashes,
// rather than encoding them as "%5C"
if (isWindows) {
const hasProjectDir = path.toUpperCase().includes(projectDir.replace(/\\/g, "\\").toUpperCase());
const hasProjectUri = path.toUpperCase().includes(projectDir.replace(/\\/g, "/").toUpperCase());
if (hasProjectDir || hasProjectUri) {
path = path.replace(/\\/g, "/");
}
else {
path = `${projectDir}/${path}`.replace(/\\/g, "/");
}
}
// Step 2: `encodeURI` will take care of MOST characters
path = encodeURI(path);
// Step 3: Manually encode characters that are not encoded by `encodeURI`.
// This includes characters such as "#" and "?", which have special meaning in URLs,
// but are just normal characters in a filesystem path.
for (let i = 0; i < urlEncodePatterns.length; i += 2) {
path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]);
}
return path;
}
exports.fromFileSystemPath = fromFileSystemPath; I modified it to: const path_1 = require("path");
…
function fromFileSystemPath(path) {
return path_1.resolve(path);
}
exports.fromFileSystemPath = fromFileSystemPath; To apply the patch using pnpm patch @apidevtools/json-schema-ref-parser
// Open the temporary folder and apply the above modifications
pnpm patch-commit tempfile // Refer to pnpm's instructions |
@bcherny Is it possible this issue will be fixed if https://github.com/bcherny/json-schema-ref-parser is synced with the latest from https://github.com/APIDevTools/json-schema-ref-parser, currently shows that its 47 commits behind. I see they have since merged in the fixes for Issue #311 in APIDevTools/json-schema-ref-parser#321. |
looks like this is fixed in v15.0 |
(on windows) looks like it adds the process path to the CWD option.
worked fine in 11.0.3
with 12.0 I got:
my code:
The text was updated successfully, but these errors were encountered: