File size: 651 Bytes
048b1e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { readFileSync, writeFileSync } from 'node:fs'

/**
 * Post-generation workaround for orval's zod output: object-literal defaults
 * are emitted without `as const`, so property values widen to `string` and
 * fail Zod's `.default()` signature when the schema expects a literal type.
 * Remove this script once orval emits `as const` for object-literal defaults.
 * See: https://github.com/orval-labs/orval/issues/3244
 */
const file = new URL('../src/zod/index.ts', import.meta.url)
const src = readFileSync(file, 'utf8')
const fixed = src.replace(
  /(^export const \w+Default =\s*\{[^{}]*\})/gm,
  '$1 as const',
)
writeFileSync(file, fixed)