-
-
Notifications
You must be signed in to change notification settings - Fork 528
mirror directory structure if output is a directory #1345
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
mirror directory structure if output is a directory #1345
Conversation
🦋 Changeset detectedLatest commit: ff00349 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
create directory structure if we are dealing with multiple files or output directory and file paths match (which indicates it's a directory)
Thanks so much for this fix! Is there any chance you’d be interested in writing a test for this? I think part of the reason why this regressed was no glob test in the test suite. If you have time, I’d love to see if we could:
Bonus points if the test has nested directories. Each schema could be basically a stub / as minimal as possible as output is tested in many other tests; this would be a purely file structure test. Would adding that test be possible for this PR, to ensure a future regression doesn’t happen? |
Added a bunch of tests:
PS: sorry for the missing commit signature verification... gonna setup now. |
@@ -76,4 +85,59 @@ describe("CLI", () => { | |||
expect(stdout).toEqual(expect.stringMatching(/^v[\d.]+(-.*)?$/)); | |||
}); | |||
}); | |||
|
|||
describe("outputs", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
The tests look great, thank you! And no worries about commit signature verification. I think we might want to either roll back #1335 or take another look into if there’s a fix for that small regression. But either way once that’s resolved, this fix will go out in the next release. |
@@ -114,13 +114,13 @@ async function generateSchema(pathToSpec) { | |||
let outputFilePath = new URL(flags.output, CWD); // note: may be directory | |||
const isDir = fs.existsSync(outputFilePath) && fs.lstatSync(outputFilePath).isDirectory(); | |||
if (isDir) { | |||
if (typeof flags.output === 'string' && !flags.output.endsWith('/')) { | |||
outputFilePath = new URL(`${flags.output}/`, CWD) | |||
if (typeof flags.output === "string" && !flags.output.endsWith("/")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we’re accidentally skipping this from linting/Prettier. Thanks for fixing this file.
Changes
Fixes #1337
Mirror the directory structure of input files if output is a directory. This prevents overwriting the same file again and again if there are multiple input files.
How to Review
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)