Skip to content

Commit 45c8396

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

File tree

2 files changed

+18
-40
lines changed

2 files changed

+18
-40
lines changed

README.md

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,34 @@ 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+
_Note: if generating a single schema, `--output` must be a file (preferably `*.ts`). If using globs, `--output` must be a directory._
44+
45+
_Thanks to [@sharmarajdaksh](https://github.com/sharmarajdaksh) for the glob feature!_
46+
3547
#### ☁️ Reading specs from remote resource
3648

3749
```bash
3850
npx openapi-typescript https://petstore.swagger.io/v2/swagger.json --output petstore.ts
3951

40-
# 🤞 Loading spec from https://petstore.swagger.io/v2/swagger.json…
52+
# 🔭 Loading spec from https://petstore.swagger.io/v2/swagger.json…
4153
# 🚀 https://petstore.swagger.io/v2/swagger.json -> petstore.ts [650ms]
4254
```
4355

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

4660
#### Using in TypeScript
4761

@@ -73,37 +87,6 @@ _Thanks to @gr2m for the operations feature!_
7387
npx openapi-typescript schema.yaml
7488
```
7589

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-
10790
#### CLI Options
10891

10992
| Option | Alias | Default | Description |

bin/cli.js

Lines changed: 1 addition & 6 deletions
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)