UNPKG

@redocly/respect-core

Version:
59 lines 2.39 kB
import { bold, red } from 'colorette'; import { getTotals, formatProblems, lint, bundle, createConfig, } from '@redocly/openapi-core'; import * as path from 'node:path'; import { printConfigLintTotals } from '../logger-output/helpers.js'; import { isTestFile } from '../../utils/file.js'; export async function bundleArazzo(options) { const { filePath, base, externalRefResolver, collectSpecData, version, skipLint = false, } = options; let lintProblems = []; const fileName = path.basename(filePath); if (!fileName) { throw new Error('Invalid file name'); } const config = await createConfig({ extends: ['recommended-strict'], arazzo1Rules: { 'no-criteria-xpath': 'error', 'respect-supported-versions': 'warn', 'no-x-security-scheme-name-without-openapi': 'error', 'x-security-scheme-required-values': 'error', 'x-security-scheme-name-reference': 'error', 'no-x-security-both-scheme-and-scheme-name': 'error', }, }); if (!skipLint) { lintProblems = await lint({ ref: filePath, config, externalRefResolver, }); if (lintProblems.length) { const fileTotals = getTotals(lintProblems); formatProblems(lintProblems, { totals: fileTotals, version, }); printConfigLintTotals(fileTotals, options.logger); } } const bundledDocument = await bundle({ base, ref: filePath, config, dereference: true, externalRefResolver, }); if (!bundledDocument) { throw new Error(`Could not find source description file '${fileName}'.`); } if (!isTestFile(fileName, bundledDocument.bundle.parsed)) { throw new Error(`No test files found. File ${fileName} does not follows naming pattern "*.[yaml | yml | json]" or have not valid "Arazzo" description.`); } collectSpecData?.(bundledDocument.bundle.parsed || {}); const errorLintProblems = lintProblems.filter((problem) => problem.severity === 'error'); if (errorLintProblems.length) { throw new Error(`${red('Found errors in Arazzo description')} ${bold(fileName)}`); } return bundledDocument.bundle.parsed || {}; } //# sourceMappingURL=get-test-description-from-file.js.map