Skip to content

feat(core): allow overrides to target formats without files - #3081

Open
SahilRajputdotexe wants to merge 1 commit into
stoplightio:developfrom
SahilRajputdotexe:feat/format-only-overrides
Open

SahilRajputdotexe wants to merge 1 commit into
stoplightio:developfrom
SahilRajputdotexe:feat/format-only-overrides

Conversation

@SahilRajputdotexe

Copy link
Copy Markdown

Fixes #2446.

This lets an override select documents by formats instead of, or together with, files. The docs already list formats as an override target, but the schema required files and the format list was never looked at when picking an override.

An override now has to state files, formats, or both, and it applies only to documents that match every selector it states. A document whose format cannot be detected is not picked by an override that states formats, but still matches overrides that only state files. Formats that are only mentioned inside an override are used when detecting a document's format. To make that work, format detection now runs before the overrides are resolved. A document with no source is only an error when some override states files. Overrides that use JSON Pointers can state formats too.

extends: [spectral:oas, spectral:asyncapi]
overrides:
  - formats: [oas3_0]
    rules:
      operation-description: info

Only OpenAPI 3.0 documents get the changed severity. Other documents linted in the same run are not affected.

I added tests for the schema, Ruleset#fromSource and linting through Spectral#run. I also updated docs/guides/4d-overrides.md, whose example was not valid YAML.

Checklist

  • Tests added / updated
  • Docs added / updated

Does this PR introduce a breaking change?

  • Yes
  • No

An override may now state formats instead of files, or both, and it is
applied only to documents that match every selector it states. Format
detection runs before overrides are resolved, so formats that are only
mentioned inside an override still take part in detection.

Overrides that use JSON Pointers can state formats as well.

Signed-off-by: Sahil Rajput <90515841+SahilRajputdotexe@users.noreply.github.com>
@SahilRajputdotexe
SahilRajputdotexe requested a review from a team as a code owner October 2, 2026 06:20
@micryc micryc self-assigned this Oct 2, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cannot override based on formats

2 participants