Skip to content

Commit

Permalink
chore: example for react-query templates (#842)
Browse files Browse the repository at this point in the history
* chore: example for react-query templates

* fix: bundle require

* chore: update docs
  • Loading branch information
stijnvanhulle authored Mar 6, 2024
1 parent c5e4921 commit e851171
Show file tree
Hide file tree
Showing 113 changed files with 2,616 additions and 2,427 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-geese-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/cli": patch
---

correct import with bundle-require
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"dependencies": {
"@vercel/analytics": "^1.2.2",
"sitemap": "^7.1.1",
"vitepress": "^1.0.0-rc.44",
"vitepress": "^1.0.0-rc.45",
"vue": "^3.4.21"
},
"devDependencies": {
"@types/node": "^20.11.24"
"@types/node": "^20.11.25"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/swagger-client/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ export default defineConfig({
})
```

<<< @/../examples/client/templates/CustomClientTemplate.tsx
<<< @/../examples/client/templates/client/index.tsx

:::

Expand Down
8 changes: 4 additions & 4 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
"@kubb/swagger-ts": "workspace:*",
"@kubb/swagger-zod": "workspace:*",
"@kubb/swagger-zodios": "workspace:*",
"@tanstack/react-query": "^5.24.8",
"@tanstack/solid-query": "^5.24.8",
"@tanstack/svelte-query": "^5.24.8",
"@tanstack/vue-query": "^5.24.8",
"@tanstack/react-query": "^5.25.0",
"@tanstack/solid-query": "^5.25.0",
"@tanstack/svelte-query": "^5.25.0",
"@tanstack/vue-query": "^5.25.0",
"@zodios/core": "^10.9.6",
"axios": "^1.6.7",
"msw": "^1.3.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/client/kubb.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from '@kubb/core'

import { templates } from './templates/CustomClientTemplate'
import * as client from './templates/client/index'

export default defineConfig(async () => {
await setTimeout(() => {
Expand Down Expand Up @@ -52,7 +52,7 @@ export default defineConfig(async () => {
pattern: 'user',
options: {
templates: {
client: templates,
client: client.templates,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion examples/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@kubb/ts-config": "workspace:*",
"react": "^18.2.0",
"tsup": "^8.0.2",
"typescript": "^5.3.3"
"typescript": "^5.4.2"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File, Function } from '@kubb/react'
import { Editor, File, Function } from '@kubb/react'
import { Client } from '@kubb/swagger-client/components'
import React from 'react'

Expand All @@ -7,12 +7,12 @@ export const templates = {
const clientParams = [client.path.template, client.withData ? 'data' : undefined, 'options'].filter(Boolean).join(', ')

return (
<>
<Editor language="typescript">
<File.Import name="axios" path="axios" />
<Function name={name} async export generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>
{`return axios.${client.method}(${clientParams})`}
</Function>
</>
</Editor>
)
},
} as const
3 changes: 2 additions & 1 deletion examples/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"noEmit": true
},
"include": [
"./src/**/*"
"./src/**/*",
"./templates/**/*"
],
"exclude": [
"**/node_modules",
Expand Down
2 changes: 1 addition & 1 deletion examples/faker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"devDependencies": {
"@kubb/ts-config": "workspace:*",
"typescript": "^5.3.3"
"typescript": "^5.4.2"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
29 changes: 14 additions & 15 deletions examples/python/kubb.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defineConfig } from '@kubb/core'
import createSwagger from '@kubb/swagger'
import { definePlugin as createSwaggerClient } from '@kubb/swagger-client'

import { templates } from './templates/CustomClientTemplate'
import * as client from './templates/client/index'

export default defineConfig(async () => {
return {
Expand All @@ -17,21 +19,18 @@ export default defineConfig(async () => {
// done: ['npx eslint --fix ./src/gen', 'prettier --write "**/*.{ts,tsx}"', 'pnpm typecheck'],
},
plugins: [
['@kubb/swagger', { output: false, validate: true }],
[
'@kubb/swagger-client',
{
output: {
path: './',
exportType: false,
},
group: { type: 'tag', output: './{{tag}}Service' },
templates: {
client: templates,
operations: false,
},
createSwagger({ output: false, validate: true }),
createSwaggerClient({
output: {
path: './',
exportType: false,
},
],
group: { type: 'tag', output: './{{tag}}Service' },
templates: {
client: client.templates,
operations: false,
},
}),
],
}
})
9 changes: 6 additions & 3 deletions examples/python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
"@kubb/swagger": "workspace:*",
"@kubb/swagger-client": "workspace:*",
"@kubb/swagger-ts": "workspace:*",
"axios": "^1.6.7"
"axios": "^1.6.7",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@kubb/ts-config": "workspace:*",
"react": "^18.2.0",
"@types/react": "^18.2.63",
"@types/react-dom": "^18.2.20",
"tsup": "^8.0.2",
"typescript": "^5.3.3"
"typescript": "^5.4.2"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions examples/python/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"target": "ES2020",
/* If NOT transpiling with TypeScript: */
"module": "ES2020",
"moduleResolution": "Bundler",
"moduleResolution": "node",
"sourceMap": true,
"strictNullChecks": true,
"jsx": "react-jsx",
Expand All @@ -18,7 +18,8 @@
"noEmit": true
},
"include": [
"./src/**/*"
"./src/**/*",
"./templates/**/*"
],
"exclude": [
"**/node_modules",
Expand Down
6 changes: 0 additions & 6 deletions examples/react-query-v5/kubb-log.log

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import createSwagger from '@kubb/swagger'
import createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'
import createSwaggerTS from '@kubb/swagger-ts'

import * as queryKey from './templates/queryKey/index'

/** @type {import('@kubb/core').UserConfig} */
export const config = {
root: '.',
Expand Down Expand Up @@ -50,6 +52,9 @@ export const config = {
initialPageParam: 0,
cursorParam: undefined,
},
templates: {
queryKey: queryKey.templates,
},
},
}],
}),
Expand Down
11 changes: 6 additions & 5 deletions examples/react-query-v5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@
"dependencies": {
"@kubb/cli": "workspace:*",
"@kubb/core": "workspace:*",
"@kubb/react": "workspace:*",
"@kubb/swagger": "workspace:*",
"@kubb/swagger-client": "workspace:*",
"@kubb/swagger-tanstack-query": "workspace:*",
"@kubb/swagger-ts": "workspace:*",
"@tanstack/react-query": "^5.24.8",
"@tanstack/react-query": "^5.25.0",
"@tanstack/react-query-devtools": "5.0.0",
"axios": "^1.6.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tsup": "^8.0.2"
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.62",
"@types/react-dom": "^18.2.19",
"@types/react": "^18.2.63",
"@types/react-dom": "^18.2.20",
"@vitejs/plugin-react": "^4.2.1",
"msw": "^1.3.2",
"tsup": "^8.0.2",
"typescript": "~5.2.2",
"unplugin-kubb": "workspace:*",
"vite": "^4.5.2"
Expand Down
40 changes: 20 additions & 20 deletions examples/react-query-v5/src/gen/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export * from './useAddPetHook'
export * from './useCreateUserHook'
export * from './useCreateUsersWithListInputHook'
export * from './useDeleteOrderHook'
export * from './useDeletePetHook'
export * from './useDeleteUserHook'
export * from './useFindPetsByStatusHook'
export * from './useFindPetsByTagsHook'
export * from './useGetInventoryHook'
export * from './useGetOrderByIdHook'
export * from './useGetPetByIdHook'
export * from './useGetUserByNameHook'
export * from './useLoginUserHook'
export * from './useLogoutUserHook'
export * from './usePlaceOrderHook'
export * from './usePlaceOrderPatchHook'
export * from './useUpdatePetHook'
export * from './useUpdatePetWithFormHook'
export * from './useUpdateUserHook'
export * from './useUploadFileHook'
export * from "./useAddPetHook";
export * from "./useCreateUserHook";
export * from "./useCreateUsersWithListInputHook";
export * from "./useDeleteOrderHook";
export * from "./useDeletePetHook";
export * from "./useDeleteUserHook";
export * from "./useFindPetsByStatusHook";
export * from "./useFindPetsByTagsHook";
export * from "./useGetInventoryHook";
export * from "./useGetOrderByIdHook";
export * from "./useGetPetByIdHook";
export * from "./useGetUserByNameHook";
export * from "./useLoginUserHook";
export * from "./useLogoutUserHook";
export * from "./usePlaceOrderHook";
export * from "./usePlaceOrderPatchHook";
export * from "./useUpdatePetHook";
export * from "./useUpdatePetWithFormHook";
export * from "./useUpdateUserHook";
export * from "./useUploadFileHook";
72 changes: 36 additions & 36 deletions examples/react-query-v5/src/gen/hooks/useAddPetHook.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import client from '@kubb/swagger-client/client'
import { useMutation } from '@tanstack/react-query'
import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from '../models/AddPet'
import type { UseMutationOptions } from '@tanstack/react-query'
import client from "@kubb/swagger-client/client";
import { useMutation } from "@tanstack/react-query";
import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from "../models/AddPet";
import type { UseMutationOptions } from "@tanstack/react-query";

type AddPetClient = typeof client<AddPetMutationResponse, AddPet405, AddPetMutationRequest>
type AddPetClient = typeof client<AddPetMutationResponse, AddPet405, AddPetMutationRequest>;
type AddPet = {
data: AddPetMutationResponse
error: AddPet405
request: AddPetMutationRequest
pathParams: never
queryParams: never
headerParams: never
response: AddPetMutationResponse
client: {
parameters: Partial<Parameters<AddPetClient>[0]>
return: Awaited<ReturnType<AddPetClient>>
}
}
data: AddPetMutationResponse;
error: AddPet405;
request: AddPetMutationRequest;
pathParams: never;
queryParams: never;
headerParams: never;
response: AddPetMutationResponse;
client: {
parameters: Partial<Parameters<AddPetClient>[0]>;
return: Awaited<ReturnType<AddPetClient>>;
};
};
/**
* @description Add a new pet to the store
* @summary Add a new pet to the store
* @link /pet */
* @description Add a new pet to the store
* @summary Add a new pet to the store
* @link /pet */
export function useAddPetHook(options: {
mutation?: UseMutationOptions<AddPet['response'], AddPet['error'], AddPet['request']>
client?: AddPet['client']['parameters']
mutation?: UseMutationOptions<AddPet["response"], AddPet["error"], AddPet["request"]>;
client?: AddPet["client"]["parameters"];
} = {}) {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
return useMutation({
mutationFn: async (data) => {
const res = await client<AddPet['data'], AddPet['error'], AddPet['request']>({
method: 'post',
url: `/pet`,
data,
...clientOptions,
})
return res.data
},
...mutationOptions,
})
}
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {};
return useMutation({
mutationFn: async (data) => {
const res = await client<AddPet["data"], AddPet["error"], AddPet["request"]>({
method: "post",
url: `/pet`,
data,
...clientOptions
});
return res.data;
},
...mutationOptions
});
}
Loading

0 comments on commit e851171

Please sign in to comment.