openapi-minifier
Version:
A CLI tool by Treblle tp minify OpenAPI V3 Specs by removing redundant information not relevant to AI Agents and LLMs.
30 lines • 1.05 kB
JavaScript
import SwaggerParser from '@apidevtools/swagger-parser';
import yaml from 'js-yaml';
export async function validateOpenAPI(content, format) {
try {
let spec;
if (format === 'yaml') {
spec = yaml.load(content);
}
else {
spec = JSON.parse(content);
}
await SwaggerParser.validate(spec);
if (typeof spec === 'object' && spec !== null && 'openapi' in spec) {
const version = spec.openapi;
if (!version || !version.startsWith('3.')) {
throw new Error(`Unsupported OpenAPI version: ${version}. Only OpenAPI v3.x is supported.`);
}
}
else {
throw new Error('Invalid OpenAPI specification: missing "openapi" field');
}
}
catch (error) {
if (error instanceof Error) {
throw new Error(`OpenAPI validation failed: ${error.message}`);
}
throw new Error('OpenAPI validation failed: Unknown error');
}
}
//# sourceMappingURL=validator.js.map