-
Notifications
You must be signed in to change notification settings - Fork 93
Generate Zod v4 metadata from TypeScript JSDoc comments #359
Copy link
Copy link
Open
Description
Feature description
Add support for Zod v4 registries and JSDoc annotations to generate schema metadata (descriptions and examples).
With Zod v4's new registry system and the .metadata() API, it would be valuable to automatically generate schema metadata from JSDoc comments. This would allow developers to maintain a single source of truth in their TypeScript types while automatically generating Zod schemas with rich metadata for documentation, validation error messages, and OpenAPI generation.
Input
/**
* User information
*/
interface User {
/**
* The user's unique identifier
* @example "123e4567-e89b-12d3-a456-426614174000"
*/
id: string;
/**
* The user's email address
* @example "user@example.com"
*/
email: string;
/**
* The user's age in years
* @example 25
*/
age: number;
/**
* User's role in the system
* @example "admin"
*/
role: "admin" | "user" | "guest";
}Output
import { z } from "zod";
export const userSchema = z.object({
id: z.string().metadata({
description: "The user's unique identifier",
examples: ["123e4567-e89b-12d3-a456-426614174000"]
}),
email: z.string().metadata({
description: "The user's email address",
examples: ["user@example.com"]
}),
age: z.number().metadata({
description: "The user's age in years",
examples: [25]
}),
role: z.enum(["admin", "user", "guest"]).metadata({
description: "User's role in the system",
examples: ["admin"]
})
}).metadata({
description: "User information"
});Additional Context
- Zod v4 metadata API: https://zod.dev/metadata
- This would be particularly useful for generating OpenAPI schemas or providing better validation error messages
- Multiple
@exampletags should result in an array of examples - Consider supporting other JSDoc tags like
@deprecated,@see, etc.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels