-
-
Notifications
You must be signed in to change notification settings - Fork 530
Feature request: Run on glob pattern, output to directory #526
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
Comments
Thanks for the suggestion! You know, I thought of this, but the main reason I didn’t implement this was I’d be scared that in auto-naming everything as you suggested, someone would ask for a different way to name the output files, and it would just be a pain. How do you feel about the current Generating multiple schemas section of the README? Would you suggest an alternate approach? I’d like to give people as many options as possible without locking them into a restriction of this library. |
Doing it in that style rapidly becomes pretty clunky as you accumulate multiple schema files (as you pretty rapidly can if you're trying to make specific bits of documentation on a big project for multiple external integrations), which is why I made the request to do it in a more integrated way. |
That‘s fair. I think it‘s something we can probably support, with the given restriction that renaming simply isn‘t allowed; filenames and folders will be carried over exactly 1:1. And for anything else, using the Node API is recommended. |
I'm using a shell script for generating from multiple schemas (also prepending with some eslint rules) #!/bin/sh
MYPWD=${PWD}
PACKAGE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )"
cd $PACKAGE_DIR
for spec_file in openapi-specs/*.yaml
do
file_name="${spec_file##*/}"
api_name="${file_name%.*}"
typescript_file="src/apigee-service/@generated-types/${api_name}.d.ts"
# `openapi-typescript` generates interface names in all lowercase - which doesn't comply with the project's lint rules
echo "/* eslint-disable @typescript-eslint/naming-convention */\n" > $typescript_file
npx openapi-typescript $spec_file \
--prettier-config prettier.config.js \
>> $typescript_file
done
cd $MYPWD |
@sharmarajdaksh sure! Here’s what I’d propose:
I propose keeping the same syntax: first (unnamed) input parameter could be a file or glob (I believe And let’s throw errors to be helpful:
This should be backwards-compatible and somewhat intuitive for users (personal opinion: I find CLI tools with different output flags for a file vs a directory to be cumbersome, especially since you can’t use both at the same time; so why not combine them?). Last suggestion: I’m slightly partial to tiny-glob over glob, especially for simple usecases like this. Hopefully that’s not too much direction! I just know there are probably a hundred ways one could implement this and I wanted to make implementation easier. |
@drwpow yeah, I looked through the code, and I agree that the glob behavior should be CLI-only, without impact on the Node API. |
@drwpow now that this feature is added in the main branch, should I also raise a PR updating the project README to mention glob support. I think this feature might have made the example using npm-run-all reduntant as well, so we could remove that (maybe?). P.S. - If I should raise this in a seperate issue, let me know. |
Merged! Thanks again. |
@sharmarajdaksh Sorry, I missed this. I’m going to do a release tonight, so I can update the README myself. But I’d love a PR if there’s anything you’d like to change or reword (will tag you when it’s up). |
A simple example of possible syntax:
This would run
openapi-typescript
once for each.yml
file inapi
, and output a file with a matching name (but with.ts
extension) tosrc/generated
.Alternately, this could use something like a
-m
(for 'match') flag to avoid any backwards compatibility questions:Other command line options would be identical to the single-file usage, but it might be useful to also have a
-p
flag to indicate running in parallel, where the default would be sequential (to play nice with limit-resource environments).The text was updated successfully, but these errors were encountered: