-
Notifications
You must be signed in to change notification settings - Fork 194
docs: add Overlay linting guides #2470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeremyfiel
wants to merge
1
commit into
Redocly:main
Choose a base branch
from
jeremyfiel:feat/overlay-linting-guides
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+480
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@redocly/cli": patch | ||
| "@redocly/openapi-core": patch | ||
| --- | ||
|
|
||
| Add Overlay linting guides. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| --- | ||
| seo: | ||
| title: Lint Overlay with Redocly CLI | ||
| 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. | ||
| --- | ||
|
|
||
| # Lint Overlay with Redocly CLI | ||
|
|
||
| [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. | ||
| Redocly CLI offers support for checking that your Overlay files are valid. | ||
|
|
||
| {% admonition type="info" name="Experimental Overlay support" %} | ||
| This feature is at an early stage, please send us lots of [feedback](https://github.com/redocly/redocly-cli/issues)! | ||
| {% /admonition %} | ||
|
|
||
| ## Lint an Overlay file | ||
|
|
||
| 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. | ||
|
|
||
| **Pro-tip:** linting is much more interesting if the file actually does contain problems. | ||
| Be your own chaos monkey and introduce some errors before you proceed! | ||
|
|
||
| Lint using a command like the following: | ||
|
|
||
| ```bash | ||
| redocly lint overlay/museum-api.overlay.yaml | ||
| ``` | ||
|
|
||
| If the file does not match the specification, the tool shows the details of each error that it finds, like in the following example: | ||
|
|
||
| ```text | ||
| validating overlay/museum-api.overlay.yaml... | ||
| [1] overlay/museum-api.overlay.yaml:5:3 at #/info/description | ||
|
|
||
| Property `description` is not expected here. | ||
|
|
||
| 3 | title: Sample Overlay Configuration | ||
| 4 | version: 1.0.0 | ||
| 5 | description: "" | ||
| 6 | extends: openapi.yaml | ||
| 7 | actions: | ||
|
|
||
| Error was generated by the struct rule. | ||
|
|
||
|
|
||
|
|
||
| validating overlay/museum-api.overlay.yaml... | ||
| [1] overlay/museum-api.overlay.yaml:11:3 at #/actions/1/descript | ||
|
|
||
| Property `descript` is not expected here. | ||
|
|
||
| Did you mean: description ? | ||
|
|
||
| 10 | - target: $.paths['/museum-hours'] | ||
| 11 | descript: "not a valid field(misspelled)" | ||
| 12 | remove: true | ||
|
|
||
| Error was generated by the struct rule. | ||
|
|
||
| ``` | ||
|
|
||
| ## Configure the linting rules | ||
|
|
||
| Choose from the ready-made rulesets (`minimal`, `recommended` or `recommended-strict`), or go one better and configure the rules that suit your use case. | ||
| There's a full [list of built-in rules for Overlay](../rules/built-in-rules.md#Overlay-rules) to refer to. | ||
|
|
||
| Add the rules to `redocly.yaml`, but for Overlay specifications. | ||
| The following example shows configuration for the minimal ruleset with additional rules configuration: | ||
|
|
||
| ```yaml | ||
| extends: | ||
| - minimal | ||
|
|
||
| rules: | ||
| info-contact: warn | ||
| ``` | ||
|
|
||
| The configuration shown here gives some good entry-level linting using the `minimal` standard, and warns if info contact information is missing. | ||
|
|
||
| ## Choose output format | ||
|
|
||
| Since Redocly CLI is already a fully-featured lint tool, additional features such as a choice of formats are already included. | ||
|
|
||
| Get a report in **Markdown format** with the following command: | ||
|
|
||
| ```bash | ||
| redocly lint --format=markdown overlay/museum-api.overlay.yaml | ||
| ``` | ||
|
|
||
| Choose your preferred output format from `codeframe`, `stylish`, `json`, `checkstyle`, `codeclimate`, `github-actions`, `markdown`, or `summary`. | ||
| The [lint command page](../commands/lint.md) has full details of the command's options. | ||
|
|
||
| ## Add Overlay linting to GitHub Actions | ||
|
|
||
| To make sure that your Overlay description remains valid, add linting to your CI (Continuous Integration) setup. | ||
| 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. | ||
| The following snippet shows an example of configuring a GitHub action for linting: | ||
|
|
||
| ```yaml | ||
| name: Validate museum overlay descriptions | ||
|
|
||
| on: [pull_request] | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Set up node | ||
| uses: actions/setup-node@v4 | ||
| - name: Install Redocly CLI | ||
| run: npm install -g @redocly/cli@latest | ||
| - name: Run linting | ||
| run: redocly lint overlay/*yaml --format=github-actions | ||
| ``` | ||
|
|
||
| With this action in place, the intentional errors I added to the Overlay description are shown as annotations on the pull request: | ||
|
|
||
| <!-- TODO: Replace with actual image link --> | ||
|
|
||
|  | ||
|
|
||
| ## Participate in Redocly CLI | ||
|
|
||
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| slug: /docs/cli/v1/rules/overlay/info-contact | ||
| --- | ||
|
|
||
| # info-contact | ||
|
|
||
| Requires the `Contact` info object defined in your API. | ||
|
|
||
| | Overlay | Compatibility | | ||
| | ------- | ------------- | | ||
| | 1.0 | ✅ | | ||
|
|
||
| ```mermaid | ||
| flowchart TD | ||
|
|
||
| Root ==> Info --> Contact | ||
|
|
||
| style Contact fill:#codaf9,stroke:#0044d4,stroke-width:5px | ||
| ``` | ||
|
|
||
| ## API design principles | ||
|
|
||
| When it comes to APIs, we generally want more consumers. | ||
| If they need help to purchase, integrate, or troubleshoot, your contact info should be front and center. | ||
|
|
||
| ## Configuration | ||
|
|
||
| | Option | Type | Description | | ||
| | -------- | ------ | ------------------------------------------------------- | | ||
| | severity | string | Possible values: `off`, `warn`, `error`. Default `off`. | | ||
|
|
||
| An example configuration: | ||
|
|
||
| ```yaml | ||
| rules: | ||
| info-contact: warn | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| Given this configuration: | ||
|
|
||
| ```yaml | ||
| rules: | ||
| info-contact: error | ||
| ``` | ||
|
|
||
| Example of **incorrect** contact: | ||
|
|
||
| ```yaml Incorrect example | ||
| info: | ||
| version: 1.0.0 | ||
| title: Incorrect example missing contact | ||
| ``` | ||
|
|
||
| Example of **correct** contact: | ||
|
|
||
| ```yaml Correct example | ||
| info: | ||
| contact: | ||
| name: Redocly API Support | ||
| url: https://www.redocly.com/support | ||
| email: [email protected] | ||
| ``` | ||
|
|
||
| ## Related rules | ||
|
|
||
| - [spec](./struct.md) | ||
| - [configurable rules](../configurable-rules.md) | ||
|
|
||
| ## Resources | ||
|
|
||
| - [Rule source](https://github.com/Redocly/redocly-cli/blob/main/packages/core/src/rules/common/info-contact.ts) | ||
| - [Contact object docs](https://redocly.com/docs/openapi-visual-reference/contact/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,28 @@ | ||||||
| --- | ||||||
| slug: /docs/cli/v1/rules/overlay/struct | ||||||
| --- | ||||||
|
|
||||||
| # struct | ||||||
|
|
||||||
| Ensures that your API document conforms to the [Overlay specification](https://spec.openapis.org/overlay/latest.html#Overlay-specification). | ||||||
|
|
||||||
| | Overlay | Compatibility | | ||||||
| | ------- | ------------- | | ||||||
| | 1.x | ✅ | | ||||||
|
|
||||||
| The default setting for this rule (in the `recommended` and `minimal` configuration) is `error`. | ||||||
|
|
||||||
| This is an essential rule. Do not turned it off, except in rare and special cases. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ## Configuration | ||||||
|
|
||||||
| | Option | Type | Description | | ||||||
| | -------- | ------ | ------------------------------------------------------------------------------------------ | | ||||||
| | severity | string | Possible values: `off`, `warn`, `error`. Default `error` (in `recommended` configuration). | | ||||||
|
|
||||||
| An example configuration: | ||||||
|
|
||||||
| ```yaml | ||||||
| rules: | ||||||
| struct: error | ||||||
| ``` | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| --- | ||
| seo: | ||
| title: Lint Overlay with Redocly CLI | ||
| 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. | ||
| --- | ||
|
|
||
| # Lint Overlay with Redocly CLI | ||
|
|
||
| [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. | ||
| Redocly CLI offers support for checking that your Overlay files are valid. | ||
|
|
||
| {% admonition type="info" name="Experimental Overlay support" %} | ||
| This feature is at an early stage, please send us lots of [feedback](https://github.com/redocly/redocly-cli/issues)! | ||
| {% /admonition %} | ||
|
|
||
| ## Lint an Overlay file | ||
|
|
||
| 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. | ||
|
|
||
| **Pro-tip:** linting is much more interesting if the file actually does contain problems. | ||
| Be your own chaos monkey and introduce some errors before you proceed! | ||
|
|
||
| Lint using a command like the following: | ||
|
|
||
| ```bash | ||
| redocly lint overlay/museum-api.overlay.yaml | ||
| ``` | ||
|
|
||
| If the file does not match the specification, the tool shows the details of each error that it finds, like in the following example: | ||
|
|
||
| ```text | ||
| validating overlay/museum-api.overlay.yaml... | ||
| [1] overlay/museum-api.overlay.yaml:5:3 at #/info/description | ||
|
|
||
| Property `description` is not expected here. | ||
|
|
||
| 3 | title: Sample Overlay Configuration | ||
| 4 | version: 1.0.0 | ||
| 5 | description: "" | ||
| 6 | extends: openapi.yaml | ||
| 7 | actions: | ||
|
|
||
| Error was generated by the struct rule. | ||
|
|
||
|
|
||
|
|
||
| validating overlay/museum-api.overlay.yaml... | ||
| [1] overlay/museum-api.overlay.yaml:11:3 at #/actions/1/descript | ||
|
|
||
| Property `descript` is not expected here. | ||
|
|
||
| Did you mean: description ? | ||
|
|
||
| 10 | - target: $.paths['/museum-hours'] | ||
| 11 | descript: "not a valid field(misspelled)" | ||
| 12 | remove: true | ||
|
|
||
| Error was generated by the struct rule. | ||
|
|
||
| ``` | ||
|
|
||
| ## Configure the linting rules | ||
|
|
||
| Choose from the ready-made rulesets (`minimal`, `recommended` or `recommended-strict`), or go one better and configure the rules that suit your use case. | ||
| There's a full [list of built-in rules for Overlay](../rules/built-in-rules.md#Overlay-rules) to refer to. | ||
|
|
||
| Add the rules to `redocly.yaml`, but for Overlay specifications. | ||
| The following example shows configuration for the minimal ruleset with additional rules configuration: | ||
|
|
||
| ```yaml | ||
| extends: | ||
| - minimal | ||
|
|
||
| rules: | ||
| info-contact: warn | ||
| ``` | ||
|
|
||
| The configuration shown here gives some good entry-level linting using the `minimal` standard, and warns if info contact information is missing. | ||
|
|
||
| ## Choose output format | ||
|
|
||
| Since Redocly CLI is already a fully-featured lint tool, additional features such as a choice of formats are already included. | ||
|
|
||
| Get a report in **Markdown format** with the following command: | ||
|
|
||
| ```bash | ||
| redocly lint --format=markdown overlay/museum-api.overlay.yaml | ||
| ``` | ||
|
|
||
| Choose your preferred output format from `codeframe`, `stylish`, `json`, `checkstyle`, `codeclimate`, `github-actions`, `markdown`, or `summary`. | ||
| The [lint command page](../commands/lint.md) has full details of the command's options. | ||
|
|
||
| ## Add Overlay linting to GitHub Actions | ||
|
|
||
| To make sure that your Overlay description remains valid, add linting to your CI (Continuous Integration) setup. | ||
| 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. | ||
| The following snippet shows an example of configuring a GitHub action for linting: | ||
|
|
||
| ```yaml | ||
| name: Validate museum overlay descriptions | ||
|
|
||
| on: [pull_request] | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Set up node | ||
| uses: actions/setup-node@v4 | ||
| - name: Install Redocly CLI | ||
| run: npm install -g @redocly/cli@latest | ||
| - name: Run linting | ||
| run: redocly lint overlay/*yaml --format=github-actions | ||
| ``` | ||
|
|
||
| With this action in place, the intentional errors I added to the Overlay description are shown as annotations on the pull request: | ||
|
|
||
| <!-- TODO: Replace with actual image link --> | ||
|
|
||
|  | ||
|
|
||
| ## Participate in Redocly CLI | ||
|
|
||
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.