diff --git a/.changeset/friendly-starfishes-smoke.md b/.changeset/friendly-starfishes-smoke.md
new file mode 100644
index 000000000..3c40b79ec
--- /dev/null
+++ b/.changeset/friendly-starfishes-smoke.md
@@ -0,0 +1,5 @@
+---
+"@kubb/swagger-tanstack-query": minor
+---
+
+use of `mutate.variablesType` to override mutation behaviour(params in the generated hook or mutate function with extra params)
diff --git a/configs/vitest.config.ts b/configs/vitest.config.ts
index b3d7f2f8a..58491e570 100644
--- a/configs/vitest.config.ts
+++ b/configs/vitest.config.ts
@@ -27,6 +27,7 @@ export default defineConfig({
'**/packages/swagger-client/client.ts',
'**/e2e/**',
'**/coverage/**',
+ '**/__snapshots__/**',
'**/packages/*/test?(s)/**',
'**/*.d.ts',
'test?(s)/**',
diff --git a/docs/plugins/react/hooks/index.md b/docs/plugins/react/hooks/index.md
index f45727573..ed17b52e4 100644
--- a/docs/plugins/react/hooks/index.md
+++ b/docs/plugins/react/hooks/index.md
@@ -32,6 +32,24 @@ function Component() {
:::
+## useLanguage
+
+`useLanguage` will return the current language set by the parent `Editor` component.
+
+::: code-group
+
+```typescript
+import { useLanguage } from '@kubb/react'
+
+function Component() {
+ const language = useLanguage()
+
+ return null
+}
+```
+
+:::
+
## usePluginManager
`usePluginManager` will return the PluginManager instance.
diff --git a/docs/plugins/swagger-tanstack-query/index.md b/docs/plugins/swagger-tanstack-query/index.md
index 39e8c3bf3..f767a72a5 100644
--- a/docs/plugins/swagger-tanstack-query/index.md
+++ b/docs/plugins/swagger-tanstack-query/index.md
@@ -365,6 +365,92 @@ export default defineConfig({
:::
+### variablesType
+
+Define the way of passing thought the queryParams, headerParams and data.
+
+`'mutate'` will use the `mutate` or `mutateAsync` function.
+`'hook'` will use the `useMutation` hook.
+
+::: info type
+
+::: code-group
+
+```typescript ['mutate']
+const { mutate } = useDeletePet()
+
+mutate({
+ petId: 1,
+})
+```
+
+```typescript ['hook']
+const { mutate } = useDeletePet(1)
+
+mutate()
+```
+
+:::
+
+::: info
+
+Type: `'mutate' | 'hook'`
+Default: `'hook'`
+
+::: code-group
+
+```typescript ['mutate']
+import { defineConfig } from '@kubb/core'
+import createSwagger from '@kubb/swagger'
+import createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'
+import createSwaggerTS from '@kubb/swagger-ts'
+
+export default defineConfig({
+ input: {
+ path: './petStore.yaml',
+ },
+ output: {
+ path: './src/gen',
+ },
+ plugins: [
+ createSwagger({ output: false }),
+ createSwaggerTS({}),
+ createSwaggerTanstackQuery(
+ {
+ variablesType: 'mutate',
+ },
+ ),
+ ],
+})
+```
+
+```typescript ['hook']
+import { defineConfig } from '@kubb/core'
+import createSwagger from '@kubb/swagger'
+import createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'
+import createSwaggerTS from '@kubb/swagger-ts'
+
+export default defineConfig({
+ input: {
+ path: './petStore.yaml',
+ },
+ output: {
+ path: './src/gen',
+ },
+ plugins: [
+ createSwagger({ output: false }),
+ createSwaggerTS({}),
+ createSwaggerTanstackQuery(
+ {
+ variablesType: 'hook',
+ },
+ ),
+ ],
+})
+```
+
+:::
+
### parser
Which parser can be used before returning the data to `@tanstack/query`.
diff --git a/docs/plugins/swagger/hooks/index.md b/docs/plugins/swagger/hooks/index.md
index d53fca1cc..29200a370 100644
--- a/docs/plugins/swagger/hooks/index.md
+++ b/docs/plugins/swagger/hooks/index.md
@@ -20,7 +20,7 @@ See [Oas](https://github.com/readmeio/oas) to understand how to use the `Oas` in
import { useOas } from '@kubb/react'
function Component() {
- const { oas } = useOas()
+ const oas = useOas()
return null
}
@@ -46,6 +46,24 @@ function Component() {
:::
+## useOperations
+
+`useOperations` will return all the Operations.
+
+::: code-group
+
+```typescript
+import { useOperations } from '@kubb/react'
+
+function Component() {
+ const operations = useOperations()
+
+ return null
+}
+```
+
+:::
+
## useSchemas
`useSchemas` will return the schemas of the current `Operation`.
@@ -64,6 +82,24 @@ function Component() {
:::
+## useOperationHelpers
+
+`useOperationHelpers` will return some helper functions that can be used to get the operation file, get the operation name.
+
+::: code-group
+
+```typescript
+import { useOperationHelpers } from '@kubb/react'
+
+function Component() {
+ const { getName, getFile } = useOperationHelpers()
+
+ return null
+}
+```
+
+:::
+
## useOperationName
`useOperationName` will return the name based on the current operation and plugin(when `pluginKey` is not provided).
diff --git a/e2e/kubb.config.js b/e2e/kubb.config.js
index 108a3ca88..651547f5e 100644
--- a/e2e/kubb.config.js
+++ b/e2e/kubb.config.js
@@ -55,6 +55,9 @@ const baseConfig = {
path: './clients/hooks',
},
group: { type: 'tag' },
+ mutate: {
+ variablesType: 'mutate',
+ },
}],
['@kubb/swagger-swr', {
output: {
diff --git a/examples/advanced/configs/kubb.config.ts b/examples/advanced/configs/kubb.config.ts
index 4125bd7e5..6c17bbac5 100644
--- a/examples/advanced/configs/kubb.config.ts
+++ b/examples/advanced/configs/kubb.config.ts
@@ -81,6 +81,9 @@ export default defineConfig(async () => {
queryParam: 'test',
initialPageParam: '0',
},
+ mutate: {
+ variablesType: 'mutate',
+ },
},
},
],
diff --git a/examples/advanced/src/gen/clients/hooks/petController/useAddPet.ts b/examples/advanced/src/gen/clients/hooks/petController/useAddPet.ts
index ed119563f..fb6d4dbeb 100644
--- a/examples/advanced/src/gen/clients/hooks/petController/useAddPet.ts
+++ b/examples/advanced/src/gen/clients/hooks/petController/useAddPet.ts
@@ -22,12 +22,18 @@ type AddPet = {
* @summary Add a new pet to the store
* @link /pet */
export function useAddPet(options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: AddPet['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
- mutationFn: async (data) => {
+ return useMutation({
+ mutationFn: async ({ data }) => {
const res = await client({
method: 'post',
url: `/pet`,
diff --git a/examples/advanced/src/gen/clients/hooks/petController/useDeletePet.ts b/examples/advanced/src/gen/clients/hooks/petController/useDeletePet.ts
index 9a7b15d83..0754239a0 100644
--- a/examples/advanced/src/gen/clients/hooks/petController/useDeletePet.ts
+++ b/examples/advanced/src/gen/clients/hooks/petController/useDeletePet.ts
@@ -21,14 +21,23 @@ type DeletePet = {
* @description delete a pet
* @summary Deletes a pet
* @link /pet/:petId */
-export function useDeletePet(petId: DeletePetPathParams['petId'], headers?: DeletePet['headerParams'], options: {
- mutation?: UseMutationOptions
+export function useDeletePet(options: {
+ mutation?: UseMutationOptions
client?: DeletePet['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
- mutationFn: async () => {
- const res = await client({
+ return useMutation({
+ mutationFn: async ({ petId, headers }) => {
+ const res = await client({
method: 'delete',
url: `/pet/${petId}`,
headers: { ...headers, ...clientOptions.headers },
diff --git a/examples/advanced/src/gen/clients/hooks/petController/useUpdatePet.ts b/examples/advanced/src/gen/clients/hooks/petController/useUpdatePet.ts
index 6f9816fb8..d172f0cda 100644
--- a/examples/advanced/src/gen/clients/hooks/petController/useUpdatePet.ts
+++ b/examples/advanced/src/gen/clients/hooks/petController/useUpdatePet.ts
@@ -22,12 +22,18 @@ type UpdatePet = {
* @summary Update an existing pet
* @link /pet */
export function useUpdatePet(options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: UpdatePet['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
- mutationFn: async (data) => {
+ return useMutation({
+ mutationFn: async ({ data }) => {
const res = await client({
method: 'put',
url: `/pet`,
diff --git a/examples/advanced/src/gen/clients/hooks/petController/useUpdatePetWithForm.ts b/examples/advanced/src/gen/clients/hooks/petController/useUpdatePetWithForm.ts
index c371f25b9..2d1fb669a 100644
--- a/examples/advanced/src/gen/clients/hooks/petController/useUpdatePetWithForm.ts
+++ b/examples/advanced/src/gen/clients/hooks/petController/useUpdatePetWithForm.ts
@@ -25,14 +25,23 @@ type UpdatePetWithForm = {
/**
* @summary Updates a pet in the store with form data
* @link /pet/:petId */
-export function useUpdatePetWithForm(petId: UpdatePetWithFormPathParams['petId'], params?: UpdatePetWithForm['queryParams'], options: {
- mutation?: UseMutationOptions
+export function useUpdatePetWithForm(options: {
+ mutation?: UseMutationOptions
client?: UpdatePetWithForm['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
- mutationFn: async () => {
- const res = await client({
+ return useMutation({
+ mutationFn: async ({ petId, params }) => {
+ const res = await client({
method: 'post',
url: `/pet/${petId}`,
params,
diff --git a/examples/advanced/src/gen/clients/hooks/petController/useUploadFile.ts b/examples/advanced/src/gen/clients/hooks/petController/useUploadFile.ts
index 234adaffb..aaca25275 100644
--- a/examples/advanced/src/gen/clients/hooks/petController/useUploadFile.ts
+++ b/examples/advanced/src/gen/clients/hooks/petController/useUploadFile.ts
@@ -25,13 +25,25 @@ type UploadFile = {
/**
* @summary uploads an image
* @link /pet/:petId/uploadImage */
-export function useUploadFile(petId: UploadFilePathParams['petId'], params?: UploadFile['queryParams'], options: {
- mutation?: UseMutationOptions
+export function useUploadFile(options: {
+ mutation?: UseMutationOptions
client?: UploadFile['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
- mutationFn: async (data) => {
+ return useMutation({
+ mutationFn: async ({ petId, params, data }) => {
const res = await client({
method: 'post',
url: `/pet/${petId}/uploadImage`,
diff --git a/examples/advanced/src/gen/clients/hooks/petsController/useCreatePets.ts b/examples/advanced/src/gen/clients/hooks/petsController/useCreatePets.ts
index 17b171a3b..c238e2b8f 100644
--- a/examples/advanced/src/gen/clients/hooks/petsController/useCreatePets.ts
+++ b/examples/advanced/src/gen/clients/hooks/petsController/useCreatePets.ts
@@ -26,13 +26,28 @@ type CreatePets = {
/**
* @summary Create a pet
* @link /pets/:uuid */
-export function useCreatePets(uuid: CreatePetsPathParams['uuid'], headers: CreatePets['headerParams'], params?: CreatePets['queryParams'], options: {
- mutation?: UseMutationOptions
+export function useCreatePets(options: {
+ mutation?: UseMutationOptions
client?: CreatePets['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
- mutationFn: async (data) => {
+ return useMutation({
+ mutationFn: async ({ uuid, headers, data, params }) => {
const res = await client({
method: 'post',
url: `/pets/${uuid}`,
diff --git a/examples/advanced/src/gen/clients/hooks/userController/useDeleteUser.ts b/examples/advanced/src/gen/clients/hooks/userController/useDeleteUser.ts
index 7a85a9a98..fd362acfc 100644
--- a/examples/advanced/src/gen/clients/hooks/userController/useDeleteUser.ts
+++ b/examples/advanced/src/gen/clients/hooks/userController/useDeleteUser.ts
@@ -22,13 +22,13 @@ type DeleteUser = {
* @summary Delete user
* @link /user/:username */
export function useDeleteUser(username: DeleteUserPathParams['username'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: DeleteUser['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
+ return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/user/${username}`,
...clientOptions,
diff --git a/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts b/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts
index c0c8c5b4f..e3ab8c2a5 100644
--- a/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts
+++ b/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts
@@ -23,14 +23,14 @@ type DeleteOrder = {
* @summary Delete purchase order by ID
* @link /store/order/:orderId */
export function useDeleteOrderHook(orderId: DeleteOrderPathParams['orderId'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: DeleteOrder['client']['parameters']
} = {}) {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
const invalidationOnSuccess = useInvalidationForMutation('useDeleteOrderHook')
return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/store/order/${orderId}`,
...clientOptions,
diff --git a/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts b/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts
index 4d0629cd5..04f4a5e57 100644
--- a/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts
+++ b/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts
@@ -23,14 +23,14 @@ type DeletePet = {
* @summary Deletes a pet
* @link /pet/:petId */
export function useDeletePetHook(petId: DeletePetPathParams['petId'], headers?: DeletePet['headerParams'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: DeletePet['client']['parameters']
} = {}) {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
const invalidationOnSuccess = useInvalidationForMutation('useDeletePetHook')
return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/pet/${petId}`,
headers: { ...headers, ...clientOptions.headers },
diff --git a/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts b/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts
index aeb466020..b7193d48b 100644
--- a/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts
+++ b/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts
@@ -23,14 +23,14 @@ type DeleteUser = {
* @summary Delete user
* @link /user/:username */
export function useDeleteUserHook(username: DeleteUserPathParams['username'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: DeleteUser['client']['parameters']
} = {}) {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
const invalidationOnSuccess = useInvalidationForMutation('useDeleteUserHook')
return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/user/${username}`,
...clientOptions,
diff --git a/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts b/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts
index f3046728f..8499cc546 100644
--- a/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts
+++ b/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts
@@ -27,14 +27,14 @@ type UpdatePetWithForm = {
* @summary Updates a pet in the store with form data
* @link /pet/:petId */
export function useUpdatePetWithFormHook(petId: UpdatePetWithFormPathParams['petId'], params?: UpdatePetWithForm['queryParams'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: UpdatePetWithForm['client']['parameters']
} = {}) {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
const invalidationOnSuccess = useInvalidationForMutation('useUpdatePetWithFormHook')
return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'post',
url: `/pet/${petId}`,
params,
diff --git a/examples/react-query-v5/templates/operations/index.tsx b/examples/react-query-v5/templates/operations/index.tsx
index 66f2aeb96..7e67f1b6d 100644
--- a/examples/react-query-v5/templates/operations/index.tsx
+++ b/examples/react-query-v5/templates/operations/index.tsx
@@ -8,12 +8,11 @@ import { usePluginManager } from '@kubb/react'
export const templates = {
...Operations.templates,
- editor: function({}: React.ComponentProps) {
+ root: function({}: React.ComponentProps) {
const pluginManager = usePluginManager()
const { key: pluginKey } = usePlugin()
const operations = useOperations()
- const { getSchemas } = useOas()
- const { getOperationName } = useOperationHelpers()
+ const { getName, getSchemas } = useOperationHelpers()
const root = path.resolve(pluginManager.config.root, pluginManager.config.output.path)
@@ -24,7 +23,7 @@ export const templates = {
}).flat().filter(Boolean)
const invalidations = operations.reduce((acc, operation) => {
- const name = getOperationName(operation, { pluginKey, type: 'function' })
+ const name = getName(operation, { pluginKey, type: 'function' })
const schemas = getSchemas(operation)
acc[name] = `UseMutationOptions<${schemas.response.name}, unknown, ${schemas.request?.name || 'void'}>['onSuccess']`
diff --git a/examples/react-query/src/gen/hooks/useDeleteOrderHook.ts b/examples/react-query/src/gen/hooks/useDeleteOrderHook.ts
index e22cd89c8..f309c6ec9 100644
--- a/examples/react-query/src/gen/hooks/useDeleteOrderHook.ts
+++ b/examples/react-query/src/gen/hooks/useDeleteOrderHook.ts
@@ -22,13 +22,13 @@ type DeleteOrder = {
* @summary Delete purchase order by ID
* @link /store/order/:orderId */
export function useDeleteOrderHook(orderId: DeleteOrderPathParams['orderId'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: DeleteOrder['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
+ return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/store/order/${orderId}`,
...clientOptions,
diff --git a/examples/react-query/src/gen/hooks/useDeletePetHook.ts b/examples/react-query/src/gen/hooks/useDeletePetHook.ts
index 48dad7da9..347d9fa05 100644
--- a/examples/react-query/src/gen/hooks/useDeletePetHook.ts
+++ b/examples/react-query/src/gen/hooks/useDeletePetHook.ts
@@ -22,13 +22,13 @@ type DeletePet = {
* @summary Deletes a pet
* @link /pet/:petId */
export function useDeletePetHook(petId: DeletePetPathParams['petId'], headers?: DeletePet['headerParams'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: DeletePet['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
+ return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/pet/${petId}`,
headers: { ...headers, ...clientOptions.headers },
diff --git a/examples/react-query/src/gen/hooks/useDeleteUserHook.ts b/examples/react-query/src/gen/hooks/useDeleteUserHook.ts
index 14e9965e1..cc2b5dc79 100644
--- a/examples/react-query/src/gen/hooks/useDeleteUserHook.ts
+++ b/examples/react-query/src/gen/hooks/useDeleteUserHook.ts
@@ -22,13 +22,13 @@ type DeleteUser = {
* @summary Delete user
* @link /user/:username */
export function useDeleteUserHook(username: DeleteUserPathParams['username'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: DeleteUser['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
+ return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/user/${username}`,
...clientOptions,
diff --git a/examples/react-query/src/gen/hooks/useUpdatePetWithFormHook.ts b/examples/react-query/src/gen/hooks/useUpdatePetWithFormHook.ts
index 0299f8c00..3d56dea46 100644
--- a/examples/react-query/src/gen/hooks/useUpdatePetWithFormHook.ts
+++ b/examples/react-query/src/gen/hooks/useUpdatePetWithFormHook.ts
@@ -26,13 +26,13 @@ type UpdatePetWithForm = {
* @summary Updates a pet in the store with form data
* @link /pet/:petId */
export function useUpdatePetWithFormHook(petId: UpdatePetWithFormPathParams['petId'], params?: UpdatePetWithForm['queryParams'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: UpdatePetWithForm['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
+ return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'post',
url: `/pet/${petId}`,
params,
diff --git a/examples/simple-single/src/gen/hooks.ts b/examples/simple-single/src/gen/hooks.ts
index 5c28a2559..d6d8a3349 100644
--- a/examples/simple-single/src/gen/hooks.ts
+++ b/examples/simple-single/src/gen/hooks.ts
@@ -341,13 +341,13 @@ type UpdatePetWithForm = {
* @summary Updates a pet in the store with form data
* @link /pet/:petId */
export function useUpdatePetWithForm(petId: UpdatePetWithFormPathParams['petId'], params?: UpdatePetWithForm['queryParams'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: UpdatePetWithForm['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
+ return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'post',
url: `/pet/${petId}`,
params,
@@ -378,13 +378,13 @@ type DeletePet = {
* @summary Deletes a pet
* @link /pet/:petId */
export function useDeletePet(petId: DeletePetPathParams['petId'], headers?: DeletePet['headerParams'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: DeletePet['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
+ return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/pet/${petId}`,
headers: { ...headers, ...clientOptions.headers },
@@ -642,13 +642,13 @@ type DeleteOrder = {
* @summary Delete purchase order by ID
* @link /store/order/:orderId */
export function useDeleteOrder(orderId: DeleteOrderPathParams['orderId'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: DeleteOrder['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
+ return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/store/order/${orderId}`,
...clientOptions,
@@ -960,13 +960,13 @@ type DeleteUser = {
* @summary Delete user
* @link /user/:username */
export function useDeleteUser(username: DeleteUserPathParams['username'], options: {
- mutation?: UseMutationOptions
+ mutation?: UseMutationOptions
client?: DeleteUser['client']['parameters']
-} = {}): UseMutationResult {
+} = {}): UseMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return useMutation({
+ return useMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/user/${username}`,
...clientOptions,
diff --git a/examples/solid-query/src/gen/hooks/deleteOrderQuery.ts b/examples/solid-query/src/gen/hooks/deleteOrderQuery.ts
index 24c7e7359..550b26514 100644
--- a/examples/solid-query/src/gen/hooks/deleteOrderQuery.ts
+++ b/examples/solid-query/src/gen/hooks/deleteOrderQuery.ts
@@ -24,14 +24,14 @@ type DeleteOrder = {
export function deleteOrderQuery(
orderId: DeleteOrderPathParams['orderId'],
options: {
- mutation?: CreateMutationOptions
+ mutation?: CreateMutationOptions
client?: DeleteOrder['client']['parameters']
} = {},
-): CreateMutationResult {
+): CreateMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return createMutation({
+ return createMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/store/order/${orderId}`,
...clientOptions,
diff --git a/examples/solid-query/src/gen/hooks/deletePetQuery.ts b/examples/solid-query/src/gen/hooks/deletePetQuery.ts
index 20a5276fe..bc3ffa309 100644
--- a/examples/solid-query/src/gen/hooks/deletePetQuery.ts
+++ b/examples/solid-query/src/gen/hooks/deletePetQuery.ts
@@ -25,14 +25,14 @@ export function deletePetQuery(
petId: DeletePetPathParams['petId'],
headers?: DeletePet['headerParams'],
options: {
- mutation?: CreateMutationOptions
+ mutation?: CreateMutationOptions
client?: DeletePet['client']['parameters']
} = {},
-): CreateMutationResult {
+): CreateMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return createMutation({
+ return createMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/pet/${petId}`,
headers: { ...headers, ...clientOptions.headers },
diff --git a/examples/solid-query/src/gen/hooks/deleteUserQuery.ts b/examples/solid-query/src/gen/hooks/deleteUserQuery.ts
index 5f32d842a..5d4e35016 100644
--- a/examples/solid-query/src/gen/hooks/deleteUserQuery.ts
+++ b/examples/solid-query/src/gen/hooks/deleteUserQuery.ts
@@ -24,14 +24,14 @@ type DeleteUser = {
export function deleteUserQuery(
username: DeleteUserPathParams['username'],
options: {
- mutation?: CreateMutationOptions
+ mutation?: CreateMutationOptions
client?: DeleteUser['client']['parameters']
} = {},
-): CreateMutationResult {
+): CreateMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return createMutation({
+ return createMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/user/${username}`,
...clientOptions,
diff --git a/examples/solid-query/src/gen/hooks/updatePetWithFormQuery.ts b/examples/solid-query/src/gen/hooks/updatePetWithFormQuery.ts
index 1194f0459..cae67bc21 100644
--- a/examples/solid-query/src/gen/hooks/updatePetWithFormQuery.ts
+++ b/examples/solid-query/src/gen/hooks/updatePetWithFormQuery.ts
@@ -29,14 +29,14 @@ export function updatePetWithFormQuery(
petId: UpdatePetWithFormPathParams['petId'],
params?: UpdatePetWithForm['queryParams'],
options: {
- mutation?: CreateMutationOptions
+ mutation?: CreateMutationOptions
client?: UpdatePetWithForm['client']['parameters']
} = {},
-): CreateMutationResult {
+): CreateMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return createMutation({
+ return createMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'post',
url: `/pet/${petId}`,
params,
diff --git a/examples/svelte-query/src/gen/hooks/deleteOrderQuery.ts b/examples/svelte-query/src/gen/hooks/deleteOrderQuery.ts
index 81c13aa4c..3afcb1d85 100644
--- a/examples/svelte-query/src/gen/hooks/deleteOrderQuery.ts
+++ b/examples/svelte-query/src/gen/hooks/deleteOrderQuery.ts
@@ -24,14 +24,14 @@ type DeleteOrder = {
export function deleteOrderQuery(
orderId: DeleteOrderPathParams['orderId'],
options: {
- mutation?: CreateMutationOptions
+ mutation?: CreateMutationOptions
client?: DeleteOrder['client']['parameters']
} = {},
-): CreateMutationResult {
+): CreateMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return createMutation({
+ return createMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/store/order/${orderId}`,
...clientOptions,
diff --git a/examples/svelte-query/src/gen/hooks/deletePetQuery.ts b/examples/svelte-query/src/gen/hooks/deletePetQuery.ts
index 135bacb2b..a146b3a46 100644
--- a/examples/svelte-query/src/gen/hooks/deletePetQuery.ts
+++ b/examples/svelte-query/src/gen/hooks/deletePetQuery.ts
@@ -25,14 +25,14 @@ export function deletePetQuery(
petId: DeletePetPathParams['petId'],
headers?: DeletePet['headerParams'],
options: {
- mutation?: CreateMutationOptions
+ mutation?: CreateMutationOptions
client?: DeletePet['client']['parameters']
} = {},
-): CreateMutationResult {
+): CreateMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return createMutation({
+ return createMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/pet/${petId}`,
headers: { ...headers, ...clientOptions.headers },
diff --git a/examples/svelte-query/src/gen/hooks/deleteUserQuery.ts b/examples/svelte-query/src/gen/hooks/deleteUserQuery.ts
index 41d3f33c6..8ce3e7c90 100644
--- a/examples/svelte-query/src/gen/hooks/deleteUserQuery.ts
+++ b/examples/svelte-query/src/gen/hooks/deleteUserQuery.ts
@@ -24,14 +24,14 @@ type DeleteUser = {
export function deleteUserQuery(
username: DeleteUserPathParams['username'],
options: {
- mutation?: CreateMutationOptions
+ mutation?: CreateMutationOptions
client?: DeleteUser['client']['parameters']
} = {},
-): CreateMutationResult {
+): CreateMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return createMutation({
+ return createMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/user/${username}`,
...clientOptions,
diff --git a/examples/svelte-query/src/gen/hooks/updatePetWithFormQuery.ts b/examples/svelte-query/src/gen/hooks/updatePetWithFormQuery.ts
index dcbdf680b..70b6bf858 100644
--- a/examples/svelte-query/src/gen/hooks/updatePetWithFormQuery.ts
+++ b/examples/svelte-query/src/gen/hooks/updatePetWithFormQuery.ts
@@ -29,14 +29,14 @@ export function updatePetWithFormQuery(
petId: UpdatePetWithFormPathParams['petId'],
params?: UpdatePetWithForm['queryParams'],
options: {
- mutation?: CreateMutationOptions
+ mutation?: CreateMutationOptions
client?: UpdatePetWithForm['client']['parameters']
} = {},
-): CreateMutationResult {
+): CreateMutationResult {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
- return createMutation({
+ return createMutation({
mutationFn: async () => {
- const res = await client({
+ const res = await client({
method: 'post',
url: `/pet/${petId}`,
params,
diff --git a/examples/vue-query-v5/src/gen/hooks/useDeleteOrder.ts b/examples/vue-query-v5/src/gen/hooks/useDeleteOrder.ts
index a189da8b0..40e78b4c4 100644
--- a/examples/vue-query-v5/src/gen/hooks/useDeleteOrder.ts
+++ b/examples/vue-query-v5/src/gen/hooks/useDeleteOrder.ts
@@ -32,9 +32,9 @@ export function useDeleteOrder(
) {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
return useMutation({
- mutationFn: async () => {
+ mutationFn: async (data) => {
const orderId = unref(refOrderId)
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/store/order/${orderId}`,
...clientOptions,
diff --git a/examples/vue-query-v5/src/gen/hooks/useDeletePet.ts b/examples/vue-query-v5/src/gen/hooks/useDeletePet.ts
index 6289681e9..860cc71d6 100644
--- a/examples/vue-query-v5/src/gen/hooks/useDeletePet.ts
+++ b/examples/vue-query-v5/src/gen/hooks/useDeletePet.ts
@@ -33,10 +33,10 @@ export function useDeletePet(
) {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
return useMutation({
- mutationFn: async () => {
+ mutationFn: async (data) => {
const petId = unref(refPetId)
const headers = unref(refHeaders)
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/pet/${petId}`,
headers: { ...headers, ...clientOptions.headers },
diff --git a/examples/vue-query-v5/src/gen/hooks/useDeleteUser.ts b/examples/vue-query-v5/src/gen/hooks/useDeleteUser.ts
index 58ae86f46..05f7b99ee 100644
--- a/examples/vue-query-v5/src/gen/hooks/useDeleteUser.ts
+++ b/examples/vue-query-v5/src/gen/hooks/useDeleteUser.ts
@@ -32,9 +32,9 @@ export function useDeleteUser(
) {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
return useMutation({
- mutationFn: async () => {
+ mutationFn: async (data) => {
const username = unref(refUsername)
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/user/${username}`,
...clientOptions,
diff --git a/examples/vue-query-v5/src/gen/hooks/useUpdatePetWithForm.ts b/examples/vue-query-v5/src/gen/hooks/useUpdatePetWithForm.ts
index bbf0868a1..4634d5fe1 100644
--- a/examples/vue-query-v5/src/gen/hooks/useUpdatePetWithForm.ts
+++ b/examples/vue-query-v5/src/gen/hooks/useUpdatePetWithForm.ts
@@ -37,10 +37,10 @@ export function useUpdatePetWithForm(
) {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
return useMutation({
- mutationFn: async () => {
+ mutationFn: async (data) => {
const petId = unref(refPetId)
const params = unref(refParams)
- const res = await client({
+ const res = await client({
method: 'post',
url: `/pet/${petId}`,
params,
diff --git a/examples/vue-query/src/gen/hooks/useDeleteOrder.ts b/examples/vue-query/src/gen/hooks/useDeleteOrder.ts
index 0d266c344..28df04808 100644
--- a/examples/vue-query/src/gen/hooks/useDeleteOrder.ts
+++ b/examples/vue-query/src/gen/hooks/useDeleteOrder.ts
@@ -33,9 +33,9 @@ export function useDeleteOrder(
): UseMutationReturnType {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
return useMutation({
- mutationFn: async () => {
+ mutationFn: async (data) => {
const orderId = unref(refOrderId)
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/store/order/${orderId}`,
...clientOptions,
diff --git a/examples/vue-query/src/gen/hooks/useDeletePet.ts b/examples/vue-query/src/gen/hooks/useDeletePet.ts
index c25c1400b..1184890c7 100644
--- a/examples/vue-query/src/gen/hooks/useDeletePet.ts
+++ b/examples/vue-query/src/gen/hooks/useDeletePet.ts
@@ -34,10 +34,10 @@ export function useDeletePet(
): UseMutationReturnType {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
return useMutation({
- mutationFn: async () => {
+ mutationFn: async (data) => {
const petId = unref(refPetId)
const headers = unref(refHeaders)
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/pet/${petId}`,
headers: { ...headers, ...clientOptions.headers },
diff --git a/examples/vue-query/src/gen/hooks/useDeleteUser.ts b/examples/vue-query/src/gen/hooks/useDeleteUser.ts
index 40a31cc09..ee966810a 100644
--- a/examples/vue-query/src/gen/hooks/useDeleteUser.ts
+++ b/examples/vue-query/src/gen/hooks/useDeleteUser.ts
@@ -33,9 +33,9 @@ export function useDeleteUser(
): UseMutationReturnType {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
return useMutation({
- mutationFn: async () => {
+ mutationFn: async (data) => {
const username = unref(refUsername)
- const res = await client({
+ const res = await client({
method: 'delete',
url: `/user/${username}`,
...clientOptions,
diff --git a/examples/vue-query/src/gen/hooks/useUpdatePetWithForm.ts b/examples/vue-query/src/gen/hooks/useUpdatePetWithForm.ts
index 63f11c3dd..a9c6b2ae0 100644
--- a/examples/vue-query/src/gen/hooks/useUpdatePetWithForm.ts
+++ b/examples/vue-query/src/gen/hooks/useUpdatePetWithForm.ts
@@ -38,10 +38,10 @@ export function useUpdatePetWithForm(
): UseMutationReturnType {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
return useMutation({
- mutationFn: async () => {
+ mutationFn: async (data) => {
const petId = unref(refPetId)
const params = unref(refParams)
- const res = await client({
+ const res = await client({
method: 'post',
url: `/pet/${petId}`,
params,
diff --git a/packages/core/src/utils/FunctionParams.test.ts b/packages/core/src/utils/FunctionParams.test.ts
index 9be1c9d84..5ba988c64 100644
--- a/packages/core/src/utils/FunctionParams.test.ts
+++ b/packages/core/src/utils/FunctionParams.test.ts
@@ -66,4 +66,31 @@ describe('objectToParameters', () => {
.toString(),
).toEqual('lastName?: User["lastName"], firstName: User["firstName"] = {}')
})
+
+ test('if object is resolved to a string with array typed parameters', () => {
+ expect(
+ new FunctionParams().add([
+ [{ name: 'id' }],
+ { name: 'params' },
+ ]).toString(),
+ ).toEqual('{ id }, params')
+ expect(
+ new FunctionParams()
+ .add([
+ [{ name: 'id' }, { name: 'data' }],
+ { name: 'params' },
+ ])
+ .toString(),
+ ).toEqual('{ id, data }, params')
+ expect(
+ new FunctionParams()
+ .add([
+ [{ name: 'id', type: 'Id' }, { name: 'data', type: 'Data' }],
+ { name: 'params', type: 'Params' },
+ ])
+ .toString(),
+ ).toEqual('{ id, data }?: { id: Id, data: Data }, params: Params')
+ })
+
+ test.todo('if static functionality works')
})
diff --git a/packages/core/src/utils/FunctionParams.ts b/packages/core/src/utils/FunctionParams.ts
index a012e9990..d743f2e29 100644
--- a/packages/core/src/utils/FunctionParams.ts
+++ b/packages/core/src/utils/FunctionParams.ts
@@ -32,55 +32,128 @@ type FunctionParamsASTWithType = {
export type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType
export class FunctionParams {
- public type?: 'generics' | 'typed'
- public items: FunctionParamsAST[] = []
+ type?: 'generics' | 'typed'
+ #items: Array = []
constructor(type?: 'generics' | 'typed') {
this.type = type
return this
}
- add(item: FunctionParamsAST | Array | undefined): FunctionParams {
+ get items(): FunctionParamsAST[] {
+ return this.#items.flat()
+ }
+
+ add(item: FunctionParamsAST | Array | undefined): FunctionParams {
if (!item) {
return this
}
if (Array.isArray(item)) {
- item.filter(Boolean).forEach((it) => this.items.push(it))
+ item.filter(Boolean).forEach((it) => this.#items.push(it))
return this
}
- this.items.push(item)
+ this.#items.push(item)
return this
}
+ static #orderItems(items: Array) {
+ return orderBy(items.filter(Boolean), [
+ (v) => {
+ if (Array.isArray(v)) {
+ return undefined
+ }
+ return !v.default
+ },
+ (v) => {
+ if (Array.isArray(v)) {
+ return undefined
+ }
+ return v.required ?? true
+ },
+ ], [
+ 'desc',
+ 'desc',
+ ])
+ }
- toString(): string {
- const sortedData = orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ['desc', 'desc'])
+ static #addParams(acc: string[], item: FunctionParamsAST) {
+ const { enabled = true, name, type, required = true, ...rest } = item
+
+ if (!enabled) {
+ return acc
+ }
+
+ if (!name) {
+ // when name is not se we will use TypeScript generics
+ acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)
+
+ return acc
+ }
+ // TODO check whey we still need the camelcase here
+ const parameterName = name.startsWith('{') ? name : camelCase(name)
+
+ if (type) {
+ if (required) {
+ acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)
+ } else {
+ acc.push(`${parameterName}?: ${type}`)
+ }
+ } else {
+ acc.push(`${parameterName}`)
+ }
+
+ return acc
+ }
+
+ static toObject(items: FunctionParamsAST[]): FunctionParamsAST {
+ let type: string[] = []
+ let name: string[] = []
+
+ const enabled = items.every(item => item.enabled) ? items.at(0)?.enabled : true
+ const required = items.every(item => item.required) ?? true
+
+ items.forEach(item => {
+ name = FunctionParams.#addParams(name, { ...item, type: undefined })
+ if (items.some(item => item.type)) {
+ type = FunctionParams.#addParams(type, item)
+ }
+ })
+
+ return {
+ name: `{ ${name.join(', ')} }`,
+ type: type.length ? `{ ${type.join(', ')} }` : undefined,
+ enabled,
+ required,
+ }
+ }
+
+ static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string {
+ const sortedData = this.#orderItems(items)
return sortedData
- .filter(({ enabled = true }) => enabled)
- .reduce((acc, { name, type, required = true, ...rest }) => {
- if (!name) {
- // when name is not se we will use TypeScript generics
- acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)
+ .reduce((acc, item) => {
+ if (Array.isArray(item)) {
+ const subItems = this.#orderItems(item) as FunctionParamsAST[]
+ const objectItem = FunctionParams.toObject(subItems)
- return acc
- }
- // TODO check whey we still need the camelcase here
- const parameterName = name.startsWith('{') ? name : camelCase(name)
-
- if (type) {
- if (required) {
- acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)
- } else {
- acc.push(`${parameterName}?: ${type}`)
- }
- } else {
- acc.push(`${parameterName}`)
+ return FunctionParams.#addParams(acc, objectItem)
}
- return acc
+ return FunctionParams.#addParams(acc, item)
}, [] as string[])
.join(', ')
}
+
+ toObject(): FunctionParamsAST {
+ const items = FunctionParams.#orderItems(this.#items).flat()
+
+ return FunctionParams.toObject(items)
+ }
+
+ toString(): string {
+ const items = FunctionParams.#orderItems(this.#items)
+
+ return FunctionParams.toString(items)
+ }
}
diff --git a/packages/react/src/hooks/useFile.ts b/packages/react/src/hooks/useFile.ts
index 50b07dead..e2e2e67d9 100644
--- a/packages/react/src/hooks/useFile.ts
+++ b/packages/react/src/hooks/useFile.ts
@@ -10,6 +10,9 @@ type Props = {
options?: TOptions
}
+/**
+ * With `useFile` you can get all props needed to create a file(path, baseName, source).
+ */
export function useFile({ name, mode, extName, pluginKey, options }: Props): KubbFile.File<{ pluginKey: Plugin['key'] }> {
const pluginManager = usePluginManager()
diff --git a/packages/react/src/hooks/useFileManager.ts b/packages/react/src/hooks/useFileManager.ts
index ddd0073f0..856dbbda1 100644
--- a/packages/react/src/hooks/useFileManager.ts
+++ b/packages/react/src/hooks/useFileManager.ts
@@ -2,6 +2,9 @@ import { useApp } from './useApp.ts'
import type { FileManager, PluginManager } from '@kubb/core'
+/**
+ * `useFileManager` will return the current FileManager instance.
+ */
export function useFileManager(): FileManager {
const app = useApp<{ pluginManager: PluginManager }>()
diff --git a/packages/react/src/hooks/useLanguage.ts b/packages/react/src/hooks/useLanguage.ts
index ae4c59c0b..b50939ff0 100644
--- a/packages/react/src/hooks/useLanguage.ts
+++ b/packages/react/src/hooks/useLanguage.ts
@@ -4,6 +4,9 @@ import { Editor } from '../components/index.ts'
import type { EditorContextProps } from '../components/Editor.tsx'
+/**
+ * `useLanguage` will return the current language set by the parent `Editor` component.
+ */
export function useLanguage(): EditorContextProps {
return useContext(Editor.Context)
}
diff --git a/packages/react/src/hooks/useMeta.ts b/packages/react/src/hooks/useMeta.ts
index 3cf0f64d8..a5c97025f 100644
--- a/packages/react/src/hooks/useMeta.ts
+++ b/packages/react/src/hooks/useMeta.ts
@@ -2,6 +2,9 @@ import { useApp } from './useApp.ts'
import type { AppContextProps } from '../components/App.tsx'
+/**
+ * `useMeta` will return an object containing the meta that has been provided with the `root.render` functionality.
+ */
export function useMeta = Record>(): AppContextProps['meta'] {
const app = useApp()
diff --git a/packages/react/src/hooks/usePackageVersion.ts b/packages/react/src/hooks/usePackageVersion.ts
index 83e146dda..005f6800b 100644
--- a/packages/react/src/hooks/usePackageVersion.ts
+++ b/packages/react/src/hooks/usePackageVersion.ts
@@ -4,7 +4,9 @@ type Props = {
dependency: string
version: string
}
-
+/**
+ * With `usePackageVersion` you can validate of a specific package is set in the `package.json`.
+ */
export function usePackageVersion({ dependency, version }: Props): boolean {
const manager = new PackageManager()
diff --git a/packages/react/src/hooks/usePlugin.ts b/packages/react/src/hooks/usePlugin.ts
index 89f846066..c18168080 100644
--- a/packages/react/src/hooks/usePlugin.ts
+++ b/packages/react/src/hooks/usePlugin.ts
@@ -2,6 +2,9 @@ import { useApp } from './useApp.ts'
import type { Plugin, PluginFactoryOptions } from '@kubb/core'
+/**
+ * `usePlugin` will return the current plugin.
+ */
export function usePlugin(): Plugin {
const app = useApp<{ plugin: Plugin }>()
diff --git a/packages/react/src/hooks/usePluginManager.ts b/packages/react/src/hooks/usePluginManager.ts
index cbdbb1b55..cbe8b8346 100644
--- a/packages/react/src/hooks/usePluginManager.ts
+++ b/packages/react/src/hooks/usePluginManager.ts
@@ -2,6 +2,9 @@ import { useApp } from './useApp.ts'
import type { PluginManager } from '@kubb/core'
+/**
+ * `usePluginManager` will return the PluginManager instance.
+ */
export function usePluginManager(): PluginManager {
const app = useApp<{ pluginManager: PluginManager }>()
diff --git a/packages/react/src/hooks/useResolveName.ts b/packages/react/src/hooks/useResolveName.ts
index a75640e43..7215259d9 100644
--- a/packages/react/src/hooks/useResolveName.ts
+++ b/packages/react/src/hooks/useResolveName.ts
@@ -4,6 +4,10 @@ import type { ResolveNameParams } from '@kubb/core'
type Props = ResolveNameParams
+/**
+ * Resolve a name based on what has been set inside the `resolveName` of a specific plugin.
+ * Use `pluginKey` to retreive the name of that specific plugin.
+ */
export function useResolveName(props: Props): string {
const pluginManager = usePluginManager()
diff --git a/packages/react/src/hooks/useResolvePath.ts b/packages/react/src/hooks/useResolvePath.ts
index 73ff6a70c..4162f376e 100644
--- a/packages/react/src/hooks/useResolvePath.ts
+++ b/packages/react/src/hooks/useResolvePath.ts
@@ -4,6 +4,10 @@ import type { KubbFile, ResolvePathParams } from '@kubb/core'
type Props = ResolvePathParams
+/**
+ * Resolve a path based on what has been set inside the `resolvePath` of a specific plugin.
+ * Use `pluginKey` to retreive the path of that specific plugin.
+ */
export function useResolvePath(props: Props): KubbFile.OptionalPath {
const pluginManager = usePluginManager()
diff --git a/packages/react/src/shared/ReactTemplate.tsx b/packages/react/src/shared/ReactTemplate.tsx
index 63b69c750..e0b97c08d 100644
--- a/packages/react/src/shared/ReactTemplate.tsx
+++ b/packages/react/src/shared/ReactTemplate.tsx
@@ -106,10 +106,9 @@ export class ReactTemplate {
this.#lastFiles = files
}
onError(error: Error): void {
- if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'development') {
+ if (process.env.NODE_ENV === 'test') {
console.error(error)
}
-
if (!this.logger) {
console.error(error)
}
diff --git a/packages/swagger-client/src/OperationGenerator.test.tsx b/packages/swagger-client/src/OperationGenerator.test.tsx
index 60542b09a..8496e4924 100644
--- a/packages/swagger-client/src/OperationGenerator.test.tsx
+++ b/packages/swagger-client/src/OperationGenerator.test.tsx
@@ -93,7 +93,7 @@ describe('OperationGenerator', async () => {
operations: Operations.templates,
client: {
default: CustomClientTemplate,
- editor: Client.templates.editor,
+ root: Client.templates.root,
},
},
client: {
diff --git a/packages/swagger-client/src/components/Client.tsx b/packages/swagger-client/src/components/Client.tsx
index bf4997a1a..66c406064 100644
--- a/packages/swagger-client/src/components/Client.tsx
+++ b/packages/swagger-client/src/components/Client.tsx
@@ -76,11 +76,11 @@ return ${client.dataReturnType === 'data' ? 'res.data' : 'res'}
)
}
-type EditorTemplateProps = {
+type RootTemplateProps = {
children?: React.ReactNode
}
-function EditorTemplate({ children }: EditorTemplateProps) {
+function RootTemplate({ children }: RootTemplateProps) {
const { options: { client: { importPath } } } = usePlugin()
const schemas = useSchemas()
@@ -112,7 +112,7 @@ function EditorTemplate({ children }: EditorTemplateProps) {
)
}
-const defaultTemplates = { default: Template, editor: EditorTemplate } as const
+const defaultTemplates = { default: Template, root: RootTemplate } as const
type Templates = Partial
@@ -195,12 +195,12 @@ Client.File = function(props: FileProps): KubbNode {
const templates = { ...defaultTemplates, ...props.templates }
const Template = templates.default
- const EditorTemplate = templates.editor
+ const RootTemplate = templates.root
return (
-
+
-
+
)
}
diff --git a/packages/swagger-client/src/components/Operations.tsx b/packages/swagger-client/src/components/Operations.tsx
index c5e45b0d9..a98441d47 100644
--- a/packages/swagger-client/src/components/Operations.tsx
+++ b/packages/swagger-client/src/components/Operations.tsx
@@ -36,11 +36,11 @@ function Template({
)
}
-type EditorTemplateProps = {
+type RootTemplateProps = {
children?: React.ReactNode
}
-function EditorTemplate({ children }: EditorTemplateProps) {
+function RootTemplate({ children }: RootTemplateProps) {
const { key: pluginKey } = usePlugin()
const file = useFile({ name: 'operations', extName: '.ts', pluginKey })
@@ -59,7 +59,7 @@ function EditorTemplate({ children }: EditorTemplateProps) {
)
}
-const defaultTemplates = { default: Template, editor: EditorTemplate } as const
+const defaultTemplates = { default: Template, root: RootTemplate } as const
type Templates = Partial
@@ -94,12 +94,12 @@ Operations.File = function(props: FileProps): KubbNode {
const templates = { ...defaultTemplates, ...props.templates }
const Template = templates.default
- const EditorTemplate = templates.editor
+ const RootTemplate = templates.root
return (
-
+
-
+
)
}
diff --git a/packages/swagger-faker/src/components/Mutation.tsx b/packages/swagger-faker/src/components/Mutation.tsx
index a83580921..16e68c573 100644
--- a/packages/swagger-faker/src/components/Mutation.tsx
+++ b/packages/swagger-faker/src/components/Mutation.tsx
@@ -30,7 +30,7 @@ Mutation.File = function({}: FileProps): ReactNode {
const schemas = useSchemas()
const pluginManager = usePluginManager()
- const { oas } = useOas()
+ const oas = useOas()
const file = useOperationFile()
const builder = new FakerBuilder(options, { oas, pluginManager })
diff --git a/packages/swagger-faker/src/components/Query.tsx b/packages/swagger-faker/src/components/Query.tsx
index f55f64cc6..d5d56eb54 100644
--- a/packages/swagger-faker/src/components/Query.tsx
+++ b/packages/swagger-faker/src/components/Query.tsx
@@ -30,7 +30,7 @@ Query.File = function({}: FileProps): ReactNode {
const schemas = useSchemas()
const pluginManager = usePluginManager()
- const { oas } = useOas()
+ const oas = useOas()
const file = useOperationFile()
const builder = new FakerBuilder(options, { oas, pluginManager })
diff --git a/packages/swagger-msw/src/components/Operations.tsx b/packages/swagger-msw/src/components/Operations.tsx
index fbc6caadd..61eddf558 100644
--- a/packages/swagger-msw/src/components/Operations.tsx
+++ b/packages/swagger-msw/src/components/Operations.tsx
@@ -29,17 +29,17 @@ type EditorTemplateProps = {
children?: React.ReactNode
}
-function EditorTemplate({ children }: EditorTemplateProps) {
+function RootTemplate({ children }: EditorTemplateProps) {
const { key: pluginKey } = usePlugin()
const file = useFile({ name: 'handlers', extName: '.ts', pluginKey })
const operations = useOperations()
- const { getOperationName, getOperationFile } = useOperationHelpers()
+ const { getName, getFile } = useOperationHelpers()
const imports = operations.map(operation => {
- const operationFile = getOperationFile(operation, { pluginKey })
- const operationName = getOperationName(operation, { pluginKey, type: 'function' })
+ const operationFile = getFile(operation, { pluginKey })
+ const operationName = getName(operation, { pluginKey, type: 'function' })
return
}).filter(Boolean)
@@ -60,7 +60,7 @@ function EditorTemplate({ children }: EditorTemplateProps) {
)
}
-const defaultTemplates = { default: Template, editor: EditorTemplate } as const
+const defaultTemplates = { default: Template, root: RootTemplate } as const
type Templates = Partial
@@ -77,12 +77,12 @@ export function Operations({
const { key: pluginKey } = usePlugin()
const operations = useOperations()
- const { getOperationName } = useOperationHelpers()
+ const { getName } = useOperationHelpers()
return (
getOperationName(operation, { type: 'function', pluginKey }))}
+ handlers={operations.map(operation => getName(operation, { type: 'function', pluginKey }))}
/>
)
}
@@ -98,12 +98,12 @@ Operations.File = function(props: FileProps): KubbNode {
const templates = { ...defaultTemplates, ...props.templates }
const Template = templates.default
- const EditorTemplate = templates.editor
+ const RootTemplate = templates.root
return (
-
+
-
+
)
}
diff --git a/packages/swagger-tanstack-query/mocks/petStore.yaml b/packages/swagger-tanstack-query/mocks/petStore.yaml
index 2823edd82..0c2b67859 100644
--- a/packages/swagger-tanstack-query/mocks/petStore.yaml
+++ b/packages/swagger-tanstack-query/mocks/petStore.yaml
@@ -1,48 +1,70 @@
-openapi: '3.0.0'
+openapi: 3.0.3
info:
- version: 1.0.0
- title: Swagger Petstore
+ title: Swagger Petstore - OpenAPI 3.0
+ description: |-
+ This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
+ Swagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
+ You can now help us improve the API whether it's by making changes to the definition itself or to the code.
+ That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
+
+ Some useful links:
+ - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
+ - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
+
+ termsOfService: http://swagger.io/terms/
+ contact:
+ email: apiteam@swagger.io
license:
- name: MIT
+ name: Apache 2.0
+ url: http://www.apache.org/licenses/LICENSE-2.0.html
+ version: 1.0.11
+externalDocs:
+ description: Find out more about Swagger
+ url: http://swagger.io
servers:
- - url: http://petstore.swagger.io/v1
+ - url: https://petstore3.swagger.io/api/v3
+tags:
+ - name: pet
+ description: Everything about your Pets
+ externalDocs:
+ description: Find out more
+ url: http://swagger.io
+ - name: store
+ description: Access to Petstore orders
+ externalDocs:
+ description: Find out more about our store
+ url: http://swagger.io
+ - name: user
+ description: Operations about user
paths:
- /pets:
- get:
- summary: List all pets
- operationId: listPets
+ /pets/{uuid}:
+ post:
+ summary: Create a pet
+ operationId: createPets
tags:
- pets
parameters:
- - name: limit
+ - description: UUID
+ in: path
+ name: uuid
+ required: true
+ schema:
+ type: string
+ - description: Offset
in: query
- description: How many items to return at one time (max 100)
- required: false
+ name: offset
+ schema:
+ type: integer
+ - description: Header parameters
+ in: header
+ name: X-EXAMPLE
+ required: true
schema:
type: string
- responses:
- '200':
- description: A paged array of pets
- headers:
- x-next:
- description: A link to the next page of responses
- schema:
- type: string
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/Pets'
- default:
- description: unexpected error
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/Error'
- post:
- summary: Create a pet
- operationId: createPets
- tags:
- - pets
+ enum:
+ - ONE
+ - TWO
+ - THREE
requestBody:
required: true
content:
@@ -50,81 +72,902 @@ paths:
schema:
type: object
required:
- - 'name'
- - 'tag'
+ - "name"
+ - "tag"
properties:
name:
type: string
tag:
type: string
responses:
- '201':
+ "201":
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
- $ref: '#/components/schemas/Error'
- /pets/{petId}:
+ $ref: "#/components/responses/PetNotFound"
+ /pet:
+ put:
+ tags:
+ - pet
+ summary: Update an existing pet
+ description: Update an existing pet by Id
+ operationId: updatePet
+ requestBody:
+ description: Update an existent pet in the store
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ application/x-www-form-urlencoded:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ required: true
+ responses:
+ "200":
+ description: Successful operation
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ "400":
+ description: Invalid ID supplied
+ "404":
+ description: Pet not found
+ "405":
+ description: Validation exception
+ security:
+ - petstore_auth:
+ - write:pets
+ - read:pets
+ post:
+ tags:
+ - pet
+ summary: Add a new pet to the store
+ description: Add a new pet to the store
+ operationId: addPet
+ requestBody:
+ description: Create a new pet in the store
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/AddPetRequest"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ application/x-www-form-urlencoded:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ required: true
+ responses:
+ "200":
+ description: Successful operation
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ "405":
+ description: Invalid input
+ $ref: "#/components/responses/PetNotFound"
+ security:
+ - petstore_auth:
+ - write:pets
+ - read:pets
+ /pet/findByStatus:
get:
- summary: Info for a specific pet
- operationId: showPetById
tags:
- - pets
+ - pet
+ summary: Finds Pets by status
+ description: Multiple status values can be provided with comma separated strings
+ operationId: findPetsByStatus
+ parameters:
+ - name: status
+ in: query
+ description: Status values that need to be considered for filter
+ required: false
+ explode: true
+ schema:
+ type: string
+ default: available
+ enum:
+ - available
+ - pending
+ - sold
+ responses:
+ "200":
+ description: successful operation
+ content:
+ application/json:
+ schema:
+ type: array
+ minItems: 1
+ maxItems: 3
+ items:
+ $ref: "#/components/schemas/Pet"
+ application/xml:
+ schema:
+ type: array
+ items:
+ $ref: "#/components/schemas/Pet"
+ "400":
+ description: Invalid status value
+ security:
+ - petstore_auth:
+ - write:pets
+ - read:pets
+ /pet/findByTags:
+ get:
+ tags:
+ - pet
+ summary: Finds Pets by tags
+ description: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
+ operationId: findPetsByTags
+ parameters:
+ - name: tags
+ in: query
+ description: Tags to filter by
+ required: false
+ explode: true
+ schema:
+ type: array
+ items:
+ type: string
+ - $ref: "#/components/parameters/page"
+ - $ref: "#/components/parameters/pageSize"
+ - description: Header parameters
+ in: header
+ name: X-EXAMPLE
+ required: true
+ schema:
+ type: string
+ enum:
+ - ONE
+ - TWO
+ - THREE
+ responses:
+ "200":
+ description: successful operation
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: "#/components/schemas/Pet"
+ application/xml:
+ schema:
+ type: array
+ items:
+ $ref: "#/components/schemas/Pet"
+ "400":
+ description: Invalid tag value
+ security:
+ - petstore_auth:
+ - write:pets
+ - read:pets
+ /pet/{petId}:
+ get:
+ tags:
+ - pet
+ summary: Find pet by ID
+ description: Returns a single pet
+ operationId: getPetById
+ parameters:
+ - name: petId
+ in: path
+ description: ID of pet to return
+ required: true
+ schema:
+ type: integer
+ format: int64
+ responses:
+ "200":
+ description: successful operation
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ "400":
+ description: Invalid ID supplied
+ "404":
+ description: Pet not found
+ security:
+ - api_key: []
+ - petstore_auth:
+ - write:pets
+ - read:pets
+ post:
+ tags:
+ - pet
+ summary: Updates a pet in the store with form data
+ description: ""
+ operationId: updatePetWithForm
parameters:
- name: petId
in: path
+ description: ID of pet that needs to be updated
required: true
- description: The id of the pet to retrieve
+ schema:
+ type: integer
+ format: int64
+ - name: name
+ in: query
+ description: Name of pet that needs to be updated
+ schema:
+ type: string
+ - name: status
+ in: query
+ description: Status of pet that needs to be updated
+ schema:
+ type: string
+ responses:
+ "405":
+ description: Invalid input
+ security:
+ - petstore_auth:
+ - write:pets
+ - read:pets
+ delete:
+ tags:
+ - pet
+ summary: Deletes a pet
+ description: delete a pet
+ operationId: deletePet
+ parameters:
+ - name: api_key
+ in: header
+ description: ""
+ required: false
schema:
type: string
- - name: testId
+ - name: petId
+ in: path
+ description: Pet id to delete
+ required: true
+ schema:
+ type: integer
+ format: int64
+ responses:
+ "400":
+ description: Invalid pet value
+ security:
+ - petstore_auth:
+ - write:pets
+ - read:pets
+ /pet/{petId}/uploadImage:
+ post:
+ tags:
+ - pet
+ summary: uploads an image
+ description: ""
+ operationId: uploadFile
+ parameters:
+ - name: petId
+ in: path
+ description: ID of pet to update
+ required: true
+ schema:
+ type: integer
+ format: int64
+ - name: additionalMetadata
+ in: query
+ description: Additional Metadata
+ required: false
+ schema:
+ type: string
+ requestBody:
+ content:
+ application/octet-stream:
+ schema:
+ type: string
+ format: binary
+ responses:
+ "200":
+ description: successful operation
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/ApiResponse"
+ security:
+ - petstore_auth:
+ - write:pets
+ - read:pets
+ /store/inventory:
+ get:
+ tags:
+ - store
+ summary: Returns pet inventories by status
+ description: Returns a map of status codes to quantities
+ operationId: getInventory
+ responses:
+ "200":
+ description: successful operation
+ content:
+ application/json:
+ schema:
+ type: object
+ additionalProperties:
+ type: integer
+ format: int32
+ security:
+ - api_key: []
+ /store/order:
+ post:
+ tags:
+ - store
+ summary: Place an order for a pet
+ description: Place a new order in the store
+ operationId: placeOrder
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Order"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/Order"
+ application/x-www-form-urlencoded:
+ schema:
+ $ref: "#/components/schemas/Order"
+ responses:
+ "200":
+ description: successful operation
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Order"
+ "405":
+ description: Invalid input
+
+ patch:
+ tags:
+ - store
+ summary: Place an order for a pet with patch
+ description: Place a new order in the store with patch
+ operationId: placeOrderPatch
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Order"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/Order"
+ application/x-www-form-urlencoded:
+ schema:
+ $ref: "#/components/schemas/Order"
+ responses:
+ "200":
+ description: successful operation
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Order"
+ "405":
+ description: Invalid input
+ /store/order/{orderId}:
+ get:
+ tags:
+ - store
+ summary: Find purchase order by ID
+ description: For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
+ operationId: getOrderById
+ parameters:
+ - name: orderId
+ in: path
+ description: ID of order that needs to be fetched
+ required: true
+ schema:
+ type: integer
+ format: int64
+ responses:
+ "200":
+ description: successful operation
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Order"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/Order"
+ "400":
+ description: Invalid ID supplied
+ "404":
+ description: Order not found
+ delete:
+ tags:
+ - store
+ summary: Delete purchase order by ID
+ description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
+ operationId: deleteOrder
+ parameters:
+ - name: orderId
in: path
+ description: ID of the order that needs to be deleted
required: true
- description: The id of the pet to retrieve
+ schema:
+ type: integer
+ format: int64
+ responses:
+ "400":
+ description: Invalid ID supplied
+ "404":
+ description: Order not found
+ /user:
+ post:
+ tags:
+ - user
+ summary: Create user
+ description: This can only be done by the logged in user.
+ operationId: createUser
+ requestBody:
+ description: Created user object
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/User"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/User"
+ application/x-www-form-urlencoded:
+ schema:
+ $ref: "#/components/schemas/User"
+ responses:
+ default:
+ description: successful operation
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/User"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/User"
+ /user/createWithList:
+ post:
+ tags:
+ - user
+ summary: Creates list of users with given input array
+ description: Creates list of users with given input array
+ operationId: createUsersWithListInput
+ requestBody:
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: "#/components/schemas/User"
+ responses:
+ "200":
+ description: Successful operation
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/User"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/User"
+ default:
+ description: successful operation
+ /user/login:
+ get:
+ tags:
+ - user
+ summary: Logs user into the system
+ description: ""
+ operationId: loginUser
+ parameters:
+ - name: username
+ in: query
+ description: The user name for login
+ required: false
+ schema:
+ type: string
+ - name: password
+ in: query
+ description: The password for login in clear text
+ required: false
schema:
type: string
responses:
- '200':
- description: Expected response to a valid request
+ "200":
+ description: successful operation
+ headers:
+ X-Rate-Limit:
+ description: calls per hour allowed by the user
+ schema:
+ type: integer
+ format: int32
+ X-Expires-After:
+ description: date in UTC when token expires
+ schema:
+ type: string
+ format: date-time
content:
+ application/xml:
+ schema:
+ type: string
application/json:
schema:
- $ref: '#/components/schemas/Pet'
+ type: string
+ "400":
+ description: Invalid username/password supplied
+ /user/logout:
+ get:
+ tags:
+ - user
+ summary: Logs out current logged in user session
+ description: ""
+ operationId: logoutUser
+ parameters: []
+ responses:
default:
- description: unexpected error
+ description: successful operation
+ /user/{username}:
+ get:
+ tags:
+ - user
+ summary: Get user by user name
+ description: ""
+ operationId: getUserByName
+ parameters:
+ - name: username
+ in: path
+ description: "The name that needs to be fetched. Use user1 for testing. "
+ required: true
+ schema:
+ type: string
+ responses:
+ "200":
+ description: successful operation
content:
application/json:
schema:
- $ref: '#/components/schemas/Error'
+ $ref: "#/components/schemas/User"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/User"
+ "400":
+ description: Invalid username supplied
+ "404":
+ description: User not found
+ put:
+ tags:
+ - user
+ summary: Update user
+ description: This can only be done by the logged in user.
+ operationId: updateUser
+ parameters:
+ - name: username
+ in: path
+ description: name that need to be deleted
+ required: true
+ schema:
+ type: string
+ requestBody:
+ description: Update an existent user in the store
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/User"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/User"
+ application/x-www-form-urlencoded:
+ schema:
+ $ref: "#/components/schemas/User"
+ responses:
+ default:
+ description: successful operation
+ delete:
+ tags:
+ - user
+ summary: Delete user
+ description: This can only be done by the logged in user.
+ operationId: deleteUser
+ parameters:
+ - name: username
+ in: path
+ description: The name that needs to be deleted
+ required: true
+ schema:
+ type: string
+ responses:
+ "400":
+ description: Invalid username supplied
+ "404":
+ description: User not found
components:
schemas:
+ Order:
+ type: object
+ properties:
+ id:
+ type: integer
+ format: int64
+ example: 10
+ petId:
+ type: integer
+ format: int64
+ example: 198772
+ quantity:
+ type: integer
+ format: int32
+ example: 7
+ shipDate:
+ type: string
+ format: date-time
+ status:
+ type: string
+ description: Order Status
+ example: approved
+ enum:
+ - placed
+ - approved
+ - delivered
+ http_status:
+ type: number
+ description: HTTP Status
+ example: 200
+ enum:
+ - 200
+ - 400
+ - 500
+ x-enumNames:
+ - ok
+ - not_found
+ complete:
+ type: boolean
+ xml:
+ name: order
+ Customer:
+ type: object
+ properties:
+ id:
+ type: integer
+ format: int64
+ example: 100000
+ username:
+ type: string
+ example: fehguy
+ address:
+ type: array
+ xml:
+ name: addresses
+ wrapped: true
+ items:
+ $ref: "#/components/schemas/Address"
+ xml:
+ name: customer
+ Address:
+ type: object
+ properties:
+ street:
+ type: string
+ example: 437 Lytton
+ city:
+ type: string
+ example: Palo Alto
+ state:
+ type: string
+ example: CA
+ zip:
+ type: string
+ example: "94301"
+ xml:
+ name: address
+ Category:
+ type: object
+ properties:
+ id:
+ type: integer
+ format: int64
+ example: 1
+ name:
+ type: string
+ example: Dogs
+ xml:
+ name: category
+ User:
+ type: object
+ properties:
+ id:
+ type: integer
+ format: int64
+ example: 10
+ username:
+ type: string
+ example: theUser
+ firstName:
+ type: string
+ example: John
+ lastName:
+ type: string
+ example: James
+ email:
+ type: string
+ example: john@email.com
+ password:
+ type: string
+ example: "12345"
+ phone:
+ type: string
+ example: "12345"
+ userStatus:
+ type: integer
+ description: User Status
+ format: int32
+ example: 1
+ xml:
+ name: user
+ tag.Tag:
+ type: object
+ properties:
+ id:
+ type: integer
+ format: int64
+ name:
+ type: string
+ xml:
+ name: tag
+
Pet:
+ required:
+ - name
+ - photoUrls
type: object
+ properties:
+ id:
+ type: integer
+ format: int64
+ example: 10
+ readOnly: true
+ name:
+ type: string
+ example: doggie
+ writeOnly: true
+ category:
+ $ref: "#/components/schemas/Category"
+ photoUrls:
+ type: array
+ xml:
+ wrapped: true
+ items:
+ type: string
+ xml:
+ name: photoUrl
+ tags:
+ type: array
+ xml:
+ wrapped: true
+ items:
+ $ref: "#/components/schemas/tag.Tag"
+ status:
+ type: string
+ description: pet status in the store
+ enum:
+ - available
+ - pending
+ - sold
+ xml:
+ name: pet
+ AddPetRequest:
required:
- - id
- name
+ - photoUrls
+ type: object
properties:
id:
type: integer
format: int64
+ example: 10
name:
type: string
- tag:
+ example: doggie
+ category:
+ $ref: "#/components/schemas/Category"
+ photoUrls:
+ type: array
+ xml:
+ wrapped: true
+ items:
+ type: string
+ xml:
+ name: photoUrl
+ tags:
+ type: array
+ xml:
+ wrapped: true
+ items:
+ $ref: "#/components/schemas/tag.Tag"
+ status:
type: string
- Pets:
- type: array
- items:
- $ref: '#/components/schemas/Pet'
- Error:
+ description: pet status in the store
+ enum:
+ - available
+ - pending
+ - sold
+ xml:
+ name: pet
+ ApiResponse:
type: object
- required:
- - code
- - message
properties:
code:
type: integer
format: int32
+ type:
+ type: string
message:
type: string
+ xml:
+ name: "##default"
+ requestBodies:
+ Pet:
+ description: Pet object that needs to be added to the store
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ application/xml:
+ schema:
+ $ref: "#/components/schemas/Pet"
+ UserArray:
+ description: List of user object
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: "#/components/schemas/User"
+ securitySchemes:
+ petstore_auth:
+ type: oauth2
+ flows:
+ implicit:
+ authorizationUrl: https://petstore3.swagger.io/oauth/authorize
+ scopes:
+ write:pets: modify pets in your account
+ read:pets: read your pets
+ api_key:
+ type: apiKey
+ name: api_key
+ in: header
+ parameters:
+ page:
+ description: to request with required page number or pagination
+ in: query
+ name: page
+ required: false
+ schema:
+ type: string
+ pageSize:
+ description: to request with required page size
+ in: query
+ name: pageSize
+ required: false
+ schema:
+ type: string
+ responses:
+ PetNotFound:
+ content:
+ application/json:
+ schema:
+ properties:
+ code:
+ format: int32
+ type: integer
+ message:
+ type: string
+ description: Pet not found
diff --git a/packages/swagger-tanstack-query/src/OperationGenerator.test.tsx b/packages/swagger-tanstack-query/src/OperationGenerator.test.tsx
new file mode 100644
index 000000000..f0c4f65f6
--- /dev/null
+++ b/packages/swagger-tanstack-query/src/OperationGenerator.test.tsx
@@ -0,0 +1,188 @@
+import { FileManager } from '@kubb/core'
+import { mockedPluginManager } from '@kubb/core/mocks'
+import { OasManager } from '@kubb/swagger'
+
+import { Mutation } from './components/Mutation.tsx'
+import { Query } from './components/Query.tsx'
+import { QueryKey } from './components/QueryKey.tsx'
+import { QueryOptions } from './components/QueryOptions.tsx'
+import { OperationGenerator } from './OperationGenerator.tsx'
+
+import type { KubbFile } from '@kubb/core'
+import type { Plugin } from '@kubb/core'
+import type { GetOperationGeneratorOptions } from '@kubb/swagger'
+import type { PluginOptions } from './types.ts'
+
+describe('OperationGenerator', async () => {
+ const oas = await OasManager.parseFromConfig({
+ root: './',
+ output: { path: 'test', clean: true },
+ input: { path: 'packages/swagger-tanstack-query/mocks/petStore.yaml' },
+ })
+
+ test('[GET] should generate with pathParamsType `inline`', async () => {
+ const options: GetOperationGeneratorOptions = {
+ framework: 'react',
+ infinite: undefined,
+ suspense: undefined,
+ dataReturnType: 'data',
+ pathParamsType: 'inline',
+ templates: {
+ query: Query.templates,
+ queryKey: QueryKey.templates,
+ queryOptions: QueryOptions.templates,
+ },
+ client: {
+ importPath: '@kubb/swagger-client/client',
+ },
+ parser: undefined,
+ query: {},
+ mutate: {},
+ }
+
+ const og = await new OperationGenerator(
+ options,
+ {
+ oas,
+ exclude: [],
+ include: undefined,
+ pluginManager: mockedPluginManager,
+ plugin: { options } as Plugin,
+ contentType: undefined,
+ override: undefined,
+ },
+ )
+ const operation = oas.operation('/pets/{uuid}', 'get')
+ const files = await og.get(operation, options) as KubbFile.File[]
+
+ files.forEach(file => {
+ expect(FileManager.getSource(file)).toMatchSnapshot()
+ })
+ })
+
+ test('[GET] should generate with pathParamsType `object`', async () => {
+ const options: GetOperationGeneratorOptions = {
+ framework: 'react',
+ infinite: undefined,
+ suspense: undefined,
+ dataReturnType: 'data',
+ pathParamsType: 'object',
+ templates: {
+ query: Query.templates,
+ queryKey: QueryKey.templates,
+ queryOptions: QueryOptions.templates,
+ },
+ client: {
+ importPath: '@kubb/swagger-client/client',
+ },
+ parser: undefined,
+ query: {},
+ mutate: {},
+ }
+
+ const og = await new OperationGenerator(
+ options,
+ {
+ oas,
+ exclude: [],
+ include: undefined,
+ pluginManager: mockedPluginManager,
+ plugin: { options } as Plugin,
+ contentType: undefined,
+ override: undefined,
+ },
+ )
+ const operation = oas.operation('/pets/{pet_id}', 'get')
+ const files = await og.get(operation, options) as KubbFile.File[]
+
+ files.forEach(file => {
+ expect(FileManager.getSource(file)).toMatchSnapshot()
+ })
+ })
+
+ test('[POST] should generate with variablesType `mutate`', async () => {
+ const options: GetOperationGeneratorOptions = {
+ framework: 'react',
+ infinite: undefined,
+ suspense: undefined,
+ dataReturnType: 'data',
+ pathParamsType: 'inline',
+ templates: {
+ query: Query.templates,
+ queryKey: QueryKey.templates,
+ queryOptions: QueryOptions.templates,
+ mutation: Mutation.templates,
+ },
+ client: {
+ importPath: '@kubb/swagger-client/client',
+ },
+ parser: undefined,
+ query: {},
+ mutate: {
+ variablesType: 'mutate',
+ },
+ }
+
+ const og = await new OperationGenerator(
+ options,
+ {
+ oas,
+ exclude: [],
+ include: undefined,
+ pluginManager: mockedPluginManager,
+ plugin: { options } as Plugin,
+ contentType: undefined,
+ override: undefined,
+ },
+ )
+ const operation = oas.operation('/pets', 'post')
+ const files = await og.post(operation, options) as KubbFile.File[]
+
+ files.forEach(file => {
+ expect(FileManager.getSource(file)).toMatchSnapshot()
+ })
+ })
+
+ test('[DELETE] should generate with variablesType `mutate`', async () => {
+ const options: GetOperationGeneratorOptions = {
+ framework: 'react',
+ infinite: undefined,
+ suspense: undefined,
+ dataReturnType: 'data',
+ pathParamsType: 'inline',
+ templates: {
+ query: Query.templates,
+ queryKey: QueryKey.templates,
+ queryOptions: QueryOptions.templates,
+ mutation: Mutation.templates,
+ },
+ client: {
+ importPath: '@kubb/swagger-client/client',
+ },
+ parser: undefined,
+ query: {},
+ mutate: {
+ variablesType: 'mutate',
+ },
+ }
+
+ const og = await new OperationGenerator(
+ options,
+ {
+ oas,
+ exclude: [],
+ include: undefined,
+ pluginManager: mockedPluginManager,
+ plugin: { options } as Plugin,
+ contentType: undefined,
+ override: undefined,
+ },
+ )
+ const operation = oas.operation('/pet/{petId}', 'delete')
+ const files = await og.delete(operation, options) as KubbFile.File[]
+
+ files.forEach(file => {
+ expect(FileManager.getSource(file)).toMatchSnapshot()
+ })
+ })
+})
diff --git a/packages/swagger-tanstack-query/src/__snapshots__/OperationGenerator.test.tsx.snap b/packages/swagger-tanstack-query/src/__snapshots__/OperationGenerator.test.tsx.snap
new file mode 100644
index 000000000..5f793e018
--- /dev/null
+++ b/packages/swagger-tanstack-query/src/__snapshots__/OperationGenerator.test.tsx.snap
@@ -0,0 +1,119 @@
+// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
+
+exports[`OperationGenerator > [DELETE] should generate with variablesType \`mutate\` 1`] = `
+"import client from "@kubb/swagger-client/client";
+import { useMutation } from "@tanstack/react-query";
+import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams, DeletePet400 } from "./";
+import type { UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
+
+ type DeletePetClient = typeof client;
+type DeletePet = {
+ data: DeletePetMutationResponse;
+ error: DeletePet400;
+ request: never;
+ pathParams: DeletePetPathParams;
+ queryParams: never;
+ headerParams: DeletePetHeaderParams;
+ response: DeletePetMutationResponse;
+ client: {
+ parameters: Partial[0]>;
+ return: Awaited>;
+ };
+};
+/**
+ * @description delete a pet
+ * @summary Deletes a pet
+ * @link /pet/:petId */
+export function deletePet(options: {
+ mutation?: UseMutationOptions