Skip to content

@kubb/swagger-zodios 🦙

With the Swagger zodios plugin you can use zodios to validate your schema's based on a Swagger file.

Installation

shell
bun add @kubb/swagger-zodios @kubb/swagger-zod @kubb/swagger
shell
pnpm add @kubb/swagger-zodios @kubb/swagger-zod @kubb/swagger
shell
npm install @kubb/swagger-zodios @kubb/swagger-zod @kubb/swagger
shell
yarn add @kubb/swagger-zodios @kubb/swagger-zod @kubb/swagger

Options

output

output.path

Output to save the zodios instance.
Output should be a file(ending with .ts or .js).

INFO

Type: string
Default: 'zodios.ts'

typescript
import { defineConfig } from '@kubb/core'
import { definePlugin as createSwagger } from '@kubb/swagger'
import { definePlugin as createSwaggerZod } from '@kubb/swagger-zod'
import { definePlugin as createSwaggerZodios } from '@kubb/swagger-zodios'

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

output.exportAs

Name to be used for the export * as from './'

INFO

Type: string

typescript
import { defineConfig } from '@kubb/core'
import { definePlugin as createSwagger } from '@kubb/swagger'
import { definePlugin as createSwaggerZod } from '@kubb/swagger-zod'
import { definePlugin as createSwaggerZodios } from '@kubb/swagger-zodios'

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

output.extName

Add an extension to the generated imports and exports, default it will not use an extension

INFO

Type: string

typescript
import { defineConfig } from '@kubb/core'
import { definePlugin as createSwagger } from '@kubb/swagger'
import { definePlugin as createSwaggerZod } from '@kubb/swagger-zod'
import { definePlugin as createSwaggerZodios } from '@kubb/swagger-zodios'

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

output.exportType

Define what needs to exported, here you can also disable the export of barrel files

INFO

Type: 'barrel' | 'barrelNamed' | false

Depended

Released under the MIT License.