···45454646Ensure you have already [configured](/openapi-ts/get-started) `@hey-api/openapi-ts`. Update your configuration to use the Axios client package.
47474848-```js{2}
4848+```js
4949export default {
5050- client: '@hey-api/client-axios',
5050+ client: '@hey-api/client-axios', // [!code ++]
5151 input: 'path/to/openapi.json',
5252 output: 'src/client',
5353-}
5353+};
5454```
55555656You can now run `openapi-ts` to use the new Axios client. 🎉
+3-3
docs/openapi-ts/clients/fetch.md
···45454646Ensure you have already [configured](/openapi-ts/get-started) `@hey-api/openapi-ts`. Update your configuration to use the Fetch API client package.
47474848-```js{2}
4848+```js
4949export default {
5050- client: '@hey-api/client-fetch',
5050+ client: '@hey-api/client-fetch', // [!code ++]
5151 input: 'path/to/openapi.json',
5252 output: 'src/client',
5353-}
5353+};
5454```
55555656You can now run `openapi-ts` to use the new Fetch API client. 🎉
···86868787Client now has to be explicitly specified and `@hey-api/openapi-ts` will no longer generate a legacy Fetch API client by default. To preserve the previous default behavior, set the `client` option to `fetch`.
88888989-```js{2}
8989+```js
9090export default {
9191- client: 'fetch',
9191+ client: 'fetch', // [!code ++]
9292 input: 'path/to/openapi.json',
9393 output: 'src/client',
9494-}
9494+};
9595```
96969797## v0.48.0
···137137138138If you want to preserve the old behavior, you can set the newly exposed `services.asClass` option to `true.`
139139140140-```js{5}
140140+```js
141141export default {
142142 input: 'path/to/openapi.json',
143143 output: 'src/client',
144144 services: {
145145- asClass: true,
145145+ asClass: true, // [!code ++]
146146 },
147147-}
147147+};
148148```
149149150150## v0.45.0
···153153154154`@hey-api/openapi-ts` will no longer infer which client you want to generate. By default, we will create a `fetch` client. If you want a different client, you can specify it using the `client` option.
155155156156-```js{2}
156156+```js
157157export default {
158158- client: 'axios',
158158+ client: 'axios', // [!code ++]
159159 input: 'path/to/openapi.json',
160160 output: 'src/client',
161161-}
161161+};
162162```
163163164164## v0.44.0
···167167168168This config option has been moved. You can now configure formatter using the `output.format` option.
169169170170-```js{4}
170170+```js
171171export default {
172172+ format: 'prettier', // [!code --]
172173 input: 'path/to/openapi.json',
173174 output: {
174174- format: 'prettier',
175175+ format: 'prettier', // [!code ++]
175176 path: 'src/client',
176177 },
177177-}
178178+};
178179```
179180180181### Moved `lint`
181182182183This config option has been moved. You can now configure linter using the `output.lint` option.
183184184184-```js{4}
185185+```js
185186export default {
186187 input: 'path/to/openapi.json',
188188+ lint: 'eslint', // [!code --]
187189 output: {
188188- lint: 'eslint',
190190+ lint: 'eslint', // [!code ++]
189191 path: 'src/client',
190192 },
191191-}
193193+};
192194```
193195194196## v0.43.0
···226228227229This config option has been moved. You can now configure enums using the `types.enums` option.
228230229229-```js{5}
231231+```js
230232export default {
233233+ enums: 'javascript', // [!code --]
231234 input: 'path/to/openapi.json',
232235 output: 'src/client',
233236 types: {
234234- enums: 'javascript',
237237+ enums: 'javascript', // [!code ++]
235238 },
236236-}
239239+};
237240```
238241239242## v0.42.0
+13-13
docs/openapi-ts/output.md
···86868787::: code-group
88888989-```js{5} [flat]
8989+```js [flat]
9090export default {
9191 input: 'path/to/openapi.json',
9292 output: 'src/client',
9393 services: {
9494- asClass: false,
9494+ asClass: false, // [!code ++]
9595 },
9696-}
9696+};
9797```
98989999-```js{5} [class]
9999+```js [class]
100100export default {
101101 input: 'path/to/openapi.json',
102102 output: 'src/client',
103103 services: {
104104- asClass: true,
104104+ asClass: true, // [!code ++]
105105 },
106106-}
106106+};
107107```
108108109109-```js{4} [none]
109109+```js [none]
110110export default {
111111 input: 'path/to/openapi.json',
112112 output: 'src/client',
113113- services: false,
114114-}
113113+ services: false, // [!code ++]
114114+};
115115```
116116117117:::
···120120121121If you only want to include specific endpoints in the generated services, you can use the `services.filter` config option to filter endpoints. The provided value should be a regular expression to match against endpoints with the `{method} {path}` pattern. For example, the config below will only include all `/api/v1/foo` endpoints.
122122123123-```js{5}
123123+```js
124124export default {
125125 input: 'path/to/openapi.json',
126126 output: 'src/client',
127127 services: {
128128- filter: '^\\w+ /api/v1/foo$'
129129- }
130130-}
128128+ filter: '^\\w+ /api/v1/foo$', // [!code ++]
129129+ },
130130+};
131131```
132132133133### Output
+114-4
docs/openapi-ts/tanstack-query.md
···11---
22title: TanStack Query
33-description: Generate query keys and query functions. Use them with our REST clients or bring your own.
33+description: Generate query keys and functions. Use them with our REST clients or bring your own.
44---
5566-# TanStack Query <span class="soon">Soon</span>
66+<script setup>
77+import { embedProject } from '../embed'
88+</script>
99+1010+# TanStack Query
1111+1212+::: warning
1313+TanStack Query plugin is currently in beta. The interface might change before it becomes stable. We encourage you to leave feedback on [GitHub](https://github.com/hey-api/openapi-ts/issues).
1414+:::
1515+1616+[TanStack Query](https://tanstack.com/query) is one of the most popular state management solutions. Hey API can generate query keys and functions for you, so you can focus on building your product. Everything is compatible with our REST clients, but you can bring your own too.
1717+1818+<button class="buttonLink" @click="(event) => embedProject('hey-api-client-fetch-plugin-tanstack-react-query-example')(event)">
1919+Live demo
2020+</button>
2121+2222+## Installation
2323+2424+Ensure you have already [configured](/openapi-ts/get-started) `@hey-api/openapi-ts`. Update your configuration to use the TanStack Query plugin.
2525+2626+::: code-group
2727+2828+```js{5} [react]
2929+export default {
3030+ client: '@hey-api/client-fetch',
3131+ input: 'path/to/openapi.json',
3232+ output: 'src/client',
3333+ plugins: ['@tanstack/react-query'], // [!code ++]
3434+}
3535+```
73688-[TanStack Query](https://tanstack.com/query) is one of the most popular state management solutions. Hey API can generate query keys and query functions for you, so you can focus on building your product. Everything is compatible with our REST clients, but you can bring your own too.
3737+```js{5} [vue]
3838+export default {
3939+ client: '@hey-api/client-fetch',
4040+ input: 'path/to/openapi.json',
4141+ output: 'src/client',
4242+ plugins: ['@tanstack/vue-query'], // [!code ++]
4343+}
4444+```
9451010-You can follow the updates on [GitHub](https://github.com/hey-api/openapi-ts/issues/653), your feedback is welcome!
4646+```js{5} [solid]
4747+export default {
4848+ client: '@hey-api/client-fetch',
4949+ input: 'path/to/openapi.json',
5050+ output: 'src/client',
5151+ plugins: ['@tanstack/solid-query'], // [!code ++]
5252+}
5353+```
11545555+```js{5} [svelte]
5656+export default {
5757+ client: '@hey-api/client-fetch',
5858+ input: 'path/to/openapi.json',
5959+ output: 'src/client',
6060+ plugins: ['@tanstack/svelte-query'], // [!code ++]
6161+}
6262+```
6363+6464+:::
6565+6666+You can now run `openapi-ts` to generate TanStack Query artifacts. 🎉
6767+6868+## Output
6969+7070+The TanStack Query plugin will optionally generate the following output layers, depending on the input specification.
7171+7272+### Queries
7373+7474+Queries are generated from GET and POST endpoints. The generated functions follow the naming convention of services and append `Options`, e.g. `getPetByIdOptions()`.
7575+7676+```ts
7777+const { data, error } = useQuery({
7878+ ...getPetByIdOptions({
7979+ path: {
8080+ petId: 1,
8181+ },
8282+ }),
8383+});
8484+```
8585+8686+### Infinite Queries
8787+8888+Infinite queries are generated from GET and POST endpoints if we detect a pagination parameter. The generated functions follow the naming convention of services and append `InfiniteOptions`, e.g. `getFooInfiniteOptions()`.
8989+9090+```ts
9191+const { data, error } = useInfiniteQuery({
9292+ ...getFooInfiniteOptions({
9393+ path: {
9494+ fooId: 1,
9595+ },
9696+ }),
9797+ getNextPageParam: (lastPage, pages) => lastPage.nextCursor,
9898+ initialPageParam: 0,
9999+});
100100+```
101101+102102+### Mutations
103103+104104+Mutations are generated from DELETE, PATCH, POST, and PUT endpoints. The generated functions follow the naming convention of services and append `Mutation`, e.g. `addPetMutation()`.
105105+106106+```ts
107107+const addPet = useMutation({
108108+ ...addPetMutation(),
109109+ onError: (error) => {
110110+ console.log(error);
111111+ },
112112+});
113113+114114+addPet.mutate({
115115+ body: {
116116+ name: 'Kitty',
117117+ },
118118+});
119119+```
120120+121121+<!--@include: ../examples.md-->
12122<!--@include: ../sponsorship.md-->
+3-3
docs/openapi-ts/transformers.md
···31313232To automatically convert date strings into `Date` objects, you can use the `types.dates` configuration option.
33333434-```js{6}
3434+```js
3535export default {
3636 client: '@hey-api/client-fetch',
3737 input: 'path/to/openapi.json',
3838 output: 'src/client',
3939 types: {
4040- dates: 'types+transform',
4040+ dates: 'types+transform', // [!code ++]
4141 },
4242-}
4242+};
4343```
44444545This will generate types that use `Date` instead of `string` and appropriate response transformers. Note that 3rd party date packages are not supported at the moment.