Skip to content

Commit 85999aa

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 4c01176 commit 85999aa

13 files changed

+868
-700
lines changed

Diff for: README.md

+25-21
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
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

1313
```
1414
$ npm install -D @7nohe/openapi-react-query-codegen
1515
```
1616

17-
Register the command to the `scripts` property in your package.json file.
17+
Register the command to the `scripts` property in your package.json file.
1818

1919
```json
2020
{
@@ -30,7 +30,6 @@ You can also run the command without installing it in your project using the npx
3030
$ npx --package @7nohe/openapi-react-query-codegen openapi-rq -i ./petstore.yaml -c axios
3131
```
3232

33-
3433
## Usage
3534

3635
```
@@ -45,12 +44,24 @@ Options:
4544
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
4645
-o, --output <value> Output directory (default: "openapi")
4746
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
48-
--useUnionTypes Use union types (default: false)
47+
--useUnionTypes Unused, will be removed in the next major version
4948
--exportSchemas <value> Write schemas to disk (default: false)
50-
--indent <value> Indentation options [4, 2, tabs] (default: "4")
49+
--indent <value> Unused, will be removed in the next major version
5150
--postfixServices <value> Service name postfix (default: "Service")
5251
--postfixModels <value> Modal name postfix
5352
--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
5465
-h, --help display help for command
5566
```
5667

@@ -68,16 +79,14 @@ $ openapi-rq -i ./petstore.yaml
6879
- openapi
6980
- queries
7081
- index.ts <- custom react hooks
71-
- requests <- output code generated by OpenAPI Typescript Codegen
82+
- requests <- output code generated by @hey-api/openapi-ts
7283
```
7384

7485
### In your app
7586

7687
```tsx
7788
// App.tsx
78-
import {
79-
usePetServiceFindPetsByStatus,
80-
} from "../openapi/queries";
89+
import { usePetServiceFindPetsByStatus } from "../openapi/queries";
8190
function App() {
8291
const { data } = usePetServiceFindPetsByStatus({ status: ["available"] });
8392

@@ -100,30 +109,25 @@ You can also use pure TS clients.
100109

101110
```tsx
102111
import { useQuery } from "@tanstack/react-query";
103-
import { PetService } from '../openapi/requests/services/PetService';
104-
import {
105-
usePetServiceFindPetsByStatusKey,
106-
} from "../openapi/queries";
112+
import { PetService } from "../openapi/requests/services/PetService";
113+
import { usePetServiceFindPetsByStatusKey } from "../openapi/queries";
107114

108115
function App() {
109116
// You can still use the auto-generated query key
110117
const { data } = useQuery({
111118
queryKey: [usePetServiceFindPetsByStatusKey],
112119
queryFn: () => {
113120
// Do something here
114-
return PetService.findPetsByStatus(['available']);
115-
}
116-
});
121+
return PetService.findPetsByStatus(["available"]);
122+
},
123+
});
117124

118-
return (
119-
<div className="App">
120-
{/* .... */}
121-
</div>
122-
);
125+
return <div className="App">{/* .... */}</div>;
123126
}
124127

125128
export default App;
126129
```
127130

128131
## License
132+
129133
MIT

Diff for: examples/react-app/package.json

+1-1
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": "node ../../dist/src/cli.js -i ./petstore.yaml -c axios --exportSchemas=true --postfixServices=Client --request ./request.ts",
12+
"generate:api": "node ../../dist/cli.js -i ./petstore.yaml -c axios --postfixServices=Client --request ./request.ts",
1313
"test:generated": "tsc ./openapi/queries/index.ts --noEmit --target esnext --moduleResolution node"
1414
},
1515
"dependencies": {

Diff for: package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
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",
89
"scripts": {
910
"build": "tsc -p tsconfig.json",
1011
"preview": "npm run build && npm -C examples/react-app run generate:api",
@@ -27,21 +28,22 @@
2728
"openapi",
2829
"swagger",
2930
"typescript",
30-
"openapi-typescript-codegen"
31+
"openapi-typescript-codegen",
32+
"@hey-api/openapi-ts"
3133
],
3234
"author": "Daiki Urata (@7nohe)",
3335
"license": "MIT",
3436
"devDependencies": {
37+
"@hey-api/openapi-ts": "0.27.38",
3538
"@types/node": "^20.10.6",
3639
"commander": "^12.0.0",
3740
"glob": "^10.3.10",
38-
"openapi-typescript-codegen": "0.25.0",
3941
"typescript": "^5.3.3"
4042
},
4143
"peerDependencies": {
44+
"@hey-api/openapi-ts": "0.27.38",
4245
"commander": ">= 11 < 13",
4346
"glob": ">= 10",
44-
"openapi-typescript-codegen": "^0.24.0",
4547
"typescript": ">= 4.8.3"
4648
}
4749
}

0 commit comments

Comments
 (0)