kubb-labs / kubb

The ultimate toolkit for working with APIs.
https://kubb.dev
MIT License
702 stars 58 forks source link

Kubb v3 ideas #1115

Open stijnvanhulle opened 2 months ago

stijnvanhulle commented 2 months ago

I am already thinking about the next version of Kubb and what should be done to make it better:

https://rollupjs.org/plugin-development/#banner https://unplugin.unjs.io/guide https://coolify.io/docs/knowledge-base/faq

dir commented 2 months ago

On your note of

"Use of the same naming for all plugins: @kubb/plugin-ts instead of @kubb/swagger-ts, prefix plugin is important here."

In a similar vein, I strongly feel that the use of "swagger" anywhere should be vaulted and replaced with openapi.

I know it seems small, but seeing swagger used instead of openapi gives off a strong "stuck in the past" vibe, for an otherwise such modern and forward thinking library.

1saifj commented 2 months ago

react-form-hook?

joakimstrandell commented 3 weeks ago

@stijnvanhulle Will it be possible to set the basePath for the client dynamically in v3? Would be a dealbreaker if you could set the basePath at runtime, not at generation.

stijnvanhulle commented 3 weeks ago

@joakimstrandell Today(in v2 and v3) you can use serverIndex to set the baseUrl: https://www.kubb.dev/plugins/plugin-oas/#serverindex. Other plugins like the @kubb/plugin-client and @kubb/plugin-react-query will use that config to set the baseURL, would that be enough or what do you mean with dynamically?

joakimstrandell commented 3 weeks ago

@stijnvanhulle I mean that I would like to set the path in the client during runtime, for example using some type of custom config. If I would use the server index I need to select the path when generating the client, if I understand the documentation correctly.

For example in hey-api you can set the base url like this:

import { client } from 'api';
import { config } from  'data' // custom

client.setConfig({
  baseUrl: config.api.basePath,
  headers: {
    Authorization: '...',
    'X-Csrftoken': '...',
  },
});
stijnvanhulle commented 3 weeks ago

@joakimstrandell I updated the default client to also have getConfig and setConfig but in Kubb you can also override the default client. This means you can do whatever you want so long you are following the guideline where the parameters are having the same shape as RequestConfig.

type RequestConfig<TData = unknown> = {
  baseURL?: string
  url?: string
  method: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS'
  params?: unknown
  data?: TData | FormData
  responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
  signal?: AbortSignal
  headers?: AxiosRequestConfig['headers']
}
RabbitShare commented 2 weeks ago

Transform snake_case to camelCase in generated code. Transform camelCase to snake_case before request

stijnvanhulle commented 2 weeks ago

@RabbitShare For that I suggest using https://github.com/thim81/openapi-format