Skip to content

Commit 00ee487

Browse files
committed
Merge branch 'main' of ../../openapi-typescript
2 parents dccfc85 + 4f76f36 commit 00ee487

22 files changed

+2797
-0
lines changed

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.turbo
2+
*.config.*
3+
biome.json
4+
tsconfig*.json

CHANGELOG.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# swr-openapi
2+
3+
## 5.4.2
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [[`bdd5ddb`](https://github.com/openapi-ts/openapi-typescript/commit/bdd5ddb7d5f8463bd0515f0b2d5c98a8a394dabf), [`0f22be2`](https://github.com/openapi-ts/openapi-typescript/commit/0f22be218f0c8050a96f35a6a271b959b2c5a23f), [`8f96eb5`](https://github.com/openapi-ts/openapi-typescript/commit/8f96eb50f5ec060e2e9100e9a43d3fe98e9795c5)]:
8+
9+
10+
11+
## 5.4.1
12+
13+
### Patch Changes
14+
15+
- Updated dependencies [[`7527d1e`](https://github.com/openapi-ts/openapi-typescript/commit/7527d1e7502cd1e9621922f028b4736d85f25800)]:
16+
17+
18+
## 5.4.0
19+
20+
### Minor Changes
21+
22+
- [#2420](https://github.com/openapi-ts/openapi-typescript/pull/2420) [`48134b5`](https://github.com/openapi-ts/openapi-typescript/commit/48134b59f1bb9f7c7daac6f9f4a8b8c6422ef9a2) Thanks [@htunnicliff](https://github.com/htunnicliff)! - Disallow extra properties in swr-openapi init types
23+
24+
## 5.3.1
25+
26+
### Patch Changes
27+
28+
- Updated dependencies [[`6943ccf`](https://github.com/openapi-ts/openapi-typescript/commit/6943ccf216f602f004eb178dd652ffcbafc05346), [`5be22d7`](https://github.com/openapi-ts/openapi-typescript/commit/5be22d7adc8bc36fdfa91f1aa3473919107060f2)]:
29+
30+
31+
## 5.3.0
32+
33+
### Minor Changes
34+
35+
- [#2310](https://github.com/openapi-ts/openapi-typescript/pull/2310) [`e66b5ce`](https://github.com/openapi-ts/openapi-typescript/commit/e66b5ce63bfcdc57c6ee942e5ed4e7667e64c290) Thanks [@drwpow](https://github.com/drwpow)! - Build package with unbuild to improve CJS support
36+
37+
### Patch Changes
38+
39+
- Updated dependencies [[`e66b5ce`](https://github.com/openapi-ts/openapi-typescript/commit/e66b5ce63bfcdc57c6ee942e5ed4e7667e64c290), [`e66b5ce`](https://github.com/openapi-ts/openapi-typescript/commit/e66b5ce63bfcdc57c6ee942e5ed4e7667e64c290)]:
40+
41+
42+
43+
## 5.2.0
44+
45+
### Minor Changes
46+
47+
- [#2147](https://github.com/openapi-ts/openapi-typescript/pull/2147) [`5848759`](https://github.com/openapi-ts/openapi-typescript/commit/5848759e3b6796331b0e85bf26a01c14af90537f) Thanks [@SSlime-s](https://github.com/SSlime-s)! - Add custom error types to query builder
48+
49+
## 5.1.7
50+
51+
### Patch Changes
52+
53+
- Updated dependencies [[`81c031d`](https://github.com/openapi-ts/openapi-typescript/commit/81c031da8584ed49b033ebfc67bbb3e1ca258699)]:
54+
55+
56+
## 5.1.6
57+
58+
### Patch Changes
59+
60+
- Updated dependencies [[`30c6da8`](https://github.com/openapi-ts/openapi-typescript/commit/30c6da800a00bda87da66dea6d04807e1379f06a), [`7205e12`](https://github.com/openapi-ts/openapi-typescript/commit/7205e12e07e5fd36a6bb3be44ea911f57bbbeb60)]:
61+
62+
63+
64+
## 5.1.5
65+
66+
### Patch Changes
67+
68+
- Updated dependencies [[`4966560`](https://github.com/openapi-ts/openapi-typescript/commit/4966560790ad49fabb06d718115a82a779a5b74a), [`fc3f7f8`](https://github.com/openapi-ts/openapi-typescript/commit/fc3f7f8b9cf52f0d4daf31ed4579d588c5b0f3e6), [`7f3f7b6`](https://github.com/openapi-ts/openapi-typescript/commit/7f3f7b65da5ef8caf5304486184118352665eb3f), [`47e4b5e`](https://github.com/openapi-ts/openapi-typescript/commit/47e4b5eb86adc59e3de2a4179741d35a26db61c0), [`ef23947`](https://github.com/openapi-ts/openapi-typescript/commit/ef239479b5f15fc4c98dd15c72974d4cb8722fb0)]:
69+
70+
71+
72+
## 5.1.4
73+
74+
### Patch Changes
75+
76+
- Updated dependencies [[`ebe56f3`](https://github.com/openapi-ts/openapi-typescript/commit/ebe56f337561bfdd1bf1abdc56ba3d2f48c4d393)]:
77+
78+
79+
## 5.1.3
80+
81+
### Patch Changes
82+
83+
- Updated dependencies [[`2bffe2a`](https://github.com/openapi-ts/openapi-typescript/commit/2bffe2a652864a54c8dc969327e4a8eb4081eb25)]:
84+
85+
86+
87+
## 5.1.2
88+
89+
### Patch Changes
90+
91+
- Updated dependencies [[`7081842`](https://github.com/openapi-ts/openapi-typescript/commit/70818420c1cd6ca2ad2529bf2d7936bd01f3ef42)]:
92+
93+
94+
## 5.1.1
95+
96+
### Patch Changes
97+
98+
- Updated dependencies [[`35c576c`](https://github.com/openapi-ts/openapi-typescript/commit/35c576c8b2852f66e641014d13ffcfdeb21e98a1), [`e2d8541`](https://github.com/openapi-ts/openapi-typescript/commit/e2d854131a1dc11d3b8e8513d3e0ce1f04ea1211)]:
99+
100+
101+
102+
## 5.1.0
103+
104+
### Minor Changes
105+
106+
- [#1932](https://github.com/openapi-ts/openapi-typescript/pull/1932) [`639ec45`](https://github.com/openapi-ts/openapi-typescript/commit/639ec45ed9155d2bc0c3d0fbebd3bc52f90ca7eb) Thanks [@htunnicliff](https://github.com/htunnicliff)! - Modify package.json to point to new repository
107+
108+
- [#1993](https://github.com/openapi-ts/openapi-typescript/pull/1993) [`d95c474`](https://github.com/openapi-ts/openapi-typescript/commit/d95c474bc3eab790e93029ac802e18b79a311fba) Thanks [@htunnicliff](https://github.com/htunnicliff)! - Update dependencies and adjust paths signature to conform to updated helper signature

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Hunter Tunnicliff
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<p align="center">
2+
<h1 align="center">swr-openapi</h1>
3+
</p>
4+
5+
<p align="center">Generate <a href="https://swr.vercel.app"><code>swr</code></a> hooks using <a href="https://swagger.io/specification/">OpenAPI</a> schemas</p>
6+
7+
<p align="center">
8+
<a aria-label="npm" href="https://www.npmjs.com/package/swr-openapi">
9+
<img alt="npm" src="https://img.shields.io/npm/v/swr-openapi.svg?style=for-the-badge&labelColor=000000">
10+
</a>
11+
<a aria-label="license" href="https://github.com/openapi-ts/openapi-typescript/blob/main/packages/swr-openapi/LICENSE">
12+
<img alt="license" src="https://img.shields.io/github/license/openapi-ts/openapi-typescript.svg?style=for-the-badge&labelColor=000000">
13+
</a>
14+
</p>
15+
16+
## Setup
17+
18+
```sh
19+
npm install swr-openapi swr openapi-fetch
20+
```
21+
22+
Follow [openapi-typescript](https://openapi-ts.dev/) directions to generate TypeScript definitions for each service being used.
23+
24+
Here is an example of types being generated for a service via the command line:
25+
26+
```sh
27+
npx openapi-typescript "https://sandwiches.example/openapi/json" --output ./types/sandwich-schema.ts
28+
```
29+
30+
## Basic Usage
31+
32+
Initialize an [openapi-fetch](https://openapi-ts.dev/openapi-fetch/) client and create any desired hooks.
33+
34+
```ts
35+
// sandwich-api.ts
36+
import createClient from "openapi-fetch";
37+
import { createQueryHook } from "swr-openapi";
38+
import type { paths as SandwichPaths } from "./types/sandwich-schema";
39+
40+
const client = createClient<SandwichPaths>(/* ... */);
41+
42+
const useSandwiches = createQueryHook(client, "sandwich-api");
43+
44+
const { data, error, isLoading, isValidating, mutate } = useSandwiches(
45+
"/sandwich/{id}", // <- Fully typed paths!
46+
{
47+
params: {
48+
path: {
49+
id: "123", // <- Fully typed params!
50+
},
51+
},
52+
},
53+
);
54+
```
55+
56+
## 📓 Docs
57+
58+
[View Docs](https://openapi-ts.dev/swr-openapi)

biome.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"root": false,
3+
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
4+
"extends": "//",
5+
"files": {
6+
"includes": ["src/**"]
7+
},
8+
"linter": {
9+
"rules": {
10+
"style": {
11+
"noNonNullAssertion": "off"
12+
}
13+
}
14+
}
15+
}

build.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineBuildConfig } from "unbuild";
2+
3+
export default defineBuildConfig({
4+
entries: ["./src/index.ts"],
5+
declaration: "compatible",
6+
clean: true,
7+
sourcemap: true,
8+
rollup: {
9+
// Ship CommonJS-compatible bundle
10+
emitCJS: true,
11+
},
12+
});

package.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"name": "swr-openapi",
3+
"description": "Generate SWR hooks from OpenAPI schemas",
4+
"version": "5.4.2",
5+
"author": {
6+
"name": "Hunter Tunnicliff",
7+
"email": "[email protected]"
8+
},
9+
"license": "MIT",
10+
"type": "module",
11+
"main": "./dist/index.mjs",
12+
"exports": {
13+
".": {
14+
"import": "./dist/index.mjs",
15+
"require": "./dist/index.cjs",
16+
"default": "./dist/index.mjs"
17+
},
18+
"./package.json": "./package.json"
19+
},
20+
"sideEffects": false,
21+
"repository": {
22+
"type": "git",
23+
"url": "https://github.com/openapi-ts/openapi-typescript",
24+
"directory": "packages/swr-openapi"
25+
},
26+
"keywords": [
27+
"swr",
28+
"openapi",
29+
"rest",
30+
"generator",
31+
"client",
32+
"fetch"
33+
],
34+
"funding": {
35+
"type": "buymeacoffee",
36+
"url": "https://buymeacoffee.com/htunnicliff"
37+
},
38+
"bugs": {
39+
"url": "https://github.com/openapi-ts/openapi-typescript/issues"
40+
},
41+
"files": [
42+
"dist",
43+
"src",
44+
"!src/__test__",
45+
"LICENSE",
46+
"README.md"
47+
],
48+
"scripts": {
49+
"build": "unbuild",
50+
"dev": "vitest --typecheck",
51+
"format": "biome format . --write",
52+
"lint": "pnpm run lint:js && pnpm run lint:ts",
53+
"lint:js": "biome check .",
54+
"lint:ts": "tsc --noEmit",
55+
"prepack": "pnpm run build",
56+
"test": "pnpm run test:js && pnpm run test:exports",
57+
"test:js": "vitest run --typecheck",
58+
"test:exports": "pnpm run build && attw --pack .",
59+
"prepublish": "pnpm run build",
60+
"version": "pnpm run build"
61+
},
62+
"peerDependencies": {
63+
"openapi-fetch": "workspace:*",
64+
"openapi-typescript": "workspace:*",
65+
"react": "18 || 19",
66+
"swr": "2",
67+
"typescript": "^5.x"
68+
},
69+
"peerDependenciesMeta": {
70+
"openapi-typescript": {
71+
"optional": true
72+
}
73+
},
74+
"dependencies": {
75+
"openapi-typescript-helpers": "workspace:^",
76+
"type-fest": "^5.0.0"
77+
},
78+
"devDependencies": {
79+
"@types/lodash": "4.17.20",
80+
"@types/react": "^18.3.24",
81+
"husky": "9.1.7",
82+
"lint-staged": "16.2.3",
83+
"lodash": "4.17.21",
84+
"openapi-fetch": "workspace:^",
85+
"openapi-typescript": "workspace:^",
86+
"react": "18.3.1",
87+
"swr": "2.3.6",
88+
"typescript": "5.9.3"
89+
}
90+
}

0 commit comments

Comments
 (0)