generate-zod.ts•937 B
#!/usr/bin/env tsx
import { generateZodClientFromOpenAPI } from 'openapi-zod-client'
import { readFileSync, writeFileSync } from 'fs'
import { join } from 'path'
const openApiDoc = JSON.parse(
readFileSync(join(process.cwd(), 'shortcut-openapi.json'), 'utf-8')
)
async function generateZodSchemas() {
console.log('Generating Zod schemas from OpenAPI spec...')
const zodSchemas = await generateZodClientFromOpenAPI({
openApiDoc,
distPath: '',
options: {
withAlias: true,
shouldExportAllSchemas: true,
isMainResponseStatus: (status) => status === '200' || status === '201',
}
})
// Write the generated schemas
const outputPath = join(process.cwd(), 'src/generated/zod-schemas.ts')
writeFileSync(outputPath, zodSchemas)
console.log(`✓ Generated Zod schemas at ${outputPath}`)
}
generateZodSchemas().catch(console.error)