Skip to content

Commit b3eb455

Browse files
committed
adding client support
1 parent 012f10f commit b3eb455

File tree

13 files changed

+3293
-2575
lines changed

13 files changed

+3293
-2575
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ Register the command to the `scripts` property in your package.json file.
2121
```json
2222
{
2323
"scripts": {
24-
"codegen": "openapi-rq -i ./petstore.yaml -c axios"
24+
"codegen": "openapi-rq -i ./petstore.yaml -c @hey-api/client-fetch"
2525
}
2626
}
2727
```
2828

2929
You can also run the command without installing it in your project using the npx command.
3030

3131
```bash
32-
$ npx --package @7nohe/openapi-react-query-codegen openapi-rq -i ./petstore.yaml -c axios
32+
$ npx --package @7nohe/openapi-react-query-codegen openapi-rq -i ./petstore.yaml -c @hey-api/client-fetch
3333
```
3434

3535
## Usage
@@ -45,7 +45,7 @@ Options:
4545
-V, --version output the version number
4646
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
4747
-o, --output <value> Output directory (default: "openapi")
48-
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
48+
-c, --client <value> HTTP client to generate [@hey-api/client-fetch, @hey-api/client-axios] (default: "@hey-api/client-fetch")
4949
--request <value> Path to custom request file
5050
--format <value> Process output folder with formatter? ['biome', 'prettier']
5151
--lint <value> Process output folder with linter? ['eslint', 'biome']

biome.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
},
66
"files": {
77
"ignore": [
8+
".vscode",
89
"dist",
910
"examples/react-app/openapi",
1011
"coverage",

examples/nextjs-app/app/page.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import { prefetchUseDefaultServiceFindPets } from "@/openapi/queries/prefetch";
21
import {
32
HydrationBoundary,
43
QueryClient,
54
dehydrate,
65
} from "@tanstack/react-query";
6+
import { prefetchUseFindPets } from "../openapi/queries/prefetch";
77
import Pets from "./pets";
8+
import { client } from "./providers";
89

910
export default async function Home() {
1011
const queryClient = new QueryClient();
1112

12-
await prefetchUseDefaultServiceFindPets(queryClient, {
13-
limit: 10,
14-
tags: [],
13+
await prefetchUseFindPets(queryClient, {
14+
query: { tags: [], limit: 10 },
15+
client: client,
1516
});
1617

1718
return (

examples/nextjs-app/app/pets.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"use client";
22

3-
import { useDefaultServiceFindPets } from "@/openapi/queries";
43
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
4+
import { useFindPets } from "../openapi/queries";
55

66
export default function Pets() {
7-
const { data } = useDefaultServiceFindPets({
8-
limit: 10,
9-
tags: [],
7+
const { data } = useFindPets({
8+
query: { tags: [], limit: 10 },
109
});
1110

1211
return (

examples/nextjs-app/app/providers.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use client";
22

3+
import { createClient } from "@hey-api/client-fetch";
34
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
45
// We can not useState or useRef in a server component, which is why we are
5-
// extracting this part out into it's own file with 'use client' on top
6-
import { useState } from "react";
6+
// extracting this part out into
77

88
function makeQueryClient() {
99
return new QueryClient({
@@ -32,6 +32,10 @@ function getQueryClient() {
3232
return browserQueryClient;
3333
}
3434

35+
export const client = createClient({
36+
baseUrl: "http://localhost:4010",
37+
});
38+
3539
export default function Providers({ children }: { children: React.ReactNode }) {
3640
// NOTE: Avoid useState when initializing the query client if you don't
3741
// have a suspense boundary between this and the code that may

examples/nextjs-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build": "next build",
1010
"start": "next start",
1111
"lint": "next lint",
12-
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml -c axios --request ./request.ts --format=biome --lint=biome"
12+
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml --request ./request.ts --format=biome --lint=biome --base http://localhost:4010"
1313
},
1414
"dependencies": {
1515
"@tanstack/react-query": "^5.32.1",

examples/react-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dev:mock": "prism mock ../petstore.yaml --dynamic",
1010
"build": "tsc && vite build",
1111
"preview": "vite preview",
12-
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml -c @hey-api/client-fetch --format=biome --lint=biome",
12+
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml --format=biome --lint=biome",
1313
"test:generated": "tsc -p ./tsconfig.openapi.json --noEmit"
1414
},
1515
"dependencies": {

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"author": "Daiki Urata (@7nohe)",
4646
"license": "MIT",
4747
"dependencies": {
48-
"@hey-api/openapi-ts": "0.46.3",
48+
"@hey-api/client-fetch": "0.1.10",
49+
"@hey-api/openapi-ts": "0.49.0",
4950
"@types/cross-spawn": "^6.0.6",
5051
"cross-spawn": "^7.0.3"
5152
},
@@ -57,15 +58,15 @@
5758
"glob": "^10.3.10",
5859
"lefthook": "^1.6.10",
5960
"rimraf": "^5.0.5",
60-
"ts-morph": "^22.0.0",
61+
"ts-morph": "^23.0.0",
6162
"ts-node": "^10.9.2",
62-
"typescript": "^5.3.3",
63+
"typescript": "^5.5.3",
6364
"vitest": "^1.5.0"
6465
},
6566
"peerDependencies": {
6667
"commander": "12.x",
6768
"glob": "10.x",
68-
"ts-morph": "22.x",
69+
"ts-morph": "23.x",
6970
"typescript": "5.x"
7071
},
7172
"engines": {

0 commit comments

Comments
 (0)