Skip to content

Strip descriptions with a macro

Pass a macro that clears description on every schema node. Macros run on the shared AST before a plugin prints code, so this keeps generated schemas free of the spec's prose without touching the OpenAPI document, and the same macro works for @kubb/plugin-ts too since both read the same AST.

kubb.config.ts
typescript
import { 
defineConfig
} from 'kubb/config'
import {
pluginZod
} from '@kubb/plugin-zod'
import {
ast
} from 'kubb/kit'
const
macroDropDescriptions
=
ast
.
defineMacro
({
name
: 'drop-descriptions',
schema
(
node
) {
return 'description' in
node
&&
node
.
description
? { ...
node
,
description
:
undefined
} :
undefined
}, }) export default
defineConfig
({
input
: './petStore.yaml',
output
: {
path
: './src/gen',
clean
: true },
plugins
: [
pluginZod
({
macros
: [
macroDropDescriptions
],
}), ], })

Output example

src/gen/zod/petSchema.ts
typescript
export const petSchema = z.object({
  status: z.enum(['available', 'pending', 'sold']).optional(),
})

Without the macro, that same field carries the spec's prose in a .describe(...) call: z.enum(['available', 'pending', 'sold']).optional().describe('pet status in the store').