Replies: 2 comments 5 replies
|
V4 of Kubb does not have support for this but we are planning v5 that will make it easier to do overrides. But to make that work, we need to refactor our generators. |
|
In v5 this is now possible without copying any plugin code. Every code-producing plugin ( import { pluginZod } from '@kubb/plugin-zod'
import { pluginFaker } from '@kubb/plugin-faker'
pluginZod({
printer: {
nodes: {
datetime: () => 'z.string().datetime()', // default: z.iso.datetime()
date: () => 'z.string().date()', // default: z.iso.date()
},
},
}),
pluginFaker({
printer: {
nodes: {
datetime: () => 'faker.date.past().toISOString()', // default: faker.date.anytime().toISOString()
},
},
}),The override keys are the schema types: Verified on
Types you don't override keep their built-in handlers. For zod, with |
Uh oh!
There was an error while loading. Please reload this page.
Currently, Kubb's output is not so easily overridable when custom code is required. Whilst it's possible to create new generators, if one wants to keep the bulk of the existing plugin functionality, the code must be copied and adjusted (unless there's another method of which I'm unaware).
For example, in the Zod plugin, it would be useful to be able to override the
datetimekeyword to return something other thanz.iso, and in the Faker plugin, something other thanfaker.date.The
mapperoption comes close, however, that only works on known keys rather than as a global override for all keys of a type.All reactions