Skip to content

Downgrade int64 to a plain number

Kubb maps an OpenAPI integer with format: int64 to the bigint schema kind, and plugin-zod's default printer turns that into z.bigint(). Override the bigint node to emit z.number() instead, useful when the rest of a codebase treats large IDs as plain numbers.

kubb.config.ts
typescript
import { defineConfig } from 'kubb/config'
import { pluginZod } from '@kubb/plugin-zod'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen', clean: true },
  plugins: [
    pluginZod({
      output: { path: 'zod', mode: 'directory' },
      printer: {
        nodes: {
          bigint() {
            return 'z.number()'
          },
        },
      },
    }),
  ],
})

Output example

src/gen/zod/petSchema.ts
typescript
export const petSchema = z.object({
  id: z.number().optional().meta({ examples: [10] }),
  // ...
})

Without the override, that same field prints id: z.bigint().optional().meta({ examples: [10] }). The integer node (for 32-bit format: int32 fields) is a separate handler from bigint, so overriding one does not affect the other.

usage.ts
typescript
import { petSchema } from './src/gen/zod/petSchema'

// id now parses as a JS number, not a bigint
const pet = petSchema.parse({ id: 10, name: 'Rex', photoUrls: [] })