@@ -48,7 +48,7 @@ Options:
48
48
--format <value> Process output folder with formatter? ['biome', 'prettier']
49
49
--lint <value> Process output folder with linter? ['eslint', 'biome']
50
50
--operationId Use operation ID to generate operation names?
51
- --serviceResponse <value> Define shape of returned value from service calls ['body', 'generics', ' response']
51
+ --serviceResponse <value> Define shape of returned value from service calls ['body', 'response']
52
52
--base <value> Manually set base in OpenAPI config instead of inferring from server value
53
53
--enums <value> Generate JavaScript objects from enum definitions? ['javascript', 'typescript']
54
54
--useDateType Use Date type instead of string for date types for models, this will not convert the data to a Date object
@@ -80,6 +80,8 @@ $ openapi-rq -i ./petstore.yaml
80
80
81
81
### In your app
82
82
83
+ #### Using the generated hooks
84
+
83
85
``` tsx
84
86
// App.tsx
85
87
import { usePetServiceFindPetsByStatus } from " ../openapi/queries" ;
@@ -97,7 +99,7 @@ function App() {
97
99
export default App ;
98
100
```
99
101
100
- You can also use pure TS clients.
102
+ #### Using the generated typescript client
101
103
102
104
``` tsx
103
105
import { useQuery } from " @tanstack/react-query" ;
@@ -120,7 +122,7 @@ function App() {
120
122
export default App ;
121
123
```
122
124
123
- You can also use suspense hooks.
125
+ #### Using Suspense Hooks
124
126
125
127
``` tsx
126
128
// App.tsx
@@ -153,6 +155,34 @@ function App() {
153
155
export default App ;
154
156
```
155
157
158
+ #### Runtime Configuration
159
+
160
+ You can modify the default values used by the generated service calls by modifying the OpenAPI configuration singleton object.
161
+
162
+ It's default location is ` openapi/requests/core/OpenAPI.ts ` and it is also exported from ` openapi/index.ts `
163
+
164
+ Import the constant into your runtime and modify it before setting up the react app.
165
+
166
+ ``` typescript
167
+ /** main.tsx */
168
+ import { OpenAPI as OpenAPIConfig } from ' ./openapi/requests/core/OpenAPI' ;
169
+ ...
170
+ OpenAPIConfig .BASE = ' www.domain.com/api' ;
171
+ OpenAPIConfig .HEADERS = {
172
+ ' x-header-1' : ' value-1' ,
173
+ ' x-header-2' : ' value-2' ,
174
+ };
175
+ ...
176
+ ReactDOM .createRoot (document .getElementById (" root" ) as HTMLElement ).render (
177
+ < React .StrictMode >
178
+ < QueryClientProvider client = {queryClient }>
179
+ < App / >
180
+ < / QueryClientProvider >
181
+ < / React .StrictMode >
182
+ );
183
+
184
+ ```
185
+
156
186
## License
157
187
158
188
MIT
0 commit comments