redocly-cli: Ignore errors settings

I’m using OAS3.0.3 and heavily using JSON Schema defined external references. Each of these files indicates the $schema keyword and this is not supported in 3.0.x. My linting report is showing me over 90 thousand errors for $schema is not expected here. How can I add a specific output message to the ignore list rather than the entire “spec” error. I don’t want to ignore all spec errors, only this particular one.

2:3     error    spec  Property `$schema` is not expected here.

 Validation failed with 91051 errors and 705 warnings.

This is my ignore file but it’s not picking up the ignore request. My intention is to lint an entire folder with the * and I want to ignore all occurrences in any folder

# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.
# See https://redoc.ly/docs/cli/ for more information.
api-library-releases/*:
  spec:
    - '#/$schema'

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (13 by maintainers)

Most upvoted comments

I’ve given this a go since I had a similar scenario. Here is the code that I’ve used.

module.exports = {
  id: 'extend-id-and-schema',
  typeExtension: {
    oas3(types) {
      return {
        ...types,
        Schema: {
          ...types.Schema,
          properties: {
            ...types.Schema.properties,
            $id: { type: 'string' },
            $schema: { type: 'string' }
          }
        }
      };
    },
  }
};

which I then added to my .redocly.yaml

plugins: 
  -  src/schemata/plugins/extend-id-and-schema.js

Bonus content. I’ve also added an example below to depict how one would make $id and $schema required in your Operation > 200 only Responses > Schema

apis:
  main@v1:
    rules:
      assert/required-id-and-schema:
        where:
          - subject: 
              type: Operation
              property: operationId
            assertions: 
              pattern: ^((?!(smoke|health)).)*$ # this are some internal endpoints that I excluded 
          - subject:
              type: Response
              filterInParentKeys:
                - '200'
            assertions: 
              defined: true
        subject: 
          type: Schema
        assertions:
          defined: true
          required: 
            - $id
            - $schema
        message: Must have $id and $schema in Schema properties
        severity: error

Hope that helps someone 😃

@bandantonio it would be great to turn this into a guide.