Skip to content

Commit cf175e6

Browse files
authored
chore(docs): Update README.md of CLI commands and add info (#88)
1 parent 4f13da8 commit cf175e6

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Options:
4848
--format <value> Process output folder with formatter? ['biome', 'prettier']
4949
--lint <value> Process output folder with linter? ['eslint', 'biome']
5050
--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']
5252
--base <value> Manually set base in OpenAPI config instead of inferring from server value
5353
--enums <value> Generate JavaScript objects from enum definitions? ['javascript', 'typescript']
5454
--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
8080

8181
### In your app
8282

83+
#### Using the generated hooks
84+
8385
```tsx
8486
// App.tsx
8587
import { usePetServiceFindPetsByStatus } from "../openapi/queries";
@@ -97,7 +99,7 @@ function App() {
9799
export default App;
98100
```
99101

100-
You can also use pure TS clients.
102+
#### Using the generated typescript client
101103

102104
```tsx
103105
import { useQuery } from "@tanstack/react-query";
@@ -120,7 +122,7 @@ function App() {
120122
export default App;
121123
```
122124

123-
You can also use suspense hooks.
125+
#### Using Suspense Hooks
124126

125127
```tsx
126128
// App.tsx
@@ -153,6 +155,34 @@ function App() {
153155
export default App;
154156
```
155157

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+
156186
## License
157187

158188
MIT

0 commit comments

Comments
 (0)