Skip to main content

Zod

Installโ€‹

npm install @basketry/zod

Basic Usageโ€‹

basketry.config.json
{
"source": "petstore.json",
"parser": "@basketry/openapi-3",
"generators": ["@basketry/zod"],
"output": "src"
}

File Structureโ€‹

This generator will create Zod schemas for all the API schemas defined in the source file.

By default, the file will be nested within a directory named after the API major version. This behavior can be disabled by using the includeVersion option from the Typescript Generator.

my-project/
โ”œโ”€โ”€ node_modules/
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ v1/ <-- generated
โ”‚ โ”‚ โ””โ”€โ”€ schemas.ts <-- generated
โ”‚ โ”œโ”€โ”€ index.ts
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ basketry.config.json
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ petstore.json
โ””โ”€โ”€ README.md

Optionsโ€‹

This generator depends on the @basketry/typescript generator and all of their applied options will also apply to files emitted by this generator.

See:

The @basketry/zod generator does not accept any of its own options.

Dependenciesโ€‹

The generated file contains code that depends on the zod package that is not included by default. You will need to install it separately.

npm install zod