Skip to content

fix: implement missing diagnostics-format options in validate command (#2007)#2070

Closed
chengyixu wants to merge 2 commits intoasyncapi:masterfrom
chengyixu:fix/diagnostics-format-missing-formatters-2007
Closed

fix: implement missing diagnostics-format options in validate command (#2007)#2070
chengyixu wants to merge 2 commits intoasyncapi:masterfrom
chengyixu:fix/diagnostics-format-missing-formatters-2007

Conversation

@chengyixu
Copy link

Summary

Fixes #2007

The validate command's --diagnostics-format flag advertises 12 format options in its --help output (github-actions, sarif, code-climate, gitlab, markdown), but these 5 formats were silently falling through to the default case in formatDiagnosticsOutput(), producing stylish output regardless of what the user specified.

Root Cause

formatDiagnosticsOutput() in validation.service.ts only handled 7 of the 12 formats in its switch statement. The other 5 fell to default: return stylish(...). Additionally, DiagnosticsFormat type and formatExtensions map did not include the missing formats.

Changes

  • src/domains/services/validation.service.ts:

    • Import codeClimate, githubActions, sarif, markdown from @stoplight/spectral-formatters
    • Add case 'github-actions', case 'sarif', case 'code-climate', case 'gitlab', case 'markdown' to the formatDiagnosticsOutput() switch
    • Add file extensions for new formats in formatExtensions (github-actions: .txt, sarif: .json, code-climate: .json, gitlab: .json, markdown: .md)
    • Add new formats to validFormats list
  • src/interfaces/index.ts:

    • Extend DiagnosticsFormat type union with the 5 missing formats

Notes

  • gitlab format is not a distinct function in @stoplight/spectral-formatters — GitLab CI natively ingests Code Climate JSON, so gitlab delegates to codeClimate
  • All 4 missing formatters (githubActions, sarif, codeClimate, markdown) are already present and exported from @stoplight/spectral-formatters (already a dependency) — no new dependencies added

Test plan

  • asyncapi validate spec.yaml --diagnostics-format=github-actions produces GitHub Actions annotation format
  • asyncapi validate spec.yaml --diagnostics-format=sarif produces SARIF JSON output
  • asyncapi validate spec.yaml --diagnostics-format=code-climate produces Code Climate JSON
  • asyncapi validate spec.yaml --diagnostics-format=gitlab produces Code Climate JSON (GitLab format)
  • asyncapi validate spec.yaml --diagnostics-format=markdown produces Markdown output
  • All existing format options continue to work (no regressions)

…asyncapi#2007)

The validate command advertised 12 --diagnostics-format options in its help
text (github-actions, sarif, code-climate, gitlab, markdown) but these formats
were not handled in formatDiagnosticsOutput() and fell through to the default
stylish formatter, producing unexpected output.

Changes:
- Import codeClimate, githubActions, sarif, markdown from @stoplight/spectral-formatters
- Add github-actions, sarif, code-climate, gitlab, markdown cases to the switch
  statement in formatDiagnosticsOutput()
- Add the missing formats to DiagnosticsFormat type in interfaces/index.ts
- Add file extensions for new formats in formatExtensions map (.txt, .json, .md)
- Add formats to the validFormats list

Note: gitlab format is not a distinct formatter in @stoplight/spectral-formatters;
GitLab CI natively consumes Code Climate JSON, so gitlab falls back to codeClimate.

Fixes asyncapi#2007
@changeset-bot
Copy link

changeset-bot bot commented Mar 21, 2026

🦋 Changeset detected

Latest commit: 2b696c1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sonarqubecloud
Copy link

@github-project-automation github-project-automation bot moved this from To Triage to Done in CLI - Kanban Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] The validate subcommand does not fully support the --diagnostics-format options despite its help message

2 participants