Skip to content

Commit e063506

Browse files
committed
Add glob feature to README
1 parent 2b2088e commit e063506

File tree

2 files changed

+16
-40
lines changed

2 files changed

+16
-40
lines changed

README.md

+15-34
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,32 @@ View examples:
2828
```bash
2929
npx openapi-typescript schema.yaml --output schema.ts
3030

31-
# 🤞 Loading spec from tests/v2/specs/stripe.yaml…
31+
# 🔭 Loading spec from schema.yaml…
3232
# 🚀 schema.yaml -> schema.ts [250ms]
33+
34+
npx openapi-typescript "specs/**/*.yaml" --output schemas/
35+
# 🔭 Loading spec from specs/one.yaml…
36+
# 🔭 Loading spec from specs/two.yaml…
37+
# 🔭 Loading spec from specs/three.yaml…
38+
# 🚀 specs/one.yaml -> schemas/one.ts [250ms]
39+
# 🚀 specs/two.yaml -> schemas/two.ts [250ms]
40+
# 🚀 specs/three.yaml -> schemas/three.ts [250ms]
3341
```
3442

43+
_Thanks to [@sharmarajdaksh](https://github.com/sharmarajdaksh) for the glob feature!_
44+
3545
#### ☁️ Reading specs from remote resource
3646

3747
```bash
3848
npx openapi-typescript https://petstore.swagger.io/v2/swagger.json --output petstore.ts
3949

40-
# 🤞 Loading spec from https://petstore.swagger.io/v2/swagger.json…
50+
# 🔭 Loading spec from https://petstore.swagger.io/v2/swagger.json…
4151
# 🚀 https://petstore.swagger.io/v2/swagger.json -> petstore.ts [650ms]
4252
```
4353

44-
_Thanks to @psmyrdek for the remote spec feature!_
54+
_Note: for obvious reasons, globbing doesn’t work for remote schemas_
55+
56+
_Thanks to [@psmyrdek](https://github.com/psmyrdek) for the remote spec feature!_
4557

4658
#### Using in TypeScript
4759

@@ -73,37 +85,6 @@ _Thanks to @gr2m for the operations feature!_
7385
npx openapi-typescript schema.yaml
7486
```
7587

76-
#### Generating multiple schemas
77-
78-
In your `package.json`, for each schema you’d like to transform add one `generate:specs:[name]` npm-script. Then combine
79-
them all into one `generate:specs` script, like so:
80-
81-
```json
82-
"scripts": {
83-
"generate:specs": "npm run generate:specs:one && npm run generate:specs:two && npm run generate:specs:three",
84-
"generate:specs:one": "npx openapi-typescript one.yaml -o one.ts",
85-
"generate:specs:two": "npx openapi-typescript two.yaml -o two.ts",
86-
"generate:specs:three": "npx openapi-typescript three.yaml -o three.ts"
87-
}
88-
```
89-
90-
If you use [npm-run-all][npm-run-all], you can shorten this:
91-
92-
```json
93-
"scripts": {
94-
"generate:specs": "run-p generate:specs:*",
95-
```
96-
97-
You can even specify unique options per-spec, if needed. To generate them all together, run:
98-
99-
```bash
100-
npm run generate:specs
101-
```
102-
103-
Rinse and repeat for more specs.
104-
105-
For anything more complicated, or for generating specs dynamically, you can also use the [Node API](#node).
106-
10788
#### CLI Options
10889

10990
| Option | Alias | Default | Description |

bin/cli.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,7 @@ async function main() {
143143
}
144144

145145
// error: tried to glob output to single file
146-
if (
147-
isGlob &&
148-
output === OUTPUT_FILE &&
149-
fs.existsSync(cli.flags.output) &&
150-
(await fs.promises.stat(cli.flags.output)).isFile()
151-
) {
146+
if (isGlob && output === OUTPUT_FILE && fs.existsSync(cli.flags.output) && fs.statSync(cli.flags.output).isFile()) {
152147
errorAndExit(`❌ Expected directory for --output if using glob patterns. Received "${cli.flags.output}".`);
153148
}
154149

0 commit comments

Comments
 (0)