Skip to content

Commit 3994af5

Browse files
authored
Fix Redoc CLI error (#1465)
1 parent aaca108 commit 3994af5

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

docs/cli.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ npx openapi-typescript https://petstore3.swagger.io/api/v3/openapi.yaml -o petst
2727

2828
### Multiple schemas
2929

30-
To transform multiple schemas, create a `redocly.yaml` file in the root of your project with [APIs defined](https://redocly.com/docs/cli/configuration/). Under `apis`, give each schema a unique name and optionally a version (the name doesn’t matter, so long as it’s unique). Set the `root` value to your schema’s entry point—this will act as the main input. For the output, set it with `openapi-ts.output`:
30+
To transform multiple schemas, create a `redocly.yaml` file in the root of your project with [APIs defined](https://redocly.com/docs/cli/configuration/). Under `apis`, give each schema a unique name and optionally a version (the name doesn’t matter, so long as it’s unique). Set the `root` value to your schema’s entry point—this will act as the main input. For the output, set it with `x-openapi-ts.output`:
3131

3232
```yaml
3333
apis:
3434
core@v2:
3535
root: ./openapi/openapi.yaml
36-
openapi-ts:
36+
x-openapi-ts:
3737
output: ./openapi/openapi.ts
3838
external@v1:
3939
root: ./openapi/external.yaml
40-
openapi-ts:
40+
x-openapi-ts:
4141
output: ./openapi/openapi.ts
4242
```
4343

packages/openapi-typescript/bin/cli.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Options
3838
const OUTPUT_FILE = "FILE";
3939
const OUTPUT_STDOUT = "STDOUT";
4040
const CWD = new URL(`file://${process.cwd()}/`);
41+
const REDOC_CONFIG_KEY = "x-openapi-ts";
4142

4243
const timeStart = performance.now();
4344

@@ -168,18 +169,25 @@ async function main() {
168169
? new URL(`file://${redoc.configFile}`)
169170
: new URL(redoc.configFile, `file://${process.cwd()}/`);
170171
}
171-
if (!api["openapi-ts"]?.output) {
172+
if (!api[REDOC_CONFIG_KEY]?.output) {
173+
// TODO: remove in stable v7
174+
if (api["openapi-ts"]) {
175+
errorAndExit(
176+
`Please rename "openapi-ts" to "x-openapi-ts" in your Redoc config.`,
177+
);
178+
}
179+
172180
errorAndExit(
173-
`API ${name} is missing an \`openapi-ts.output\` key. See https://openapi-ts.pages.dev/cli/#multiple-schemas.`,
181+
`API ${name} is missing an \`${REDOC_CONFIG_KEY}.output\` key. See https://openapi-ts.pages.dev/cli/#multiple-schemas.`,
174182
);
175183
}
176184
const result = await generateSchema(new URL(api.root, configRoot), {
177185
redoc, // TODO: merge API overrides better?
178186
});
179-
const outFile = new URL(api["openapi-ts"].output, configRoot);
187+
const outFile = new URL(api[REDOC_CONFIG_KEY].output, configRoot);
180188
fs.mkdirSync(new URL(".", outFile), { recursive: true });
181189
fs.writeFileSync(outFile, result, "utf8");
182-
done(name, api["openapi-ts"].output, performance.now() - timeStart);
190+
done(name, api[REDOC_CONFIG_KEY].output, performance.now() - timeStart);
183191
}),
184192
);
185193
}

packages/openapi-typescript/test/fixtures/redocly-flag/redocly.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ extends:
44
apis:
55
a@v1:
66
root: ./openapi/a.yaml
7-
openapi-ts:
7+
x-openapi-ts:
88
output: ./output/a.ts
99
b@v1:
1010
root: ./openapi/b.yaml
11-
openapi-ts:
11+
x-openapi-ts:
1212
output: ./output/b.ts
1313
c@v1:
1414
root: ./openapi/c.yaml
15-
openapi-ts:
15+
x-openapi-ts:
1616
output: ./output/c.ts

packages/openapi-typescript/test/fixtures/redocly/redocly.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ extends:
44
apis:
55
a@v1:
66
root: ./openapi/a.yaml
7-
openapi-ts:
7+
x-openapi-ts:
88
output: ./output/a.ts
99
b@v1:
1010
root: ./openapi/b.yaml
11-
openapi-ts:
11+
x-openapi-ts:
1212
output: ./output/b.ts
1313
c@v1:
1414
root: ./openapi/c.yaml
15-
openapi-ts:
15+
x-openapi-ts:
1616
output: ./output/c.ts

0 commit comments

Comments
 (0)