support-litestar-openapi-tuples.mjs
1 import { readFileSync, writeFileSync, lstatSync } from 'node:fs' 2 3 const filePath = process.argv[2] 4 5 if (!lstatSync(filePath).isFile()) { 6 throw `${filePath} is not a file` 7 } 8 9 const openapiSchema = readFileSync(filePath, { encoding: 'utf-8' }) 10 11 const openapiSchemaWithoutStrangeTuples = openapiSchema 12 .replace(/\n^\s*default: !!python\/tuple.*(\n\s*-.+)*/gm, '') 13 .replace(/- default: !!python\/tuple(.*)(\n\s*-.+)*/gm, "- default: '!!python/tuple$1'") 14 15 writeFileSync(filePath, openapiSchemaWithoutStrangeTuples) 16 17 console.log('transform tuples done!'.toUpperCase())