Skip to content

Commit 56e36e1

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

File tree

15 files changed

+1774
-557
lines changed

15 files changed

+1774
-557
lines changed

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
"devDependencies": {
2525
"@changesets/changelog-github": "^0.4.8",
2626
"@changesets/cli": "^2.26.2",
27-
"@typescript-eslint/eslint-plugin": "^6.7.4",
28-
"@typescript-eslint/parser": "^6.7.4",
27+
"@typescript-eslint/eslint-plugin": "^6.12.0",
28+
"@typescript-eslint/parser": "^6.12.0",
2929
"del-cli": "^5.1.0",
30-
"eslint": "^8.50.0",
30+
"eslint": "^8.54.0",
3131
"eslint-config-prettier": "^9.0.0",
32-
"eslint-plugin-import": "^2.28.1",
32+
"eslint-plugin-import": "^2.29.0",
3333
"eslint-plugin-no-only-tests": "^3.1.0",
34-
"eslint-plugin-prettier": "^5.0.0",
34+
"eslint-plugin-prettier": "^5.0.1",
3535
"eslint-plugin-vitest": "^0.2.8",
3636
"npm-run-all": "^4.1.5",
37-
"prettier": "^3.0.3",
38-
"typescript": "^5.2.2"
37+
"prettier": "^3.1.0",
38+
"typescript": "^5.3.2"
3939
}
4040
}

packages/openapi-fetch/examples/nextjs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"@types/react": "18.2.20",
1818
"@types/react-dom": "18.2.7",
1919
"openapi-typescript": "workspace:^",
20-
"typescript": "5.2.2"
20+
"typescript": "5.3.2"
2121
}
2222
}

packages/openapi-fetch/examples/react-query/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"devDependencies": {
1717
"@vitejs/plugin-react-swc": "^3.3.2",
18-
"typescript": "^5.2.2",
18+
"typescript": "^5.3.2",
1919
"vite": "^4.4.9"
2020
}
2121
}

packages/openapi-fetch/examples/sveltekit/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"svelte": "^4.2.0",
1919
"svelte-check": "^3.5.1",
2020
"tslib": "^2.6.2",
21-
"typescript": "^5.2.2",
21+
"typescript": "^5.3.2",
2222
"vite": "^4.4.9"
2323
}
2424
}

packages/openapi-fetch/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"openapi-typescript-codegen": "^0.25.0",
7575
"openapi-typescript-fetch": "^1.1.3",
7676
"superagent": "^8.1.2",
77-
"typescript": "^5.2.2",
77+
"typescript": "^5.3.2",
7878
"vitest": "^0.34.6",
7979
"vitest-fetch-mock": "^0.2.2"
8080
}

packages/openapi-typescript-helpers/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
"test": "tsc --noEmit"
3434
},
3535
"devDependencies": {
36-
"typescript": "^5.2.2"
36+
"typescript": "^5.3.2"
3737
}
3838
}

packages/openapi-typescript/bin/cli.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ async function main() {
149149
);
150150
const redoc = maybeRedoc
151151
? await loadConfig({ configPath: maybeRedoc })
152-
: createConfig({}, { extends: ["minimal"] });
152+
: await createConfig({}, { extends: ["minimal"] });
153153

154154
// handle Redoc APIs
155155
const hasRedoclyApis = Object.keys(redoc?.apis ?? {}).length > 0;
@@ -161,9 +161,13 @@ 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+
// note: this will be absolute if --redoc is passed; otherwise, relative
167+
configRoot = path.isAbsolute(redoc.configFile)
168+
? new URL(`file://${redoc.configFile}`)
169+
: new URL(redoc.configFile, `file://${process.cwd()}/`);
170+
}
167171
if (!api["openapi-ts"]?.output) {
168172
errorAndExit(
169173
`API ${name} is missing an \`openapi-ts.output\` key. See https://openapi-ts.pages.dev/cli/#multiple-schemas.`,

packages/openapi-typescript/package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,20 @@
6060
"version": "pnpm run build"
6161
},
6262
"dependencies": {
63-
"@redocly/openapi-core": "^1.2.0",
63+
"@redocly/openapi-core": "^1.4.1",
6464
"ansi-colors": "^4.1.3",
6565
"supports-color": "^9.4.0",
66-
"typescript": "^5.2.2",
66+
"typescript": "^5.3.2",
6767
"yargs-parser": "^21.1.1"
6868
},
6969
"devDependencies": {
70-
"@types/degit": "^2.8.4",
71-
"@types/js-yaml": "^4.0.6",
72-
"@types/node": "^20.8.0",
70+
"@types/degit": "^2.8.6",
71+
"@types/js-yaml": "^4.0.9",
72+
"@types/node": "^20.9.4",
7373
"degit": "^2.8.4",
7474
"del-cli": "^5.1.0",
75-
"esbuild": "^0.19.5",
75+
"esbuild": "^0.19.7",
7676
"execa": "^7.2.0",
77-
"vite": "^4.4.9",
7877
"vite-node": "^0.34.6",
7978
"vitest": "^0.34.6"
8079
}

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

+22-3
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,33 @@ describe("CLI", () => {
115115
});
116116

117117
describe("Redocly config", () => {
118-
test("accepts multiple APIs", async () => {
119-
await execa(cmd, ["--redoc", "test/fixtures/redocly/redocly.yaml"], {
118+
// TODO: why won’t this run on Windows?
119+
test.skipIf(os.platform() !== "win32")("automatic config", async () => {
120+
/* eslint-disable @typescript-eslint/no-shadow */
121+
122+
// note: we have to change the cwd here for the automatic config to pick up properly
123+
const root = new URL("./fixtures/redocly/", import.meta.url);
124+
const cwd = os.platform() === "win32" ? fileURLToPath(root) : root;
125+
126+
await execa("../../../bin/cli.js", { cwd });
127+
for (const schema of ["a", "b", "c"]) {
128+
expect(
129+
fs.readFileSync(new URL(`./output/${schema}.ts`, root), "utf8"),
130+
).toMatchFileSnapshot(
131+
fileURLToPath(new URL("../../../examples/simple-example.ts", root)),
132+
);
133+
}
134+
/* eslint-enable @typescript-eslint/no-shadow */
135+
});
136+
137+
test("--redoc config", async () => {
138+
await execa(cmd, ["--redoc", "test/fixtures/redocly-flag/redocly.yaml"], {
120139
cwd,
121140
});
122141
for (const schema of ["a", "b", "c"]) {
123142
expect(
124143
fs.readFileSync(
125-
new URL(`./test/fixtures/redocly/output/${schema}.ts`, root),
144+
new URL(`./test/fixtures/redocly-flag/output/${schema}.ts`, root),
126145
"utf8",
127146
),
128147
).toMatchFileSnapshot(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output

0 commit comments

Comments
 (0)