Skip to content
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

Error saving output on windows with full file paths instead of relative #1745

Closed
1 of 2 tasks
jarrodls opened this issue Jul 5, 2024 · 0 comments · Fixed by #1747
Closed
1 of 2 tasks

Error saving output on windows with full file paths instead of relative #1745

jarrodls opened this issue Jul 5, 2024 · 0 comments · Fixed by #1747
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@jarrodls
Copy link

jarrodls commented Jul 5, 2024

Description

When trying to generate types on Windows and using a full filepath as the output it will error. It does not have the same issue for the input path. If you change the output path to something like ./output.d.ts or ../output.d.ts it seems to handle those fine.

The issue seems to be here where you are trying to create a new URL based on the output file but trying to prefix it with . which will error when given a full path instead of a relative path.

const outFile = new URL(flags.output, CWD);
fs.mkdirSync(new URL(".", outFile), { recursive: true });
fs.writeFileSync(outFile, result, "utf8");

 npx openapi-typescript C:\Users\User\Desktop\swagger.json -o C:\Users\User\Desktop\output.d.ts
✨ openapi-typescript 7.0.2
node:internal/url:797
    this.#updateContext(bindingUrl.parse(input, base));
                                   ^

TypeError: Invalid URL
    at new URL (node:internal/url:797:36)
    at main (file:https:///O:/.packageCache/npm/_npx/21d31b7563e6adbc/node_modules/openapi-typescript/bin/cli.js:206:20) {
  code: 'ERR_INVALID_URL',
  input: '.',
  base: 'c:\\Users\\User\\Desktop\\output.d.ts'
}
Name Version
openapi-typescript 7.0.2
Node.js 20.15.0
OS + version Windows 11

Reproduction

Try to generate a types file with a full filepath on Windows such as C:\Users\User\Desktop\output.d.ts

 npx openapi-typescript C:\Users\User\Desktop\swagger.json -o C:\Users\User\Desktop\output.d.ts

Expected result

It shouldn't error and should support the path like any other

Checklist

@jarrodls jarrodls added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant