37bed1cd4e
Docs Check / Markdown lint (push) Successful in 1m6s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 1m20s
Build and Push Docker Image / build (push) Successful in 1m35s
CI / Swagger Validation & Coverage (push) Failing after 2m0s
CI / Security audit (push) Successful in 2m6s
Docs Check / Mermaid diagram parse check (push) Successful in 2m20s
CI / Tests & coverage (push) Failing after 2m30s
- Add RAML generation scripts (generate-openapi, downgrade-openapi, simple-raml-converter, package-raml) - Add /api/swagger.json endpoint to server/app.js - Add minimal .spectral.yml ruleset for OpenAPI linting - Add npm scripts for OpenAPI/RAML generation and packaging - Extend CI swagger job with RAML generation steps - Upload raml-package artifact with 14-day retention - Update CHANGELOG.md for v1.7.1
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
// Copyright (c) 2026 Gordon Bolton. MIT License.
|
|
/**
|
|
* Converts OpenAPI 3.0 to RAML 1.0 using AMF (amf-client-js)
|
|
* AMF is the modern replacement for deprecated RAML converters.
|
|
*/
|
|
|
|
const { Main, AMFParser, AMFTransformer } = require('amf-client-js');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const INPUT_FILE = path.join(process.cwd(), 'dist/openapi-30.json');
|
|
const OUTPUT_FILE = path.join(process.cwd(), 'dist/api.raml');
|
|
|
|
async function convertToRaml() {
|
|
if (!fs.existsSync(INPUT_FILE)) {
|
|
throw new Error(`Input file not found: ${INPUT_FILE}`);
|
|
}
|
|
|
|
console.log('Initializing AMF...');
|
|
await Main.init();
|
|
|
|
console.log(`Reading OpenAPI 3.0 spec from ${INPUT_FILE}`);
|
|
const specContent = fs.readFileSync(INPUT_FILE, 'utf-8');
|
|
|
|
console.log('Parsing OpenAPI spec...');
|
|
const parser = new AMFParser();
|
|
const model = await parser.parseStringAsync('file://' + INPUT_FILE, specContent, 'application/json');
|
|
|
|
console.log('Resolving references...');
|
|
const resolvedModel = await AMFTransformer.resolve(model);
|
|
|
|
console.log('Converting to RAML 1.0...');
|
|
const ramlModel = await AMFTransformer.transform(resolvedModel, 'RAML 1.0');
|
|
|
|
console.log('Generating RAML output...');
|
|
const ramlContent = await AMFTransformer.generateString(ramlModel, 'application/yaml');
|
|
|
|
// Clean up the output - AMF sometimes adds extra formatting
|
|
const cleanedRaml = ramlContent
|
|
.replace('#%RAML 1.0\n', '#%RAML 1.0\n\n')
|
|
.replace(/\n{3,}/g, '\n\n');
|
|
|
|
fs.writeFileSync(OUTPUT_FILE, cleanedRaml);
|
|
console.log(`✓ RAML spec written to ${OUTPUT_FILE}`);
|
|
|
|
// Basic validation
|
|
if (!cleanedRaml.includes('#%RAML 1.0')) {
|
|
throw new Error('Generated RAML does not appear to be valid RAML 1.0');
|
|
}
|
|
|
|
console.log('RAML conversion complete');
|
|
}
|
|
|
|
convertToRaml()
|
|
.then(() => {
|
|
process.exit(0);
|
|
})
|
|
.catch((error) => {
|
|
console.error('Failed to convert to RAML:', error);
|
|
process.exit(1);
|
|
});
|