Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-suppress-all-warnings-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@asyncapi/cli": patch
---

fix(validate): only suppress warning-severity rules and ignore non-ruleset diagnostic codes in `--suppressAllWarnings`
3 changes: 2 additions & 1 deletion src/domains/services/validation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,12 @@ export class ValidationService extends BaseService {
const allRuleNames = Array.from(
new Set(
diagnostics
.filter((d) => d.severity === DiagnosticSeverity.Warning)
.map((d) => d.code)
.filter((c): c is string => typeof c === 'string'),
),
);
return this.buildCustomParser(allRuleNames);
return this.buildParserWithSpecificWarningsSuppressed(allRuleNames);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions test/integration/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,24 @@ describe('validate', () => {
});
});

describe('validate command with --suppressAllWarnings flag', () => {
test
.stderr()
.stdout()
.command([
'validate',
path.join('test', 'fixtures', 'specification-invalid.yml'),
'--suppressAllWarnings'
])
.it('should suppress warnings while still failing on errors', (ctx, done) => {
expect(ctx.stderr).to.include('have governance issues.');
expect(ctx.stdout).to.include('asyncapi-document-resolved');
expect(ctx.stdout).to.not.include('asyncapi-id');
expect(process.exitCode).to.equal(1);
done();
});
});

describe('with --save-output flag', () => {
beforeEach(() => {
testHelper.createDummyContextFile();
Expand Down
44 changes: 44 additions & 0 deletions test/unit/services/validation.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,50 @@ describe('ValidationService', () => {
expect(result.data?.diagnostics).to.be.an('array');
}
});

it('should suppress only warnings and preserve error diagnostics when suppressAllWarnings is true', async () => {
const specFile = new Specification(invalidAsyncAPI);

const result = await validationService.validateDocument(specFile, {
suppressAllWarnings: true
});

expect(result.success).to.equal(true);
if (result.success) {
expect(result.data?.status).to.equal('invalid');
expect(result.data?.diagnostics?.some((d: any) => d.severity === 0)).to.equal(true);
expect(result.data?.diagnostics?.some((d: any) => d.severity === 1)).to.equal(false);
}
});

it('should not throw on invalid-ref diagnostics when suppressAllWarnings is true', async () => {
const brokenRefSpec = new Specification(JSON.stringify({
asyncapi: '2.6.0',
info: {
title: 'Test Service',
version: '1.0.0'
},
channels: {
'user/signedup': {
subscribe: {
message: {
$ref: './non-existent-file.yaml#/messages/UserSignedUp'
}
}
}
}
}), { filepath: '/tmp/broken-ref-spec.json' });

const result = await validationService.validateDocument(brokenRefSpec, {
suppressAllWarnings: true
});

expect(result.success).to.equal(true);
if (result.success) {
expect(result.data?.status).to.equal('invalid');
expect(result.data?.diagnostics?.some((d: any) => d.code === 'invalid-ref')).to.equal(true);
}
});
});

describe('validateDocument() with external URLs', () => {
Expand Down
Loading