stoplightio / spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI (v3.1, v3.0, and v2.0), Arazzo v1.0, as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.51k stars 240 forks source link

Proposal: Option to exclude JSONPaths for the rules definition #2414

Open pavelkornev opened 1 year ago

pavelkornev commented 1 year ago

User story. As a user of Spectral it would be much flexible for me to have an opportunity to exclude certain paths from the given paths without overcomplicating JSONPaths or without defining a custom function for this purpose.

Describe the solution you'd like

In the following example the rule checks all description or title properties, but excluding examples objects because same-called properties are not part of the OpenAPI documents definition itself, but rather the example of the actual content payload which have their own constrains and requirements/guidelines:

'no-script-tags-in-markdown': {
  description: 'Markdown descriptions must not have "<script>" tags.',
  recommended: true,
  given: '$..[description,title]',
  exclude: '$..examples', // <--- easy way to exclude `title` and `description` inside these objects
  then: {
    function: pattern,
    functionOptions: {
      notMatch: '<script',
    },
  },
},