Skip to content

Commit 3010adf

Browse files
author
alpsla
committed
Session 92: Fix Spectral missing default ruleset - use spectral:oas
1 parent eb004c0 commit 3010adf

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

packages/agents/src/two-branch/tools/universal/api-schema-scanner.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,22 @@ async function runSpectralOnFile(
259259

260260
try {
261261
// Build spectral command
262-
const rulesetArgs = config.rulesets?.map(r => `--ruleset ${r}`).join(' ') || '';
262+
// SESSION 92 FIX: Use default spectral:oas ruleset if no custom rulesets provided
263+
// Without a ruleset, Spectral fails with "No ruleset has been found"
264+
let rulesetArgs = '';
265+
if (config.rulesets && config.rulesets.length > 0) {
266+
rulesetArgs = config.rulesets.map(r => `--ruleset ${r}`).join(' ');
267+
} else {
268+
// Create a temporary ruleset file that extends the built-in OAS rules
269+
const tempRulesetPath = path.join(path.dirname(filePath), '.spectral-temp.yml');
270+
const tempRulesetContent = 'extends: spectral:oas\n';
271+
fs.writeFileSync(tempRulesetPath, tempRulesetContent);
272+
rulesetArgs = `--ruleset "${tempRulesetPath}"`;
273+
// Clean up temp file after use (in finally block would be better but keeping it simple)
274+
setTimeout(() => {
275+
try { fs.unlinkSync(tempRulesetPath); } catch { /* ignore */ }
276+
}, 5000);
277+
}
263278
const cmd = `spectral lint "${filePath}" --format json ${rulesetArgs}`;
264279

265280
const { stdout, stderr } = await execAsync(cmd, {

0 commit comments

Comments
 (0)