Skip to content

Options

This page is a reference to the different options you can use for configuring your Kubb config. By setting the following options you can override the default behaviour of Kubb and even extend it with your own plugins.

root

Project root directory. Can be an absolute path, or a path relative from the location of the config file itself.

INFO

Type: string
Default: process.cwd()

typescript
import { defineConfig } from '@kubb/core'

export default defineConfig({
  root: '.',
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
})
import { defineConfig } from '@kubb/core'

export default defineConfig({
  root: '.',
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
})

input

You can use input.path or input.data depending on the needs you have.

path

Define your Swagger/OpenAPI file.
This can be an absolute path or a path relative to the root.

INFO

Type: string
Required: true

typescript
import { defineConfig } from '@kubb/core'

export default defineConfig({
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
})
import { defineConfig } from '@kubb/core'

export default defineConfig({
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
})

data

string or object containing your Swagger/OpenAPI

INFO

Type: string | unknown
Required: true

typescript
import { defineConfig } from '@kubb/core'

import petStore from './petStore.yaml'

export default defineConfig({
  input: {
    data: petStore,
  },
  output: {
    path: './src/gen',
  },
})
import { defineConfig } from '@kubb/core'

import petStore from './petStore.yaml'

export default defineConfig({
  input: {
    data: petStore,
  },
  output: {
    path: './src/gen',
  },
})

output

path

Path to be used to export all generated files.
This can be an absolute path, or a path relative from the defined root option.

INFO

Type: string
Required: true

typescript
import { defineConfig } from '@kubb/core'

export default defineConfig({
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
})
import { defineConfig } from '@kubb/core'

export default defineConfig({
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
})

clean

Clean output directory before each build.

INFO

Type: boolean

typescript
import { defineConfig } from '@kubb/core'

export default defineConfig({
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
    clean: true,
  },
})
import { defineConfig } from '@kubb/core'

export default defineConfig({
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
    clean: true,
  },
})

write

Write files to the fileSystem.

INFO

Type: boolean
Default: true

typescript
import { defineConfig } from '@kubb/core'

export default defineConfig({
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
    clean: true,
    write: true,
  },
})
import { defineConfig } from '@kubb/core'

export default defineConfig({
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
    clean: true,
    write: true,
  },
})

plugins

Array of Kubb plugins to use. The plugin/package can have some extra options defined by the plugin. Sometimes a plugin is depended on another plugin, if that's the case you will get an error back from the plugin you installed.(see validate)

plugins[index]

TypeScript

INFO

Type: Plugin

typescript
import { defineConfig } from '@kubb/core'
import createSwagger from '@kubb/swagger'

export default defineConfig({
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
  plugins: [createSwagger({})],
})
import { defineConfig } from '@kubb/core'
import createSwagger from '@kubb/swagger'

export default defineConfig({
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
  plugins: [createSwagger({})],
})

JSON

When using JSON, the structure will be a little bit different. Here we are using the same syntax like how Babel makes it possible to use plugins with extra options.

[PLUGIN, {...options}]
[PLUGIN, {...options}]

INFO

json
{
  "$schema": "@kubb/core/schemas/config.json",
  "root": ".",
  "input": {
    "path": "./petStore.yaml"
  },
  "output": {
    "path": "./src/gen"
  },
  "plugins": [
    [
      "@kubb/swagger",
      {
        "output": "schemas",
        "validate": true
      }
    ]
  ]
}
{
  "$schema": "@kubb/core/schemas/config.json",
  "root": ".",
  "input": {
    "path": "./petStore.yaml"
  },
  "output": {
    "path": "./src/gen"
  },
  "plugins": [
    [
      "@kubb/swagger",
      {
        "output": "schemas",
        "validate": true
      }
    ]
  ]
}

hooks

Hooks that will be called when a specific action is triggered in Kubb.

done

Hook that will be triggered at the end of Kubb's generation.
Useful for running Prettier or ESLint to format/lint your code.

INFO

Type: string | string[]

typescript
import { defineConfig } from '@kubb/core'

export default defineConfig({
  hooks: {
    done: ['npx prettier --write .'],
  },
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
})
import { defineConfig } from '@kubb/core'

export default defineConfig({
  hooks: {
    done: ['npx prettier --write .'],
  },
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
})
typescript
import { defineConfig } from '@kubb/core'

export default defineConfig({
  hooks: {
    done: 'npx prettier --write .',
  },
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
})
import { defineConfig } from '@kubb/core'

export default defineConfig({
  hooks: {
    done: 'npx prettier --write .',
  },
  input: {
    path: './petStore.yaml',
  },
  output: {
    path: './src/gen',
  },
})

Released under the MIT License.