Skip to content

Commit

Permalink
chore(docs): Update README.md of CLI commands and add info (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
seriouslag committed Apr 27, 2024
1 parent 4f13da8 commit cf175e6
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Options:
--format <value> Process output folder with formatter? ['biome', 'prettier']
--lint <value> Process output folder with linter? ['eslint', 'biome']
--operationId Use operation ID to generate operation names?
--serviceResponse <value> Define shape of returned value from service calls ['body', 'generics', 'response']
--serviceResponse <value> Define shape of returned value from service calls ['body', 'response']
--base <value> Manually set base in OpenAPI config instead of inferring from server value
--enums <value> Generate JavaScript objects from enum definitions? ['javascript', 'typescript']
--useDateType Use Date type instead of string for date types for models, this will not convert the data to a Date object
Expand Down Expand Up @@ -80,6 +80,8 @@ $ openapi-rq -i ./petstore.yaml

### In your app

#### Using the generated hooks

```tsx
// App.tsx
import { usePetServiceFindPetsByStatus } from "../openapi/queries";
Expand All @@ -97,7 +99,7 @@ function App() {
export default App;
```

You can also use pure TS clients.
#### Using the generated typescript client

```tsx
import { useQuery } from "@tanstack/react-query";
Expand All @@ -120,7 +122,7 @@ function App() {
export default App;
```

You can also use suspense hooks.
#### Using Suspense Hooks

```tsx
// App.tsx
Expand Down Expand Up @@ -153,6 +155,34 @@ function App() {
export default App;
```

#### Runtime Configuration

You can modify the default values used by the generated service calls by modifying the OpenAPI configuration singleton object.

It's default location is `openapi/requests/core/OpenAPI.ts` and it is also exported from `openapi/index.ts`

Import the constant into your runtime and modify it before setting up the react app.

```typescript
/** main.tsx */
import { OpenAPI as OpenAPIConfig } from './openapi/requests/core/OpenAPI';
...
OpenAPIConfig.BASE = 'www.domain.com/api';
OpenAPIConfig.HEADERS = {
'x-header-1': 'value-1',
'x-header-2': 'value-2',
};
...
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<App />
</QueryClientProvider>
</React.StrictMode>
);

```

## License

MIT

0 comments on commit cf175e6

Please sign in to comment.