// Copyright (c) 2026 Gordon Bolton. MIT License. /** * Downgrades OpenAPI 3.1.0 to 3.0.0 for compatibility with RAML converters. * OpenAPI 3.1 has limited support in existing RAML conversion tools. */ const fs = require('fs'); const path = require('path'); const INPUT_FILE = path.join(process.cwd(), 'dist/openapi-merged.json'); const OUTPUT_FILE = path.join(process.cwd(), 'dist/openapi-30.json'); function downgradeOpenApi30(spec) { // Change version from 3.1.0 to 3.0.0 spec.openapi = '3.0.0'; // OpenAPI 3.1 uses "type" with array for nullable, 3.0 uses nullable: true // This is a simple pass-through for now - complex schemas may need more handling // For this spec, most nullable fields are already using 3.0-compatible syntax return spec; } async function main() { if (!fs.existsSync(INPUT_FILE)) { throw new Error(`Input file not found: ${INPUT_FILE}`); } console.log(`Reading OpenAPI 3.1 spec from ${INPUT_FILE}`); const spec = JSON.parse(fs.readFileSync(INPUT_FILE, 'utf-8')); console.log('Downgrading to OpenAPI 3.0.0...'); const downgraded = downgradeOpenApi30(spec); fs.writeFileSync(OUTPUT_FILE, JSON.stringify(downgraded, null, 2)); console.log(`✓ Downgraded spec written to ${OUTPUT_FILE}`); } main() .then(() => { console.log('Downgrade complete'); process.exit(0); }) .catch((error) => { console.error('Failed to downgrade spec:', error); process.exit(1); });