Skip to content

Show component/schema name in finding locations, not just path:line #399

Description

@hdamker

Problem description

Findings for rules like S-211 (unused component) and S-313 (string missing
format/pattern/enum) render only path:line in the Step Summary, and the underlying Spectral
message text for both rules is a static string with no location detail:

  • S-211: "Potentially unused component has been detected."
  • S-313: "Schema of type string should specify a format, pattern, enum, or const."

Reviewers have to open the spec at that line to find out which schema/component a finding is
about, which is painful on larger specs.

Possible evolution

spectral_adapter.py already captures a schema_path (dot-joined JSONPath) for every Spectral
finding; format_finding_location() in validation/output/formatting.py just doesn't read it.
Extend it: when schema_path matches components.(schemas|parameters|responses|requestBodies|headers).<name>,
append (<name>) to the rendered location, e.g.
code/API_definitions/quality-on-demand.yaml:342 (QosProfile). This applies uniformly to any
Spectral-engine finding whose schema_path resolves to a named component, not only S-211/S-313.
When schema_path doesn't resolve to a named component (e.g. an inline string schema under
paths.*, which S-313's document-wide scan can also hit), leave the location unchanged.

Alternative solution

Show the full schema_path instead of just the trailing component name — considered and
rejected: it gets long for deeply nested properties, and the component name alone is what's
needed to find the schema in the spec.

Additional context

Regression fixtures (regression-expected-schema.yaml) match findings on (rule_id, path, level) only — line numbers and messages are explicitly excluded from the match key — so this is
a rendering-only change with no regression-fixture impact.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions