Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support of fetch client as part of `@kubb/plugin-client #1456

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .changeset/honest-years-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/plugin-client": minor
---

support of fetch client as part of ``@kubb/plugin-client`
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ title: Changelog

# Changelog

## 3.3.0
- [`plugin-client`](/plugins/plugin-client): `client` to use `fetch` or `axios` as HTTP client

## 3.2.0
- [`plugin-msw`](/plugins/plugin-msw): `paramsCasing` to define casing for params
- [`plugin-react-query`](/plugins/plugin-react-query/): `paramsCasing` to define casing for params
Expand Down
4 changes: 2 additions & 2 deletions docs/knowledge-base/fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ outline: deep
---

# Use of Fetch <Badge type="info" text="@kubb/plugin-client" />
By default, `@kubb/plugin-client` uses the import client from `@kubb/plugin-client/client` as its client, which is based on the Axios instance interface for making API calls.
By default, `@kubb/plugin-client` uses the import client from `@kubb/plugin-client/clients/axios` as its client, which is based on the Axios instance interface for making API calls.

However, there are cases where you might want to customize the client. For example, you might prefer to use [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) or [Ky](https://github.com/sindresorhus/ky).

## Create a `kubb.config.ts` with the following config
`importPath` can be a relative, import alias, or an import to another library(default `@kubb/plugin-client/client` will be used).
`importPath` can be a relative, import alias, or an import to another library(default `@kubb/plugin-client/clients/axios` will be used).

See [plugins/plugin-client](/plugins/plugin-client/#client).
```typescript twoslash
Expand Down
11 changes: 11 additions & 0 deletions docs/plugins/plugin-client/client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Which client should be used to do the HTTP calls

| | |
|----------:|:---------------------|
| Type: | `'axios' \| 'fetch'` |
| Required: | `false` |
| Default: | `'axios'` |


- `'axios'` will use `@kubb/plugin-client/clients/axios` to fetch data.
- `'fetch'` will use `@kubb/plugin-client/clients/fetch` to fetch data.
2 changes: 1 addition & 1 deletion docs/plugins/plugin-client/importPath.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ It allows both relative and absolute path but be aware that we will not change t
|----------:|:-------------------------------|
| Type: | `string` |
| Required: | `false` |
| Default: | `'@kubb/plugin-client/client'` |
| Default: | `'@kubb/plugin-client/clients/axios'` |
4 changes: 4 additions & 0 deletions docs/plugins/plugin-client/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ Create `operations.ts` file with all operations grouped by methods.
### parser
<!--@include: ../plugin-client/parser.md-->

### client
<!--@include: ../plugin-client/client.md-->

### baseURL
<!--@include: ../plugin-client/baseURL.md-->

Expand Down Expand Up @@ -210,6 +213,7 @@ export default defineConfig({
],
pathParamsType: "object",
dataReturnType: 'full',
client: 'axios'
}),
],
})
Expand Down
2 changes: 1 addition & 1 deletion e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@kubb/core": ["../packages/core/src/index.ts"],
"@kubb/plugin-oas": ["../packages/plugin-oas/src/index.ts"],
"@kubb/plugin-client": ["../packages/plugin-client/src/index.ts"],
"@kubb/plugin-client/client": ["../packages/plugin-client/client.ts"],
"@kubb/plugin-client/clients/axios": ["../packages/plugin-client/client.ts"],
"@kubb/plugin-faker": ["../packages/plugin-faker/src/index.ts"],
"@kubb/plugin-msw": ["../packages/plugin-msw/src/index.ts"],
"@kubb/plugin-react-query": ["../packages/plugin-react-query/src/index.ts"],
Expand Down
4 changes: 2 additions & 2 deletions examples/client/src/gen/clients/axios/petService/addPet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from '../../../models/ts/petController/AddPet.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description Add a new pet to the store
Expand Down
4 changes: 2 additions & 2 deletions examples/client/src/gen/clients/axios/petService/deletePet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams, DeletePet400 } from '../../../models/ts/petController/DeletePet.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description delete a pet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams, FindPetsByStatus400 } from '../../../models/ts/petController/FindPetsByStatus.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description Multiple status values can be provided with comma separated strings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, FindPetsByTags400 } from '../../../models/ts/petController/FindPetsByTags.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { GetPetByIdQueryResponse, GetPetByIdPathParams, GetPetById400, GetPetById404 } from '../../../models/ts/petController/GetPetById.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description Returns a single pet
Expand Down
4 changes: 2 additions & 2 deletions examples/client/src/gen/clients/axios/petService/updatePet.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type {
UpdatePetMutationRequest,
UpdatePetMutationResponse,
UpdatePet400,
UpdatePet404,
UpdatePet405,
} from '../../../models/ts/petController/UpdatePet.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description Update an existing pet by Id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type {
UpdatePetWithFormMutationResponse,
UpdatePetWithFormPathParams,
UpdatePetWithFormQueryParams,
UpdatePetWithForm405,
} from '../../../models/ts/petController/UpdatePetWithForm.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @summary Updates a pet in the store with form data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type {
UploadFileMutationRequest,
UploadFileMutationResponse,
UploadFilePathParams,
UploadFileQueryParams,
} from '../../../models/ts/petController/UploadFile.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @summary uploads an image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { CreateUserMutationRequest, CreateUserMutationResponse } from '../../../models/ts/userController/CreateUser.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description This can only be done by the logged in user.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type {
CreateUsersWithListInputMutationRequest,
CreateUsersWithListInputMutationResponse,
} from '../../../models/ts/userController/CreateUsersWithListInput.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description Creates list of users with given input array
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { DeleteUserMutationResponse, DeleteUserPathParams, DeleteUser400, DeleteUser404 } from '../../../models/ts/userController/DeleteUser.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description This can only be done by the logged in user.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type {
GetUserByNameQueryResponse,
GetUserByNamePathParams,
GetUserByName400,
GetUserByName404,
} from '../../../models/ts/userController/GetUserByName.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @summary Get user by user name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { LoginUserQueryResponse, LoginUserQueryParams, LoginUser400 } from '../../../models/ts/userController/LoginUser.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @summary Logs user into the system
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { LogoutUserQueryResponse } from '../../../models/ts/userController/LogoutUser.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @summary Logs out current logged in user session
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-alert, no-console */
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { UpdateUserMutationRequest, UpdateUserMutationResponse, UpdateUserPathParams } from '../../../models/ts/userController/UpdateUser.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description This can only be done by the logged in user.
Expand Down
4 changes: 2 additions & 2 deletions examples/client/src/gen/tag.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { DeleteOrderMutationResponse, DeleteOrderPathParams, DeleteOrder400, DeleteOrder404 } from './models/ts/storeController/DeleteOrder.js'
import type { GetInventoryQueryResponse } from './models/ts/storeController/GetInventory.js'
import type { GetOrderByIdQueryResponse, GetOrderByIdPathParams, GetOrderById400, GetOrderById404 } from './models/ts/storeController/GetOrderById.js'
import type { PlaceOrderMutationRequest, PlaceOrderMutationResponse, PlaceOrder405 } from './models/ts/storeController/PlaceOrder.js'
import type { PlaceOrderPatchMutationRequest, PlaceOrderPatchMutationResponse, PlaceOrderPatch405 } from './models/ts/storeController/PlaceOrderPatch.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description Returns a map of status codes to quantities
Expand Down
4 changes: 2 additions & 2 deletions examples/client/src/gen/tagObject.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import client from '@kubb/plugin-client/client'
import client from '@kubb/plugin-client/clients/axios'
import type { DeleteOrderMutationResponse, DeleteOrderPathParams, DeleteOrder400, DeleteOrder404 } from './models/ts/storeController/DeleteOrder.js'
import type { GetInventoryQueryResponse } from './models/ts/storeController/GetInventory.js'
import type { GetOrderByIdQueryResponse, GetOrderByIdPathParams, GetOrderById400, GetOrderById404 } from './models/ts/storeController/GetOrderById.js'
import type { PlaceOrderMutationRequest, PlaceOrderMutationResponse, PlaceOrder405 } from './models/ts/storeController/PlaceOrder.js'
import type { PlaceOrderPatchMutationRequest, PlaceOrderPatchMutationResponse, PlaceOrderPatch405 } from './models/ts/storeController/PlaceOrderPatch.js'
import type { RequestConfig } from '@kubb/plugin-client/client'
import type { RequestConfig } from '@kubb/plugin-client/clients/axios'

/**
* @description Returns a map of status codes to quantities
Expand Down
2 changes: 1 addition & 1 deletion examples/fetch/kubb.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default defineConfig(() => {
output: {
path: '.',
},
importPath: '../client.ts',
client: 'fetch',
}),
],
}
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/addPet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @description Add a new pet to the store
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/createUser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { CreateUserMutationRequest, CreateUserMutationResponse } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @description This can only be done by the logged in user.
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/createUsersWithListInput.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { CreateUsersWithListInputMutationRequest, CreateUsersWithListInputMutationResponse } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @description Creates list of users with given input array
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/deleteOrder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { DeleteOrderMutationResponse, DeleteOrderPathParams, DeleteOrder400, DeleteOrder404 } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/deletePet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams, DeletePet400 } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @description delete a pet
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/deleteUser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { DeleteUserMutationResponse, DeleteUserPathParams, DeleteUser400, DeleteUser404 } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @description This can only be done by the logged in user.
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/findPetsByStatus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams, FindPetsByStatus400 } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @description Multiple status values can be provided with comma separated strings
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/findPetsByTags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, FindPetsByTags400 } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/getInventory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { GetInventoryQueryResponse } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @description Returns a map of status codes to quantities
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/getOrderById.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { GetOrderByIdQueryResponse, GetOrderByIdPathParams, GetOrderById400, GetOrderById404 } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/getPetById.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { GetPetByIdQueryResponse, GetPetByIdPathParams, GetPetById400, GetPetById404 } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @description Returns a single pet
Expand Down
4 changes: 2 additions & 2 deletions examples/fetch/src/gen/getUserByName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '../client.ts'
import type { RequestConfig } from '../client.ts'
import client from '@kubb/plugin-client/clients/fetch'
import type { GetUserByNameQueryResponse, GetUserByNamePathParams, GetUserByName400, GetUserByName404 } from './models.ts'
import type { RequestConfig } from '@kubb/plugin-client/clients/fetch'

/**
* @summary Get user by user name
Expand Down
Loading
Loading