Skip to content

Commit c9e26a4

Browse files
committed
Fix Redocly automatic config loading
1 parent 952eb99 commit c9e26a4

File tree

7 files changed

+1097
-7
lines changed

7 files changed

+1097
-7
lines changed

packages/openapi-typescript/bin/cli.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,16 @@ async function main() {
161161
}
162162
await Promise.all(
163163
Object.entries(redoc.apis).map(async ([name, api]) => {
164-
const configRoot = redoc?.configFile
165-
? new URL(`file://${redoc.configFile}`)
166-
: CWD;
164+
let configRoot = CWD;
165+
if (redoc?.configFile) {
166+
configRoot = new URL(redoc.configFile, `file://${process.cwd()}/`);
167+
}
167168
if (!api["openapi-ts"]?.output) {
168169
errorAndExit(
169170
`API ${name} is missing an \`openapi-ts.output\` key. See https://openapi-ts.pages.dev/cli/#multiple-schemas.`,
170171
);
171172
}
173+
console.log({ root: api.root, configRoot: configRoot.href });
172174
const result = await generateSchema(new URL(api.root, configRoot), {
173175
redoc, // TODO: merge API overrides better?
174176
});

packages/openapi-typescript/test/cli.test.ts

+22-4
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,33 @@ describe("CLI", () => {
114114
});
115115
});
116116

117-
describe("Redocly config", () => {
118-
test("accepts multiple APIs", async () => {
119-
await execa(cmd, ["--redoc", "test/fixtures/redocly/redocly.yaml"], {
117+
describe.only("Redocly config", () => {
118+
test("automatic config", async () => {
119+
/* eslint-disable @typescript-eslint/no-shadow */
120+
121+
// note: we have to change the cwd here for the automatic config to pick up properly
122+
const root = new URL("./fixtures/redocly/", import.meta.url);
123+
const cwd = os.platform() === "win32" ? fileURLToPath(root) : root;
124+
125+
await execa("../../../bin/cli.js", { cwd });
126+
for (const schema of ["a", "b", "c"]) {
127+
expect(
128+
fs.readFileSync(new URL(`./output/${schema}.ts`, root), "utf8"),
129+
).toMatchFileSnapshot(
130+
fileURLToPath(new URL("../../../examples/simple-example.ts", root)),
131+
);
132+
}
133+
/* eslint-enable @typescript-eslint/no-shadow */
134+
});
135+
136+
test("--redoc config", async () => {
137+
await execa(cmd, ["--redoc", "test/fixtures/redocly-flag/redocly.yaml"], {
120138
cwd,
121139
});
122140
for (const schema of ["a", "b", "c"]) {
123141
expect(
124142
fs.readFileSync(
125-
new URL(`./test/fixtures/redocly/output/${schema}.ts`, root),
143+
new URL(`./test/fixtures/redocly-flag/output/${schema}.ts`, root),
126144
"utf8",
127145
),
128146
).toMatchFileSnapshot(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output

0 commit comments

Comments
 (0)