Is there a native enum (z.nativeEnum) support for zod pluggin? #3871
-
|
Hello, I am using the By default, when encountering enums in the OpenAPI specification, the Zod artifacts are generated in array-based union format: export const zStatus = z.enum(['active', 'inactive', 'pending']);My question is: // What I am trying to achieve
export enum Status {
Active = 'active',
Inactive = 'inactive',
Pending = 'pending'
}
export const zStatus = z.nativeEnum(Status); // or `z.enum(Status)` for zod v4If this feature does not exist yet, would you accept a PR adding a configuration option (such as enums: 'native') inside the zod plugin configuration block? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
|
Hi @volkankalin! I'm Dosu and I’m helping the openapi-ts team. There's currently no built-in configuration flag (like However, you can customize enum generation using the Resolvers API via the {
name: 'zod',
'~resolvers': {
enum(ctx) {
// Custom logic to generate z.nativeEnum() instead
}
}
}This gives you full control over how enums are compiled, though wiring it up to reference a separately generated TypeScript As for a PR — that's a question for the maintainers, but the resolvers escape hatch might unblock you in the meantime. To reply, just mention @dosu. Docs are dead. Just use Dosu. |
Beta Was this translation helpful? Give feedback.
-
|
@volkankalin Hey! What @dosu said, I'm quite certain you'd be able to work around it today. Also open to a pull request if you want! |
Beta Was this translation helpful? Give feedback.
@volkankalin you can follow along on #3884. Once merged, it will be available at
@next. There are too many concepts to explain before you'd be able to contribute this yourself so I tackled it. It's mainly due to the aforementioned design deficiencies – if it was a matter of extending existing patterns, I would've let you do it. In the meantime, I'd love if you have any other feedback