Skip to content

Fix path generation #991

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

Merged
merged 2 commits into from
Apr 5, 2023
Merged

Fix path generation #991

merged 2 commits into from
Apr 5, 2023

Conversation

HiiiiD
Copy link
Contributor

@HiiiiD HiiiiD commented Nov 15, 2022

Changes

What does this PR change? Link to any related issue(s).

Currently, if a url like https://api-test.<website>/docs/json is passed, then the regex creates a file with the https:// prefix before it, and so it doesn't work. It creates a file like https://api-test.<website>.ts

How to Review

How can a reviewer review your changes? What should be kept in mind for this review?

Checklist

  • Unit tests updated
  • README updated
  • examples/ directory updated (if applicable)

@drwpow
Copy link
Contributor

drwpow commented Nov 16, 2022

Thank you for adding! Could you add a test for this? I do think you are fixing an issue here but I’m not sure in what scenario this is encountered. A test would help.

@HiiiiD
Copy link
Contributor Author

HiiiiD commented Nov 16, 2022

Can't add a test to verify that what I'm doing is right but the issue is that here there's a regex to rename the file
The fact is that if you put https://<domain>/docs.json, then it returns a URL resolved with https that clearly doesn't work

@HiiiiD
Copy link
Contributor Author

HiiiiD commented Nov 16, 2022

BTW I've tried a couple more combinations and I've figured out that I should update the regex I've done because it doesn't cover all the cases

@HiiiiD
Copy link
Contributor Author

HiiiiD commented Nov 16, 2022

I've removed the previous regex replace that I've added
Now https://<domain>.com/* with --output <dir>/ translates to <dir>/<domain>.ts while before, it the last part contained a . created a path like <dir>/<domain>/<before-dot>/*.ts

@drwpow
Copy link
Contributor

drwpow commented Nov 16, 2022

Ohh the https is in the filename itself. I see. I think this is testable! It just may involve possibly mocking fetch as well as fs.writeFileSync for the test.

@HiiiiD
Copy link
Contributor Author

HiiiiD commented Nov 16, 2022

I think that testing this PR may require #990 due to the fact that Pascal case headers don't seem to work

@drwpow
Copy link
Contributor

drwpow commented Nov 23, 2022

Got it. Merged #990!

@HiiiiD HiiiiD force-pushed the fix-path-generation branch from ec2f7d6 to 5f20b22 Compare November 23, 2022 17:38
@HiiiiD
Copy link
Contributor Author

HiiiiD commented Nov 23, 2022

I think I've an issue with tests
It shows 24 failed tests, with the codebase on the main branch

Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So sorry about the delay to merging this one. It slipped through the cracks. Thank you for your patience!

@drwpow drwpow merged commit f92f753 into openapi-ts:main Apr 5, 2023
@drwpow
Copy link
Contributor

drwpow commented Apr 5, 2023

@all-contributors please add @HiiiiD for code, bug

@allcontributors
Copy link
Contributor

@drwpow

I've put up a pull request to add @HiiiiD! 🎉

@dgee2
Copy link

dgee2 commented Apr 26, 2023

Thanks this is really useful for me (hoping to get http yaml files on our build server rather than storing them in source control for a project)

It does look like this has broken another scenario where I'm loading all yaml files from a directory. The following gives an error on both windows and our linux build server. I assume it is because of the wildcard search for the input files.

openapi-typescript ./open-api/*.yaml --output ./src/generated/open-api

Output from yarn:

$ openapi-typescript ./open-api/*.yaml --output ./src/generated/open-api
✨ openapi-typescript 6.2.2
node:fs:599
  handleErrorFromBinding(ctx);
  ^

Error: EISDIR: illegal operation on a directory, open 'C:\git\cyclone_accountmanagementui\cyclone_accountmanagementui\src\generated\open-api'
    at Object.openSync (node:fs:599:3)
    at Object.writeFileSync (node:fs:2221:35)
    at generateSchema (file:///C:/git/cyclone_accountmanagementui/cyclone_accountmanagementui/node_modules/openapi-typescript/bin/cli.js:122:8)
    at async file:///C:/git/cyclone_accountmanagementui/cyclone_accountmanagementui/node_modules/openapi-typescript/bin/cli.js:195:7
    at async Promise.all (index 0)
    at async main (file:///C:/git/cyclone_accountmanagementui/cyclone_accountmanagementui/node_modules/openapi-typescript/bin/cli.js:185:3) {
  errno: -4068,
  syscall: 'open',
  code: 'EISDIR',
  path: 'C:\\git\\cyclone_accountmanagementui\\cyclone_accountmanagementui\\src\\generated\\open-api'
}

Node.js v18.7.0
error Command failed with exit code 1.

@HiiiiD
Copy link
Contributor Author

HiiiiD commented Apr 26, 2023

Gotcha @dgee2, it's because we're using writeFileSync
I personally didn't think of a directory, and didn't see any test on it, so I skipped this case
I'd suggest creating an issue and I'll take a look as soon as I can💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants