Skip to content

Fix Redoc CLI warning #1465

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

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ npx openapi-typescript https://petstore3.swagger.io/api/v3/openapi.yaml -o petst

### Multiple schemas

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`:
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`:

```yaml
apis:
core@v2:
root: ./openapi/openapi.yaml
openapi-ts:
x-openapi-ts:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👀

output: ./openapi/openapi.ts
external@v1:
root: ./openapi/external.yaml
openapi-ts:
x-openapi-ts:
output: ./openapi/openapi.ts
```

Expand Down
16 changes: 12 additions & 4 deletions packages/openapi-typescript/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Options
const OUTPUT_FILE = "FILE";
const OUTPUT_STDOUT = "STDOUT";
const CWD = new URL(`file://${process.cwd()}/`);
const REDOC_CONFIG_KEY = "x-openapi-ts";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A manually-typed constant 3× was a bug waiting to happen 😅


const timeStart = performance.now();

Expand Down Expand Up @@ -168,18 +169,25 @@ async function main() {
? new URL(`file://${redoc.configFile}`)
: new URL(redoc.configFile, `file://${process.cwd()}/`);
}
if (!api["openapi-ts"]?.output) {
if (!api[REDOC_CONFIG_KEY]?.output) {
// TODO: remove in stable v7
if (api["openapi-ts"]) {
errorAndExit(
`Please rename "openapi-ts" to "x-openapi-ts" in your Redoc config.`,
);
}

errorAndExit(
`API ${name} is missing an \`openapi-ts.output\` key. See https://openapi-ts.pages.dev/cli/#multiple-schemas.`,
`API ${name} is missing an \`${REDOC_CONFIG_KEY}.output\` key. See https://openapi-ts.pages.dev/cli/#multiple-schemas.`,
);
}
const result = await generateSchema(new URL(api.root, configRoot), {
redoc, // TODO: merge API overrides better?
});
const outFile = new URL(api["openapi-ts"].output, configRoot);
const outFile = new URL(api[REDOC_CONFIG_KEY].output, configRoot);
fs.mkdirSync(new URL(".", outFile), { recursive: true });
fs.writeFileSync(outFile, result, "utf8");
done(name, api["openapi-ts"].output, performance.now() - timeStart);
done(name, api[REDOC_CONFIG_KEY].output, performance.now() - timeStart);
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ extends:
apis:
a@v1:
root: ./openapi/a.yaml
openapi-ts:
x-openapi-ts:
output: ./output/a.ts
b@v1:
root: ./openapi/b.yaml
openapi-ts:
x-openapi-ts:
output: ./output/b.ts
c@v1:
root: ./openapi/c.yaml
openapi-ts:
x-openapi-ts:
output: ./output/c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ extends:
apis:
a@v1:
root: ./openapi/a.yaml
openapi-ts:
x-openapi-ts:
output: ./output/a.ts
b@v1:
root: ./openapi/b.yaml
openapi-ts:
x-openapi-ts:
output: ./output/b.ts
c@v1:
root: ./openapi/c.yaml
openapi-ts:
x-openapi-ts:
output: ./output/c.ts