Skip to content

Commit c145f5f

Browse files
authored
Fix Record<string, never> appearing in discriminator union (#1248)
1 parent 898cf3c commit c145f5f

14 files changed

+236
-171
lines changed

.changeset/old-owls-whisper.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-typescript": patch
3+
---
4+
5+
Fix Record<string, never> appearing in union

.changeset/tall-shrimps-pay.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-typescript": patch
3+
---
4+
5+
Improve oneOf generated types

.eslintrc.cjs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module.exports = {
44
parserOptions: {
55
project: ["./tsconfig.json"],
66
},
7-
extends: ["eslint:recommended", "plugin:@typescript-eslint/strict"],
8-
plugins: ["@typescript-eslint", "prettier"],
7+
extends: ["eslint:recommended", "plugin:@typescript-eslint/strict", "plugin:vitest/recommended"],
8+
plugins: ["@typescript-eslint", "no-only-tests", "prettier", "vitest"],
99
rules: {
1010
"@typescript-eslint/consistent-indexed-object-style": "off", // sometimes naming keys is more user-friendly
1111
"@typescript-eslint/no-dynamic-delete": "off", // delete is OK
@@ -19,6 +19,8 @@ module.exports = {
1919
rules: {
2020
"@typescript-eslint/ban-ts-comment": "off", // allow @ts-ignore only in tests
2121
"@typescript-eslint/no-empty-function": "off", // don’t enforce this in tests
22+
"no-only-tests/no-only-tests": "error",
23+
"vitest/valid-title": "off", // doesn’t work?
2224
},
2325
},
2426
],

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
"del-cli": "^5.0.0",
2828
"eslint": "^8.44.0",
2929
"eslint-config-prettier": "^8.8.0",
30+
"eslint-plugin-no-only-tests": "^3.1.0",
3031
"eslint-plugin-prettier": "^4.2.1",
32+
"eslint-plugin-vitest": "^0.2.6",
3133
"npm-run-all": "^4.1.5",
3234
"prettier": "^2.8.8",
3335
"typescript": "^5.1.6"

packages/openapi-fetch/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"build:ts-min": "esbuild --bundle src/index.ts --format=esm --minify --outfile=dist/index.min.js && cp dist/index.d.ts dist/index.min.d.ts",
4949
"build:cjs": "esbuild --bundle src/index.ts --format=cjs --outfile=dist/index.cjs",
5050
"lint": "pnpm run lint:js",
51-
"lint:js": "prettier --check \"{src,test}/**/*\"",
51+
"lint:js": "eslint \"{src,test}/**/*.{js,ts}\"",
52+
"lint:prettier": "prettier --check \"{src,test}/**/*\"",
5253
"test": "pnpm run test:ts && npm run test:js",
5354
"test:js": "vitest run",
5455
"test:ts": "tsc --noEmit",

packages/openapi-fetch/src/index.test.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ describe("client", () => {
227227
});
228228

229229
describe("body", () => {
230+
// these are pure type tests; no runtime assertions needed
231+
/* eslint-disable vitest/expect-expect */
230232
it("requires necessary requestBodies", async () => {
231233
const client = createClient<paths>({ baseUrl: "https://myapi.com/v1" });
232234
mockFetch({ status: 200, body: JSON.stringify({ message: "OK" }) });
@@ -285,6 +287,7 @@ describe("client", () => {
285287
});
286288
});
287289
});
290+
/* eslint-enable vitest/expect-expect */
288291
});
289292

290293
describe("options", () => {
@@ -408,7 +411,7 @@ describe("client", () => {
408411
expect(response.status).toBe(204);
409412

410413
// assert error is empty
411-
expect(error).toBe(undefined);
414+
expect(error).toBeUndefined();
412415
});
413416

414417
it("treats `default` as an error", async () => {
@@ -478,7 +481,7 @@ describe("client", () => {
478481
expect(response.status).toBe(200);
479482

480483
// assert error is empty
481-
expect(error).toBe(undefined);
484+
expect(error).toBeUndefined();
482485
});
483486

484487
it("sends correct options, returns error", async () => {
@@ -500,7 +503,7 @@ describe("client", () => {
500503
expect(response.status).toBe(404);
501504

502505
// assert data is empty
503-
expect(data).toBe(undefined);
506+
expect(data).toBeUndefined();
504507
});
505508

506509
// note: this was a previous bug in the type inference
@@ -543,7 +546,7 @@ describe("client", () => {
543546
expect(response.status).toBe(201);
544547

545548
// assert error is empty
546-
expect(error).toBe(undefined);
549+
expect(error).toBeUndefined();
547550
});
548551

549552
it("supports sepecifying utf-8 encoding", async () => {
@@ -563,7 +566,7 @@ describe("client", () => {
563566
expect(response.status).toBe(201);
564567

565568
// assert error is empty
566-
expect(error).toBe(undefined);
569+
expect(error).toBeUndefined();
567570
});
568571
});
569572

@@ -588,7 +591,7 @@ describe("client", () => {
588591
expect(data).toEqual({});
589592

590593
// assert error is empty
591-
expect(error).toBe(undefined);
594+
expect(error).toBeUndefined();
592595
});
593596

594597
it("returns empty object on Content-Length: 0", async () => {
@@ -604,7 +607,7 @@ describe("client", () => {
604607
expect(data).toEqual({});
605608

606609
// assert error is empty
607-
expect(error).toBe(undefined);
610+
expect(error).toBeUndefined();
608611
});
609612
});
610613

0 commit comments

Comments
 (0)