Skip to content

Fix Record<string, never> appearing in discriminator union #1248

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
Jul 25, 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
5 changes: 5 additions & 0 deletions .changeset/old-owls-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-typescript": patch
---

Fix Record<string, never> appearing in union
5 changes: 5 additions & 0 deletions .changeset/tall-shrimps-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-typescript": patch
---

Improve oneOf generated types
6 changes: 4 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module.exports = {
parserOptions: {
project: ["./tsconfig.json"],
},
extends: ["eslint:recommended", "plugin:@typescript-eslint/strict"],
plugins: ["@typescript-eslint", "prettier"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/strict", "plugin:vitest/recommended"],
Copy link
Contributor Author

@drwpow drwpow Jul 25, 2023

Choose a reason for hiding this comment

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

Minor linting improvements to test files (mostly just catches test.only() from lingering, which can be easy to forget to remove)

plugins: ["@typescript-eslint", "no-only-tests", "prettier", "vitest"],
rules: {
"@typescript-eslint/consistent-indexed-object-style": "off", // sometimes naming keys is more user-friendly
"@typescript-eslint/no-dynamic-delete": "off", // delete is OK
Expand All @@ -19,6 +19,8 @@ module.exports = {
rules: {
"@typescript-eslint/ban-ts-comment": "off", // allow @ts-ignore only in tests
"@typescript-eslint/no-empty-function": "off", // don’t enforce this in tests
"no-only-tests/no-only-tests": "error",
"vitest/valid-title": "off", // doesn’t work?
},
},
],
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"del-cli": "^5.0.0",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vitest": "^0.2.6",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"typescript": "^5.1.6"
Expand Down
3 changes: 2 additions & 1 deletion packages/openapi-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"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",
"build:cjs": "esbuild --bundle src/index.ts --format=cjs --outfile=dist/index.cjs",
"lint": "pnpm run lint:js",
"lint:js": "prettier --check \"{src,test}/**/*\"",
"lint:js": "eslint \"{src,test}/**/*.{js,ts}\"",
"lint:prettier": "prettier --check \"{src,test}/**/*\"",
"test": "pnpm run test:ts && npm run test:js",
"test:js": "vitest run",
"test:ts": "tsc --noEmit",
Expand Down
17 changes: 10 additions & 7 deletions packages/openapi-fetch/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ describe("client", () => {
});

describe("body", () => {
// these are pure type tests; no runtime assertions needed
/* eslint-disable vitest/expect-expect */
it("requires necessary requestBodies", async () => {
const client = createClient<paths>({ baseUrl: "https://myapi.com/v1" });
mockFetch({ status: 200, body: JSON.stringify({ message: "OK" }) });
Expand Down Expand Up @@ -285,6 +287,7 @@ describe("client", () => {
});
});
});
/* eslint-enable vitest/expect-expect */
});

describe("options", () => {
Expand Down Expand Up @@ -408,7 +411,7 @@ describe("client", () => {
expect(response.status).toBe(204);

// assert error is empty
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});

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

// assert error is empty
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});

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

// assert data is empty
expect(data).toBe(undefined);
expect(data).toBeUndefined();
});

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

// assert error is empty
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});

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

// assert error is empty
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});
});

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

// assert error is empty
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});

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

// assert error is empty
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});
});

Expand Down
Loading