zod-meta-parser
is a utility that extracts metadata descriptions from Zod schemas into a structured format. This is particularly useful for generating documentation or for other meta-programming purposes.
import { z } from "zod"
import { zodMetaParser } from "zod-meta-parser"
const schema = z.object({
id: z.number(), // no description
email: z.string().describe(JSON.stringify({ unique: true })),
image: z
.string()
.optional()
.describe(JSON.stringify({ s3: true })),
createdAt: z.date().describe("Read-only field"),
}),
console.log(zodMetaParser(schema))
{
"email": {
"_meta": {
"unique": true
}
},
"image": {
"_meta": {
"s3": true
}
},
"createdAt": {
"_meta": "Read-only field"
}
}
You can install the package via npm:
npm install zod-meta-parser
or via bun (recommended):
bun add zod-meta-parser
- Extracts metadata descriptions from Zod schemas.
- Supports nested objects and various Zod types.
- Provides a structured output format for easy consumption.
The zodMetaParser
function currently does not accept any additional options. All metadata extraction is done based on the structure and descriptions provided in the Zod schema.
- The
zodToJsonSchema
library used internally might not handle all Zod types perfectly, such assymbol
. Custom handling is added for types not supported natively. - Ensure all fields you want metadata for are described using the
.describe()
method in Zod.
This package follows semantic versioning. New features and bug fixes will be released as minor or patch updates, while breaking changes will be released as major updates.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License - see the LICENSE file for details.
If you enjoy this package, consider sponsoring the project on my GitHub Sponsors page. Your support is greatly appreciated!
Feel free to adjust the links and other details as per your project specifics.