Set your own baseURL
Set a baseURL in two ways. Read it from the servers list in your OpenAPI spec, or pass the baseURL option to the client plugin.
Read it from the spec
When you set no baseURL on the client plugin, the client falls back to the server URL the OpenAPI adapter resolves. The adapter resolves one only when you point its server.index at an entry in the spec's servers array, so set adapter: adapterOas({ server: { index: 0 } }) to use the first entry. Add variables to fill in any {variable} placeholders in the chosen URL. Leave server unset and the spec contributes no baseURL.
openapi: 3.0.3
info:
title: Swagger Example
description:
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
servers:
- url: http://petstore.swagger.io/api
- url: http://localhost:3000import { } from 'kubb'
import { } from '@kubb/adapter-oas'
import { } from '@kubb/plugin-axios'
export default ({
: {
: './petStore.yaml',
},
: {
: './src/gen',
},
: ({ : { : 0 } }),
: [()],
})defineConfig applies adapterOas() for you, so you set adapter only to change an adapter option. Here it sets server.index so the adapter resolves http://petstore.swagger.io/api from the spec.
Use the baseURL option
Pass baseURL to the client plugin. It prepends the URL to every request.
import { } from 'kubb'
import { } from '@kubb/plugin-axios'
import { } from '@kubb/plugin-react-query'
export default ({
: {
: './petStore.yaml',
},
: {
: './src/gen',
},
: [
({
: 'https://localhost:8080/api/v1',
}),
({
: 'axios',
}),
],
})