Skip to content

Commit 43edab3

Browse files
authored
Merge branch 'drwpow:main' into fix/converting-by-glob
2 parents c1fbdae + d93755b commit 43edab3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+7691
-6700
lines changed

.changeset/new-rats-yawn.md

-5
This file was deleted.

.eslintrc.cjs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
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
12+
"@typescript-eslint/no-non-null-assertion": "off", // this is better than "as"
1213
"@typescript-eslint/no-unnecessary-condition": "off", // this gives bad advice
1314
"no-console": "error",
1415
"no-unused-vars": "off",
@@ -19,6 +20,7 @@ module.exports = {
1920
rules: {
2021
"@typescript-eslint/ban-ts-comment": "off", // allow @ts-ignore only in tests
2122
"@typescript-eslint/no-empty-function": "off", // don’t enforce this in tests
23+
"@typescript-eslint/no-explicit-any": "off", // tests sometimes need this
2224
"no-only-tests/no-only-tests": "error",
2325
"vitest/valid-title": "off", // doesn’t work?
2426
},

docs/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ See the [README](./README.md) for basic setup.
66

77
## Corrections / small edits
88

9-
Corrections are always welcome! Please go straight to [opening a PR](https://github.com/drwpow/openapi-typescript/pulls) for correcting typos or misinformation language. Small edits are also welcome, which include shortening verbose language or clarifying confusing wording.
9+
Corrections are always welcome! Please go straight to [opening a PR](https://github.com/drwpow/openapi-typescript/pulls) for correcting typos or misinformation. Small grammar edits are also welcome such as shortening verbose language or clarifying confusing statements.
1010

1111
## Styling fixes
1212

docs/scripts/update-contributors.js

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const OPENAPI_TS_CONTRIBUTORS = [
9191
"toomuchdesign",
9292
"psychedelicious",
9393
"tkrotoff",
94+
"pimveldhuisen",
9495
]),
9596
];
9697

docs/src/data/contributors.json

+1-1
Large diffs are not rendered by default.

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
"devDependencies": {
2323
"@changesets/changelog-github": "^0.4.8",
2424
"@changesets/cli": "^2.26.2",
25-
"@typescript-eslint/eslint-plugin": "^5.61.0",
26-
"@typescript-eslint/parser": "^5.61.0",
25+
"@typescript-eslint/eslint-plugin": "^6.3.0",
26+
"@typescript-eslint/parser": "^6.3.0",
2727
"del-cli": "^5.0.0",
28-
"eslint": "^8.44.0",
29-
"eslint-config-prettier": "^8.8.0",
28+
"eslint": "^8.46.0",
29+
"eslint-config-prettier": "^9.0.0",
3030
"eslint-plugin-no-only-tests": "^3.1.0",
31-
"eslint-plugin-prettier": "^4.2.1",
32-
"eslint-plugin-vitest": "^0.2.6",
31+
"eslint-plugin-prettier": "^5.0.0",
32+
"eslint-plugin-vitest": "^0.2.8",
3333
"npm-run-all": "^4.1.5",
34-
"prettier": "^2.8.8",
34+
"prettier": "^3.0.1",
3535
"typescript": "^5.1.6"
3636
}
3737
}

packages/openapi-fetch/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# openapi-fetch
22

3+
## 0.7.2
4+
5+
### Patch Changes
6+
7+
- [#1242](https://github.com/drwpow/openapi-typescript/pull/1242) [`8d11701`](https://github.com/drwpow/openapi-typescript/commit/8d11701deb22d47bc8ef04b6210ea6722ecb461b) Thanks [@drwpow](https://github.com/drwpow)! - Fix impossible body typing
8+
39
## 0.7.1
410

511
### Patch Changes

packages/openapi-fetch/CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Thanks for being willing to contribute! 🙏
66

77
## Open issues
88

9-
Please check out the [the open issues](https://github.com/drwpow/openapi-fetch/issues). Issues labelled [**Help Wanted**](https://github.com/drwpow/openapi-fetch/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) and [**Good First Issue**](https://github.com/drwpow/openapi-fetch/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) are especially good to help with.
9+
Please check out the [the open issues](https://github.com/drwpow/openapi-typescript/issues). Issues labelled [**Good First Issue**](https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)are especially good to start with.
1010

1111
Contributing doesn’t have to be in code! Simply answering questions in open issues, or providing workarounds, is just as important a contribution as making pull requests.
1212

@@ -26,7 +26,7 @@ However, if adding a feature or breaking change, please **open an issue first to
2626

2727
Create a new branch for your PR with `git checkout -b your-branch-name`. Add the relevant code as well as docs and tests. When you push everything up (`git push`), navigate back to your repo GitHub and you should see a prompt to open a new PR.
2828

29-
While best practices for commit messages are encouraged (e.g. start with an imperative verb, keep it short, use the body if needed), this repo doesn’t follow any specific guidelines like [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). Clarity is favored over strict rules. Changelogs are generated separately from git (see [the Changelogs section](#changelogs)
29+
While best practices for commit messages are encouraged (e.g. start with an imperative verb, keep it short, use the body if needed), this repo doesn’t follow any specific guidelines. Clarity is favored over strict rules. Changelogs are generated separately from git (see [the Changelogs section](#changelogs))
3030

3131
### Writing the PR
3232

packages/openapi-fetch/package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "openapi-fetch",
33
"description": "Fetch using your OpenAPI types. Weighs 2 kb and has virtually zero runtime. Works with React, Vue, Svelte, or vanilla JS.",
4-
"version": "0.7.1",
4+
"version": "0.7.2",
55
"author": {
66
"name": "Drew Powers",
77
"email": "[email protected]"
@@ -59,10 +59,9 @@
5959
},
6060
"devDependencies": {
6161
"del-cli": "^5.0.0",
62-
"esbuild": "^0.18.17",
62+
"esbuild": "^0.19.0",
6363
"nanostores": "^0.9.3",
64-
"openapi-typescript": "*",
65-
"prettier": "^2.8.8",
64+
"openapi-typescript": "^6.4.2",
6665
"typescript": "^5.1.6",
6766
"vitest": "^0.33.0",
6867
"vitest-fetch-mock": "^0.2.2"

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ describe("client", () => {
235235

236236
// expect error on missing `body`
237237
// @ts-expect-error
238-
await client.GET("/blogposts", {});
238+
await client.PUT("/blogposts", {});
239239

240240
// expect error on missing fields
241241
// @ts-expect-error
@@ -318,7 +318,7 @@ describe("client", () => {
318318
new Headers({
319319
...headers, // assert new header got passed
320320
"Content-Type": "application/json", // probably doesn’t need to get tested, but this was simpler than writing lots of code to ignore these
321-
})
321+
}),
322322
);
323323
});
324324

@@ -333,7 +333,7 @@ describe("client", () => {
333333
new Headers({
334334
"Cache-Control": "no-cache",
335335
"Content-Type": "application/json",
336-
})
336+
}),
337337
);
338338
});
339339

@@ -372,7 +372,7 @@ describe("client", () => {
372372
it("multipart/form-data", async () => {
373373
const client = createClient<paths>();
374374
mockFetchOnce({ status: 200, body: "{}" });
375-
const { data } = await client.PUT("/contact", {
375+
await client.PUT("/contact", {
376376
body: {
377377
name: "John Doe",
378378
@@ -401,9 +401,8 @@ describe("client", () => {
401401
it("returns empty object on 204", async () => {
402402
const client = createClient<paths>();
403403
mockFetchOnce({ status: 204, body: "" });
404-
const { data, error, response } = await client.PUT("/tag/{name}", {
404+
const { data, error, response } = await client.DELETE("/tag/{name}", {
405405
params: { path: { name: "New Tag" } },
406-
body: { description: "This is a new tag" },
407406
});
408407

409408
// assert correct data was returned
@@ -445,6 +444,7 @@ describe("client", () => {
445444
const client = createClient<paths>();
446445
mockFetchOnce({ status: 200, body: "{}" });
447446
const { data } = await client.GET("/anyMethod", { parseAs: "blob" });
447+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
448448
expect((data as any).constructor.name).toBe("Blob");
449449
});
450450

@@ -681,7 +681,7 @@ describe("examples", () => {
681681
setTimeout(() => {
682682
token.set(tokenVal); // simulate promise-like token setting
683683
resolve();
684-
}, 0)
684+
}, 0),
685685
);
686686
await client.get().GET("/blogposts/{post_id}", { params: { path: { post_id: "1234" } } });
687687
expect(fetchMocker.mock.calls[1][1].headers.get("authorization")).toBe(`Bearer ${tokenVal}`);
@@ -710,7 +710,7 @@ describe("examples", () => {
710710
setTimeout(() => {
711711
token = tokenVal; // simulate promise-like token setting
712712
resolve();
713-
}, 0)
713+
}, 0),
714714
);
715715
await client.GET("/blogposts/{post_id}", { params: { path: { post_id: "1234" } } });
716716
expect(fetchMocker.mock.calls[1][1].headers.get("authorization")).toBe(`Bearer ${tokenVal}`);

packages/openapi-fetch/src/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const DEFAULT_HEADERS = {
44
};
55
const TRAILING_SLASH_RE = /\/*$/;
66

7+
// Note: though "any" is considered bad practice in general, this library relies
8+
// on "any" for type inference only it can give. Same goes for the "{}" type.
9+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
10+
711
/** options for each client instance */
812
interface ClientOptions extends RequestInit {
913
/** set the common root URL for all API requests */
@@ -47,7 +51,7 @@ export type Params<T> = T extends { parameters: any } ? { params: NonNullable<T[
4751
export type RequestBodyObj<T> = T extends { requestBody?: any } ? T["requestBody"] : never;
4852
export type RequestBodyContent<T> = undefined extends RequestBodyObj<T> ? FilterKeys<NonNullable<RequestBodyObj<T>>, "content"> | undefined : FilterKeys<RequestBodyObj<T>, "content">;
4953
export type RequestBodyMedia<T> = FilterKeys<RequestBodyContent<T>, MediaType> extends never ? FilterKeys<NonNullable<RequestBodyContent<T>>, MediaType> | undefined : FilterKeys<RequestBodyContent<T>, MediaType>;
50-
export type RequestBody<T> = undefined extends RequestBodyMedia<T> ? { body?: RequestBodyMedia<T> } : { body: RequestBodyMedia<T> };
54+
export type RequestBody<T> = RequestBodyMedia<T> extends never ? { body?: never } : undefined extends RequestBodyMedia<T> ? { body?: RequestBodyMedia<T> } : { body: RequestBodyMedia<T> };
5155
export type QuerySerializer<T> = (query: T extends { parameters: any } ? NonNullable<T["parameters"]["query"]> : Record<string, unknown>) => string;
5256
export type BodySerializer<T> = (body: RequestBodyMedia<T>) => any;
5357
export type RequestOptions<T> = Params<T> &

packages/openapi-fetch/test/v1.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ export interface paths {
176176
500: components["responses"]["Error"];
177177
};
178178
};
179+
delete: {
180+
parameters: {
181+
path: {
182+
name: string;
183+
};
184+
};
185+
responses: {
186+
/** @description No Content */
187+
204: never;
188+
500: components["responses"]["Error"];
189+
};
190+
};
179191
parameters: {
180192
path: {
181193
name: string;

packages/openapi-fetch/test/v1.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ paths:
190190
$ref: '#/components/responses/CreateTag'
191191
500:
192192
$ref: '#/components/responses/Error'
193+
delete:
194+
responses:
195+
204:
196+
description: No Content
197+
500:
198+
$ref: '#/components/responses/Error'
193199
/default-as-error:
194200
get:
195201
responses:

packages/openapi-typescript/CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# openapi-typescript
22

3+
## 6.4.3
4+
5+
### Patch Changes
6+
7+
- [#1287](https://github.com/drwpow/openapi-typescript/pull/1287) [`8a9d8ed`](https://github.com/drwpow/openapi-typescript/commit/8a9d8ede95802370c4015846a4856fd0701ada33) Thanks [@drwpow](https://github.com/drwpow)! - Fix oneOf handling with empty object parent type
8+
9+
## 6.4.2
10+
11+
### Patch Changes
12+
13+
- [#1278](https://github.com/drwpow/openapi-typescript/pull/1278) [`d7420e3`](https://github.com/drwpow/openapi-typescript/commit/d7420e30f1697ad8cfc0fdefc93127ad2b813f99) Thanks [@pvanagtmaal](https://github.com/pvanagtmaal)! - Fix externalizing external refs
14+
15+
## 6.4.1
16+
17+
### Patch Changes
18+
19+
- [#1269](https://github.com/drwpow/openapi-typescript/pull/1269) [`e735ff2`](https://github.com/drwpow/openapi-typescript/commit/e735ff2b9307eaec1959d0d3bf733a240a880c48) Thanks [@pimveldhuisen](https://github.com/pimveldhuisen)! - Stop trimming whitespace other than linebreaks in string values
20+
321
## 6.4.0
422

523
### Minor Changes

packages/openapi-typescript/CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Thanks for being willing to contribute! 🙏
66

77
## Open issues
88

9-
Please check out the [the open issues](https://github.com/drwpow/openapi-typescript/issues). Issues labelled [**Help Wanted**](https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) and [**Good First Issue**](https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) are especially good to help with.
9+
Please check out the [the open issues](https://github.com/drwpow/openapi-typescript/issues). Issues labelled [**Good First Issue**](https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)are especially good to start with.
1010

1111
Contributing doesn’t have to be in code! Simply answering questions in open issues, or providing workarounds, is just as important a contribution as making pull requests.
1212

@@ -26,7 +26,7 @@ However, if adding a feature or breaking change, please **open an issue first to
2626

2727
Create a new branch for your PR with `git checkout -b your-branch-name`. Add the relevant code as well as docs and tests. When you push everything up (`git push`), navigate back to your repo GitHub and you should see a prompt to open a new PR.
2828

29-
While best practices for commit messages are encouraged (e.g. start with an imperative verb, keep it short, use the body if needed), this repo doesn’t follow any specific guidelines like [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). Clarity is favored over strict rules. Changelogs are generated separately from git (see [the Changelogs section](#changelogs)
29+
While best practices for commit messages are encouraged (e.g. start with an imperative verb, keep it short, use the body if needed), this repo doesn’t follow any specific guidelines. Clarity is favored over strict rules. Changelogs are generated separately from git (see [the Changelogs section](#changelogs))
3030

3131
When working locally, run:
3232

packages/openapi-typescript/examples/digital-ocean-api/resources/uptime/create_alert.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
operationId: uptime_alert_create
1+
operationId: uptime_create_alert
22

33
summary: Create a New Alert
44

packages/openapi-typescript/examples/digital-ocean-api/resources/uptime/create_check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
operationId: uptime_check_create
1+
operationId: uptime_create_check
22

33
summary: Create a New Check
44

packages/openapi-typescript/examples/digital-ocean-api/resources/uptime/delete_alert.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
operationId: uptime_alert_delete
1+
operationId: uptime_delete_alert
22

33
summary: Delete an Alert
44

packages/openapi-typescript/examples/digital-ocean-api/resources/uptime/delete_check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
operationId: uptime_check_delete
1+
operationId: uptime_delete_check
22

33
summary: Delete a Check
44

packages/openapi-typescript/examples/digital-ocean-api/resources/uptime/get_alert.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
operationId: uptime_alert_get
1+
operationId: uptime_get_alert
22

33
summary: Retrieve an Existing Alert
44

packages/openapi-typescript/examples/digital-ocean-api/resources/uptime/get_check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
operationId: uptime_check_get
1+
operationId: uptime_get_check
22

33
summary: Retrieve an Existing Check
44

packages/openapi-typescript/examples/digital-ocean-api/resources/uptime/get_check_state.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
operationId: uptime_check_state_get
1+
operationId: uptime_get_checkState
22

33
summary: Retrieve Check State
44

packages/openapi-typescript/examples/digital-ocean-api/resources/uptime/list_alerts.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
operationId: uptime_check_alerts_list
1+
operationId: uptime_list_alerts
22

33
summary: List All Alerts
44

packages/openapi-typescript/examples/digital-ocean-api/resources/uptime/list_checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
operationId: uptime_checks_list
1+
operationId: uptime_list_checks
22

33
summary: List All Checks
44

packages/openapi-typescript/examples/digital-ocean-api/resources/uptime/update_alert.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
operationId: uptime_alert_update
1+
operationId: uptime_update_alert
22

33
summary: Update an Alert
44

packages/openapi-typescript/examples/digital-ocean-api/resources/uptime/update_check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
operationId: uptime_check_update
1+
operationId: uptime_update_check
22

33
summary: Update a Check
44

0 commit comments

Comments
 (0)