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

adds support for glob-style input spec paths and directory output paths #616

Merged
merged 3 commits into from
May 28, 2021

Conversation

sharmarajdaksh
Copy link
Contributor

This PR adds support for glob-style inputs and directory output paths for the openapi-typescript cli, as mentioned in #526.
With this, something like the following should be possible:

npx openapi-typescript specs/*.yaml -o outdir/
  • Maintains backwards compatibility, and throws reasonable helpful errors.
  • If the input is a glob path and -o flag it specified, it must be a directory
  • Cannot specify remote resources using glob-type paths

const outputManifold = fs.readFileSync(path.join(__dirname, "generated", "manifold.ts"), "utf8");
expect(outputPetstore).toBe(expectedPetstore);
expect(outputManifold).toBe(expectedManifold);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice test!

let result = "";
for (const specPath of inputSpecPaths) {
// append result returned for each spec
result += await generateSchema(specPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is clever. I hadn’t thought about the stdout case but this seems pretty handy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wait—we’re logging to stdout elsewhere. Truth be told, I don’t know why we’re returning the result here; it doesn’t seem to be helpful (and possibly wasting memory?). Either way, this is fine to leave in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, I was initially confused as well about what the reason to return the result was. In user usage, the returned result doesn't matter, but I think it gets used in certain tests so it should be kept in.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Yeah leave it in for now, and I can revisit that post-merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright!
Rebasing and updating expected schemas fixed the broken test, so I think this PR should be ready now

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.

This looks great to me! Only reason why the tests are failing is the “expected” output isn’t up-to-date with latest main; if you rebase then tests should pass. Great work!

@drwpow drwpow mentioned this pull request May 27, 2021
@codecov
Copy link

codecov bot commented May 27, 2021

Codecov Report

Merging #616 (eb73a76) into main (a36a728) will increase coverage by 1.71%.
The diff coverage is 88.31%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #616      +/-   ##
==========================================
+ Coverage   88.53%   90.25%   +1.71%     
==========================================
  Files           9       10       +1     
  Lines         349      390      +41     
  Branches      123      141      +18     
==========================================
+ Hits          309      352      +43     
- Misses         37       38       +1     
+ Partials        3        0       -3     
Impacted Files Coverage Δ
src/transform/headers.ts 23.07% <0.00%> (-4.20%) ⬇️
src/transform/index.ts 87.93% <78.78%> (+8.30%) ⬆️
src/transform/responses.ts 84.21% <81.81%> (-3.89%) ⬇️
src/transform/paths.ts 92.00% <87.50%> (ø)
src/transform/request.ts 95.00% <95.00%> (ø)
src/transform/parameters.ts 98.00% <96.42%> (+0.50%) ⬆️
src/index.ts 79.31% <100.00%> (+6.58%) ⬆️
src/transform/operation.ts 100.00% <100.00%> (+3.12%) ⬆️
src/transform/schema.ts 98.79% <100.00%> (+1.73%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4466097...eb73a76. Read the comment docs.

@drwpow drwpow merged commit 866409c into openapi-ts:main May 28, 2021
@drwpow
Copy link
Contributor

drwpow commented May 28, 2021

@all-contributors please add @sharmarajdaksh for code

@allcontributors
Copy link
Contributor

@drwpow

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

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.

2 participants