|
| 1 | +--- |
| 2 | +seo: |
| 3 | + title: Lint Overlay with Redocly CLI |
| 4 | + description: Unlock powerful linting capabilities for Overlay documents. Use the Redocly CLI to enforce basic validation, configure rules, or even build custom plugins for Overlay. |
| 5 | +--- |
| 6 | + |
| 7 | +# Lint Overlay with Redocly CLI |
| 8 | + |
| 9 | +[Overlay](https://spec.openapis.org/overlay/latest.html#Overlay-specification) is an open standard from the OpenAPI Initiative for describing a set of changes to be applied or “overlaid” onto an existing OpenAPI description. |
| 10 | +Redocly CLI offers support for checking that your Overlay files are valid. |
| 11 | + |
| 12 | +{% admonition type="info" name="Experimental Overlay support" %} |
| 13 | +This feature is at an early stage, please send us lots of [feedback](https://github.com/redocly/redocly-cli/issues)! |
| 14 | +{% /admonition %} |
| 15 | + |
| 16 | +## Lint an Overlay file |
| 17 | + |
| 18 | +Use your existing Overlay files, or use the Overlay examples in the [Museum API project](https://github.com/Redocly/museum-openapi-example) if you'd prefer to use sample data to try things out. |
| 19 | + |
| 20 | +**Pro-tip:** linting is much more interesting if the file actually does contain problems. |
| 21 | +Be your own chaos monkey and introduce some errors before you proceed! |
| 22 | + |
| 23 | +Lint using a command like the following: |
| 24 | + |
| 25 | +```bash |
| 26 | +redocly lint overlay/museum-api.overlay.yaml |
| 27 | +``` |
| 28 | + |
| 29 | +If the file does not match the specification, the tool shows the details of each error that it finds, like in the following example: |
| 30 | + |
| 31 | +```text |
| 32 | +validating overlay/museum-api.overlay.yaml... |
| 33 | +[1] overlay/museum-api.overlay.yaml:5:3 at #/info/description |
| 34 | +
|
| 35 | +Property `description` is not expected here. |
| 36 | +
|
| 37 | +3 | title: Sample Overlay Configuration |
| 38 | +4 | version: 1.0.0 |
| 39 | +5 | description: "" |
| 40 | +6 | extends: openapi.yaml |
| 41 | +7 | actions: |
| 42 | +
|
| 43 | +Error was generated by the struct rule. |
| 44 | +
|
| 45 | +
|
| 46 | +
|
| 47 | +validating overlay/museum-api.overlay.yaml... |
| 48 | +[1] overlay/museum-api.overlay.yaml:11:3 at #/actions/1/descript |
| 49 | +
|
| 50 | +Property `descript` is not expected here. |
| 51 | +
|
| 52 | +Did you mean: description ? |
| 53 | +
|
| 54 | +10 | - target: $.paths['/museum-hours'] |
| 55 | +11 | descript: "not a valid field(misspelled)" |
| 56 | +12 | remove: true |
| 57 | +
|
| 58 | +Error was generated by the struct rule. |
| 59 | +
|
| 60 | +``` |
| 61 | + |
| 62 | +## Configure the linting rules |
| 63 | + |
| 64 | +Choose from the ready-made rulesets (`minimal`, `recommended` or `recommended-strict`), or go one better and configure the rules that suit your use case. |
| 65 | +There's a full [list of built-in rules for Overlay](../rules/built-in-rules.md#Overlay-rules) to refer to. |
| 66 | + |
| 67 | +Add the rules to `redocly.yaml`, but for Overlay specifications. |
| 68 | +The following example shows configuration for the minimal ruleset with additional rules configuration: |
| 69 | + |
| 70 | +```yaml |
| 71 | +extends: |
| 72 | + - minimal |
| 73 | + |
| 74 | +rules: |
| 75 | + info-contact: warn |
| 76 | +``` |
| 77 | +
|
| 78 | +The configuration shown here gives some good entry-level linting using the `minimal` standard, and warns if info contact information is missing. |
| 79 | + |
| 80 | +## Choose output format |
| 81 | + |
| 82 | +Since Redocly CLI is already a fully-featured lint tool, additional features such as a choice of formats are already included. |
| 83 | + |
| 84 | +Get a report in **Markdown format** with the following command: |
| 85 | + |
| 86 | +```bash |
| 87 | +redocly lint --format=markdown overlay/museum-api.overlay.yaml |
| 88 | +``` |
| 89 | + |
| 90 | +Choose your preferred output format from `codeframe`, `stylish`, `json`, `checkstyle`, `codeclimate`, `github-actions`, `markdown`, or `summary`. |
| 91 | +The [lint command page](../commands/lint.md) has full details of the command's options. |
| 92 | + |
| 93 | +## Add Overlay linting to GitHub Actions |
| 94 | + |
| 95 | +To make sure that your Overlay description remains valid, add linting to your CI (Continuous Integration) setup. |
| 96 | +You can use Redocly CLI with the `github-actions` output format to get annotations directly in your pull request if any validation problems are found. |
| 97 | +The following snippet shows an example of configuring a GitHub action for linting: |
| 98 | + |
| 99 | +```yaml |
| 100 | +name: Validate museum overlay descriptions |
| 101 | +
|
| 102 | +on: [pull_request] |
| 103 | +
|
| 104 | +jobs: |
| 105 | + build: |
| 106 | + runs-on: ubuntu-latest |
| 107 | + steps: |
| 108 | + - name: Checkout |
| 109 | + uses: actions/checkout@v4 |
| 110 | + - name: Set up node |
| 111 | + uses: actions/setup-node@v4 |
| 112 | + - name: Install Redocly CLI |
| 113 | + run: npm install -g @redocly/cli@latest |
| 114 | + - name: Run linting |
| 115 | + run: redocly lint overlay/*yaml --format=github-actions |
| 116 | +``` |
| 117 | + |
| 118 | +With this action in place, the intentional errors I added to the Overlay description are shown as annotations on the pull request: |
| 119 | + |
| 120 | +<!-- TODO: Replace with actual image link --> |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +## Participate in Redocly CLI |
| 125 | + |
| 126 | +Redocly CLI is an open source project, so we invite you to check out the [code on GitHub](https://github.com/Redocly/redocly-cli/), and open issues to report problems or request features. |
0 commit comments