A utility function to convert Zod schemas to Markdown documentation.
Install the package using npm:
npm install zod-to-markdownImport the zodSchemaToMarkdown function from the package:
import { zodSchemaToMarkdown } from 'zod-to-markdown';Use the function to convert a Zod schema to Markdown:
import { z } from 'zod';
const mySchema = z.object({
name: z.string(),
age: z.number(),
email: z.string().email(),
});
const markdown = zodSchemaToMarkdown(mySchema);
console.log(markdown);Output:
- name: String
- age: Number
- email: String (email)The zodSchemaToMarkdown function takes a Zod schema as input and returns a string representing the schema in Markdown format.
The following Zod types are supported by zodSchemaToMarkdown:
ZodObjectZodArrayZodStringZodNumberZodEnumZodUnionZodBooleanZodDefaultZodOptionalZodNullable
The zodSchemaToMarkdown function accepts an optional second parameter indentLevel to specify the initial indentation level. By default, it is set to 0.
const markdown = zodSchemaToMarkdown(mySchema, 2);Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository.
This package is open source and available under the MIT License.