Skip to content

[BUG] validate --suppressAllWarnings disables Error rules (passing invalid specs) and crashes on invalid-ref #2340

Open

Description

@hoanle0126

Describe the bug.

In ValidationService.buildParserWithAllWarningsSuppressed (src/domains/services/validation.service.ts#L327-L341), --suppressAllWarnings collects d.code from every diagnostic returned by this.parser.validate(...) without filtering for warning severity (d.severity === DiagnosticSeverity.Warning), and passes all of them directly to this.buildCustomParser(allRuleNames):

  private async buildParserWithAllWarningsSuppressed(
    specFile: Specification
  ): Promise<Parser> {
    const diagnostics = await this.parser.validate(specFile.text(), {
      source: specFile.getSource(),
    });
    const allRuleNames = Array.from(
      new Set(
        diagnostics
          .map((d) => d.code)
          .filter((c): c is string => typeof c === 'string'),
      ),
    );
    return this.buildCustomParser(allRuleNames);
  }

This causes two distinct failures when asyncapi validate <spec> --suppressAllWarnings (or validationService.validateDocument(spec, { suppressAllWarnings: true })) is run on an invalid specification:

  1. Schema and resolution Error rules are silently turned 'off', causing invalid documents to pass validation with exit code 0:
    When a document has Error-severity Spectral rules (such as asyncapi2-schemas, asyncapi3-schemas, or asyncapi-document-resolved in test/fixtures/specification-invalid.yml), buildParserWithAllWarningsSuppressed turns those error rules 'off'. Re-parsing then returns status: 'valid' and diagnostics: [] (File ... is valid!) with exit code 0.
  2. Documents with unresolvable $refs crash with Cannot extend non-existing rule: "invalid-ref":
    When a document triggers a parser diagnostic whose code is not an extendable Spectral rule in the base ruleset (such as invalid-ref), this.buildCustomParser(allRuleNames) throws Error: Cannot extend non-existing rule: "invalid-ref" instead of filtering via buildParserWithSpecificWarningsSuppressed.

Expected behavior

  • --suppressAllWarnings should only suppress rules with d.severity === DiagnosticSeverity.Warning (DiagnosticSeverity.Error, Information, and Hint diagnostics must not have their rules disabled).
  • buildParserWithAllWarningsSuppressed should delegate to this.buildParserWithSpecificWarningsSuppressed(warningRuleNames) (or return this.parser when warningRuleNames.length === 0) so any non-ruleset diagnostic code never throws Cannot extend non-existing rule.

Screenshots

Not applicable.

How to Reproduce

From the root of asyncapi/cli:

npx ts-node -T -r tsconfig-paths/register -e '
import { ValidationService } from "./src/domains/services/validation.service";
import { load, Specification } from "./src/domains/models/SpecificationFile";

(async () => {
  const svc = new ValidationService();

  // 1. Invalid spec (missing required fields / unresolved errors) passes as "valid"
  const invalidSpec = await load("./test/fixtures/specification-invalid.yml");
  console.log("1. specification-invalid.yml without flag:", (await svc.validateDocument(invalidSpec)).data?.status);
  // -> "invalid"
  console.log("2. specification-invalid.yml with suppressAllWarnings:", (await svc.validateDocument(invalidSpec, { suppressAllWarnings: true })).data?.status);
  // -> "valid" (0 diagnostics!)

  // 2. Broken $ref crashes with "Cannot extend non-existing rule: \"invalid-ref\""
  const brokenRefSpec = new Specification(JSON.stringify({
    asyncapi: "2.6.0",
    info: { title: "Test", version: "1.0.0" },
    channels: {
      "user/signedup": {
        subscribe: { message: { $ref: "./non-existent.yaml#/messages/UserSignedUp" } }
      }
    }
  }), { filePath: "/tmp/spec.json" });
  console.log("3. brokenRefSpec with suppressAllWarnings:", await svc.validateDocument(brokenRefSpec, { suppressAllWarnings: true }));
  // -> { success: false, error: "Cannot extend non-existing rule: \"invalid-ref\"" }
})();
'

🖥️ Device Information [optional]

  • Operating System (OS): Linux
  • Node.js: v24.11+
  • @asyncapi/cli: current master (v6.2.3)

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

Activity

  1. github-actions commented on Nov 7, 2026

    @github-actions
    Contributor

    Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
    Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

  2. hoanle0126 commented on Nov 7, 2026

    @hoanle0126
    Author

    I have opened #2341 with a fix and regression tests for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions