Skip to content

Commit 82b932b

Browse files
authored
feat/new openapi client support 2 (#131)
1 parent be5cd9d commit 82b932b

38 files changed

+1947
-1844
lines changed

.github/workflows/comment-release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ jobs:
5353
github-token: ${{ secrets.GITHUB_TOKEN }}
5454
script: |
5555
const { issue: { number: issue_number }, repo: { owner, repo }, payload } = context;
56-
const { name: packageName, version } = require(`${process.env.GITHUB_WORKSPACE}/package.json`);
56+
const fs = require('fs')
57+
const jsonString = fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/package.json`)
58+
var packageJson = JSON.parse(jsonString)
59+
const { name: packageName, version } = packageJson;
5760
5861
const body = [
5962
`npm package published to pre tag.`,

README.md

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

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

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

3636
## Usage
@@ -46,23 +46,22 @@ Options:
4646
-V, --version output the version number
4747
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
4848
-o, --output <value> Output directory (default: "openapi")
49-
-c, --client <value> HTTP client to generate (choices: "angular", "axios", "fetch", "node", "xhr", default: "fetch")
49+
-c, --client <value> HTTP client to generate (choices: "@hey-api/client-fetch", "@hey-api/client-axios", default: "@hey-api/client-fetch")
5050
--request <value> Path to custom request file
5151
--format <value> Process output folder with formatter? (choices: "biome", "prettier")
5252
--lint <value> Process output folder with linter? (choices: "biome", "eslint")
5353
--operationId Use operation ID to generate operation names?
5454
--serviceResponse <value> Define shape of returned value from service calls (choices: "body", "response", default: "body")
5555
--base <value> Manually set base in OpenAPI config instead of inferring from server value
56-
--enums <value> Generate JavaScript objects from enum definitions? ['javascript', 'typescript', 'typescript+namespace']
5756
--enums <value> Generate JavaScript objects from enum definitions? (choices: "javascript", "typescript")
5857
--useDateType Use Date type instead of string for date types for models, this will not convert the data to a Date object
5958
--debug Run in debug mode?
6059
--noSchemas Disable generating JSON schemas
6160
--schemaType <value> Type of JSON schema [Default: 'json'] (choices: "form", "json")
6261
--pageParam <value> Name of the query parameter used for pagination (default: "page")
6362
--nextPageParam <value> Name of the response parameter used for next page (default: "nextPage")
64-
--initialPageParam <value> Initial value for the pagination parameter (default: "1")
65-
-h, --help display help for command
63+
--initialPageParam <value> Initial page value to query (default: "initialPageParam")
64+
-h, --help display help for command
6665
```
6766

6867
### Example Usage

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/components/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";
3+
import { useFindPets } from "@/openapi/queries";
44
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
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/page.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { prefetchUseDefaultServiceFindPets } from "@/openapi/queries/prefetch";
21
import {
32
HydrationBoundary,
43
QueryClient,
54
dehydrate,
65
} from "@tanstack/react-query";
76
import Link from "next/link";
7+
import { prefetchUseFindPets } from "../openapi/queries/prefetch";
88
import Pets from "./components/Pets";
99

1010
export default async function Home() {
1111
const queryClient = new QueryClient();
1212

13-
await prefetchUseDefaultServiceFindPets(queryClient, {
14-
limit: 10,
15-
tags: [],
13+
await prefetchUseFindPets(queryClient, {
14+
query: { tags: [], limit: 10 },
1615
});
1716

1817
return (

examples/nextjs-app/app/providers.tsx

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

33
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
4+
import "../fetchClient";
5+
46
// 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";
7+
// extracting this part out into
78

89
function makeQueryClient() {
910
return new QueryClient({

examples/nextjs-app/fetchClient.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { client } from "@/openapi/requests/services.gen";
2+
3+
client.setConfig({
4+
baseUrl: "http://localhost:4010",
5+
});

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/petstore.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ components:
197197
NewPet:
198198
type: object
199199
required:
200-
- name
200+
- name
201201
properties:
202202
name:
203203
type: string
204204
tag:
205-
type: string
205+
type: string
206206

207207
Error:
208208
type: object
@@ -214,4 +214,4 @@ components:
214214
type: integer
215215
format: int32
216216
message:
217-
type: string
217+
type: string

examples/react-app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
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 axios --request ./request.ts --format=biome --lint=biome",
12+
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml --format=biome --lint=biome -c @hey-api/client-axios",
1313
"test:generated": "tsc -p ./tsconfig.openapi.json --noEmit"
1414
},
1515
"dependencies": {
16+
"@hey-api/client-axios": "^0.2.7",
1617
"@tanstack/react-query": "^5.32.1",
1718
"axios": "^1.6.7",
1819
"form-data": "~4.0.0",

0 commit comments

Comments
 (0)