Skip to content

Commit e09fc02

Browse files
committed
feat!: changing openapi generator
Changed openapi code generator to @hey-api/openapi-ts. Not supporting all properties yet. Supporting new properties: - base - serviceResponse - enums - useDateType indent and useUnionTypes properties were removed left in for backwards compatibility. BREAKING CHANGE: changed from cjs to mjs
1 parent 4374671 commit e09fc02

23 files changed

+1203
-877
lines changed

.github/workflows/test.yml

+5-8
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,20 @@ jobs:
2424
- name: Install Node.js
2525
uses: actions/setup-node@v4
2626
with:
27-
node-version: 20
28-
cache: 'pnpm'
27+
node-version: 18
28+
cache: "pnpm"
2929

3030
- name: Install dependencies
31-
run: pnpm -w install
32-
31+
run: pnpm install --frozen-lockfile
32+
3333
- name: Build
3434
run: pnpm -w build
3535

36-
- name: Install dependencies in example app
37-
run: pnpm --filter @7nohe/react-app install --no-frozen-lockfile
38-
3936
- name: Run codegen
4037
run: pnpm --filter @7nohe/react-app generate:api
4138

4239
- name: Archive generated query file
43-
uses: actions/upload-artifact@v3
40+
uses: actions/upload-artifact@v4
4441
with:
4542
name: generated-query-file-${{ matrix.os }}
4643
path: examples/react-app/openapi/queries/index.ts

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ dist-ssr
2424
*.sw?
2525

2626
openapi
27+
*.tsbuildinfo

README.md

+17-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
- Supports generation of custom react hooks that use React Query's `useQuery` and `useMutation` hooks
88
- Supports generation of query keys for query caching
9-
- Supports the option to use pure TypeScript clients generated by [OpenAPI Typescript Codegen](https://github.com/ferdikoomen/openapi-typescript-codegen)
9+
- Supports the option to use pure TypeScript clients generated by [@hey-api/openapi-ts](https://github.com/hey-api/openapi-ts)
1010

1111
## Install
1212

@@ -44,12 +44,24 @@ Options:
4444
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
4545
-o, --output <value> Output directory (default: "openapi")
4646
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
47-
--useUnionTypes Use union types (default: false)
47+
--useUnionTypes Unused, will be removed in the next major version
4848
--exportSchemas <value> Write schemas to disk (default: false)
49-
--indent <value> Indentation options [4, 2, tabs] (default: "4")
49+
--indent <value> Unused, will be removed in the next major version
5050
--postfixServices <value> Service name postfix (default: "Service")
51-
--postfixModels <value> Modal name postfix
51+
--postfixModels <value> Unused, will be removed in the next major version
5252
--request <value> Path to custom request file
53+
--write <value> Write the files to disk (true or false)
54+
--useDateType Use Date type instead of string for date types for models, this will not convert the data to a Date object
55+
--enums Generate JavaScript objects from enum definitions?
56+
--base <value> Manually set base in OpenAPI config instead of inferring from server value
57+
--serviceResponse <value> Define shape of returned value from service calls ['body', 'generics', 'response']
58+
--operationId Use operation ID to generate operation names?
59+
--lint Process output folder with linter?
60+
--name Custom client class name
61+
--format Process output folder with formatter?
62+
--exportCore <value> Export core types
63+
--exportModels <value> Export models
64+
--exportServices <value> Export services
5365
-h, --help display help for command
5466
```
5567

@@ -70,7 +82,7 @@ $ openapi-rq -i ./petstore.yaml
7082
- common.ts <- common types
7183
- queries.ts <- generated query hooks
7284
- suspenses.ts <- generated suspense hooks
73-
- requests <- output code generated by OpenAPI Typescript Codegen
85+
- requests <- output code generated by @hey-api/openapi-ts
7486
```
7587

7688
### In your app

examples/react-app/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"dev:mock": "prism mock ./petstore.yaml --dynamic",
1010
"build": "tsc && vite build",
1111
"preview": "vite preview",
12-
"generate:api": "node ../../dist/src/cli.js -i ./petstore.yaml -c axios --exportSchemas=true --postfixServices=Client --request ./request.ts",
13-
"test:generated": "tsc ./openapi/queries/index.ts --noEmit --target esnext --moduleResolution node"
12+
"generate:api": "node ../../dist/cli.mjs -i ./petstore.yaml -c axios --postfixServices=Client",
13+
"test:generated": "tsc -p ./tsconfig.openapi.json --noEmit"
1414
},
1515
"dependencies": {
1616
"@tanstack/react-query": "^5.18.1",
@@ -28,4 +28,4 @@
2828
"typescript": "^5.3.3",
2929
"vite": "^5.0.12"
3030
}
31-
}
31+
}

examples/react-app/request.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from "axios";
2-
import type { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";
2+
import type { RawAxiosRequestHeaders } from "axios";
33

44
import type { ApiRequestOptions } from "./ApiRequestOptions";
55
import { CancelablePromise } from "./CancelablePromise";
@@ -13,7 +13,7 @@ const axiosInstance = axios.create({
1313
baseURL: "http://localhost:4010",
1414
headers: {
1515
// Your custom headers
16-
},
16+
} satisfies RawAxiosRequestHeaders,
1717
});
1818

1919
// Add a request interceptor

examples/react-app/tsconfig.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
"strict": true,
1111
"forceConsistentCasingInFileNames": true,
1212
"module": "ESNext",
13-
"moduleResolution": "Node",
13+
"moduleResolution": "Bundler",
1414
"resolveJsonModule": true,
1515
"isolatedModules": true,
1616
"noEmit": true,
1717
"jsx": "react-jsx"
1818
},
19-
"include": ["src", "openapi"],
20-
"references": [{ "path": "./tsconfig.node.json" }]
19+
"include": ["src"],
20+
"references": [
21+
{ "path": "./tsconfig.node.json" },
22+
{ "path": "./tsconfig.openapi.json" }
23+
]
2124
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"target": "ESNext",
5+
"useDefineForClassFields": true,
6+
"allowJs": false,
7+
"skipLibCheck": true,
8+
"esModuleInterop": false,
9+
"allowSyntheticDefaultImports": true,
10+
"strict": true,
11+
"forceConsistentCasingInFileNames": true,
12+
"module": "ESNext",
13+
"moduleResolution": "Node10",
14+
"resolveJsonModule": true,
15+
"isolatedModules": true
16+
},
17+
"include": ["openapi"]
18+
}

package.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
"version": "0.5.3",
44
"description": "OpenAPI React Query Codegen",
55
"bin": {
6-
"openapi-rq": "dist/src/cli.js"
6+
"openapi-rq": "dist/cli.js"
77
},
8+
"type": "module",
9+
"workspaces": [
10+
"examples/*"
11+
],
812
"scripts": {
913
"build": "tsc -p tsconfig.json",
1014
"preview": "npm run build && npm -C examples/react-app run generate:api",
@@ -27,21 +31,22 @@
2731
"openapi",
2832
"swagger",
2933
"typescript",
30-
"openapi-typescript-codegen"
34+
"openapi-typescript-codegen",
35+
"@hey-api/openapi-ts"
3136
],
3237
"author": "Daiki Urata (@7nohe)",
3338
"license": "MIT",
3439
"devDependencies": {
40+
"@hey-api/openapi-ts": "0.34.5",
3541
"@types/node": "^20.10.6",
3642
"commander": "^12.0.0",
3743
"glob": "^10.3.10",
38-
"openapi-typescript-codegen": "0.25.0",
3944
"typescript": "^5.3.3"
4045
},
4146
"peerDependencies": {
47+
"@hey-api/openapi-ts": "0.34.5",
4248
"commander": ">= 11 < 13",
4349
"glob": ">= 10",
44-
"openapi-typescript-codegen": "^0.24.0",
4550
"typescript": ">= 4.8.3"
4651
}
4752
}

0 commit comments

Comments
 (0)