Skip to content

Commit 6c45985

Browse files
authored
feat: improve the spec ruleset (#2163)
1 parent ef9968f commit 6c45985

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+572
-170
lines changed

.changeset/long-ducks-deliver.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@redocly/openapi-core": minor
3+
"@redocly/cli": minor
4+
---
5+
6+
Configured the `spec` ruleset for OpenAPI, AsyncAPI, Arazzo, and Overlay specifications.
7+
This ruleset is designed to strictly follow the specifications.

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
coverage/
22
lib/
33
output/
4-
packages/core/src/rules/__tests__/fixtures/invalid-yaml.yaml
4+
packages/core/src/rules/common/__tests__/fixtures/invalid-yaml.yaml
55
packages/respect-core/src/modules/runtime-expressions/abnf-parser.cjs
66
benchmark/api-definitions/
77
LICENSE.md

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ It only checks links within the local docs (it can't check links to other docs s
160160

161161
## Built-in rules changes
162162

163-
After adding a new rule, make sure it is added to the `minimal`, `recommended`, `recommended-strict` (the same as the previous but with warnings turned into error) and `all` rulesets with appropriate severity levels.
163+
After adding a new rule, make sure it is added to the `minimal`, `recommended`, `recommended-strict` (the same as the previous but with warnings turned into error), `spec`, and `all` rulesets with appropriate severity levels.
164164
The defaults are `off` for `minimal` and `recommended` and `error` for `all`.
165165
Also add the rule to the built-in rules list in [the config types tree](./packages/core/src/types/redocly-yaml.ts).
166166

docs/@v2/commands/lint.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ redocly lint --version
2424

2525
## Options
2626

27-
| Option | Type | Description |
28-
| ---------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
29-
| apis | [string] | Array of API or Arazzo description filenames that need to be linted. See [the API section](#specify-api) for more options. |
30-
| --config | string | Specify path to the [configuration file](#use-custom-configuration-file). |
31-
| --extends | [string] | [Extend a specific configuration](#extend-configuration) (defaults or config file settings). Build-in rulesets are: `minimal`, `recommended`, `recommended-strict`. Default value is `recommended`. |
32-
| --format | string | Format for the output.<br />**Possible values:** `codeframe`, `stylish`, `json`, `checkstyle`, `codeclimate`, `github-actions`, `markdown`, `summary`. Default value is `codeframe`. |
33-
| --generate-ignore-file | boolean | [Generate ignore file](#generate-ignore-file). |
34-
| --help | boolean | Show help. |
35-
| --lint-config | string | Specify the severity level for the configuration file. <br/> **Possible values:** `warn`, `error`, `off`. Default value is `warn`. |
36-
| --max-problems | integer | Truncate output to display the specified [maximum number of problems](#limit-the-displayed-problems-count). Default value is 100. |
37-
| --skip-preprocessor | [string] | Ignore certain preprocessors. See the [Skip preprocessor or rule section](#skip-preprocessor-or-rule) below. |
38-
| --skip-rule | [string] | Ignore certain rules. See the [Skip preprocessor or rule section](#skip-preprocessor-or-rule) below. |
39-
| --version | boolean | Show version number. |
27+
| Option | Type | Description |
28+
| ---------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
29+
| apis | [string] | Array of API or Arazzo description filenames that need to be linted. See [the API section](#specify-api) for more options. |
30+
| --config | string | Specify path to the [configuration file](#use-custom-configuration-file). |
31+
| --extends | [string] | [Extend a specific configuration](#extend-configuration) (defaults or config file settings). Build-in rulesets are: `spec`, `minimal`, `recommended`, `recommended-strict`. Default value is `recommended`. |
32+
| --format | string | Format for the output.<br />**Possible values:** `codeframe`, `stylish`, `json`, `checkstyle`, `codeclimate`, `github-actions`, `markdown`, `summary`. Default value is `codeframe`. |
33+
| --generate-ignore-file | boolean | [Generate ignore file](#generate-ignore-file). |
34+
| --help | boolean | Show help. |
35+
| --lint-config | string | Specify the severity level for the configuration file. <br/> **Possible values:** `warn`, `error`, `off`. Default value is `warn`. |
36+
| --max-problems | integer | Truncate output to display the specified [maximum number of problems](#limit-the-displayed-problems-count). Default value is 100. |
37+
| --skip-preprocessor | [string] | Ignore certain preprocessors. See the [Skip preprocessor or rule section](#skip-preprocessor-or-rule) below. |
38+
| --skip-rule | [string] | Ignore certain rules. See the [Skip preprocessor or rule section](#skip-preprocessor-or-rule) below. |
39+
| --version | boolean | Show version number. |
4040

4141
## Examples
4242

@@ -113,7 +113,7 @@ redocly lint --config=./another/directory/config.yaml
113113
### Extend configuration
114114

115115
The `--extends` option allows you to extend the existing configuration.
116-
This option accepts one of the following values: `minimal`, `recommended`, or `recommended-strict`.
116+
This option accepts one of the following values: `minimal`, `recommended`, `recommended-strict`, or `spec`.
117117
Each of the values is a base set of rules that the `lint` command uses.
118118
You can further modify this set in cases when you want to have your own set of rules based on the existing one, including particular rules that cover your specific needs.
119119
For more details, see [rulesets](../rules.md).
@@ -304,8 +304,8 @@ Running the `lint` command with `--format=markdown` produces output like the fol
304304

305305
| Severity | Location | Problem | Message |
306306
|---|---|---|---|
307-
| error | line 42:11 | [struct](https://redocly.com/docs/cli/rules/oas/struct) | Must contain at least one of the following fields: schema, content. |
308-
| error | line 44:11 | [struct](https://redocly.com/docs/cli/rules/oas/struct) | Property `type` is not expected here. |
307+
| error | line 42:11 | [struct](https://redocly.com/docs/cli/rules/common/struct) | Must contain at least one of the following fields: schema, content. |
308+
| error | line 44:11 | [struct](https://redocly.com/docs/cli/rules/common/struct) | Property `type` is not expected here. |
309309

310310
Validation failed
311311
Errors: 2
@@ -369,7 +369,7 @@ Example of an ignore file:
369369

370370
```yaml .redocly.lint-ignore.yaml file
371371
# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.
372-
# See https://redoc.ly/docs/cli/ for more information.
372+
# See https://redocly.com/docs/cli/ for more information.
373373
museum-with-errors.yaml:
374374
struct:
375375
- '#/paths/~1museum-hours/get/operationIds'

docs/@v2/guides/configure-rules.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ In this guide, learn how to choose and adapt the rules built into Redocly for yo
1010

1111
To get started, try one of the existing rulesets and see if it meets your needs.
1212

13+
- The [`spec`](../rules/spec-ruleset.md) ruleset follows the OpenAPI specification.
1314
- The [`recommended`](../rules/recommended.md) ruleset has a good basic set of rules for a consistent, user-friendly API.
1415
- The [recommended-strict](../rules/recommended.md#recommended-strict-ruleset) ruleset is identical to the `recommended`, except it elevates all warnings to errors so that you don't miss the warnings, i.e. in a CI pipeline.
1516
- Or try the [`minimal`](../rules/minimal.md) ruleset which shows some warnings, but far fewer errors that would cause the lint to fail.

docs/@v2/guides/lint-arazzo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ run `redocly lint --generate-ignore-file` to add all problems to the ignore file
7070

7171
## Configure the linting rules
7272

73-
Choose from the ready-made rulesets (`minimal`, `recommended` or `recommended-strict`), or go one better and configure the rules that suit your use case.
73+
Choose from the ready-made rulesets (`spec`, `minimal`, `recommended` or `recommended-strict`), or go one better and configure the rules that suit your use case.
7474
There's a full [list of built-in rules for Arazzo](../rules/built-in-rules.md#arazzo-rules) to refer to.
7575

7676
Add the rules to `redocly.yaml`, but for Arazzo specifications, the rules go in their own configuration section called `arazzoRules`.

docs/@v2/quickstart.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ You have 1 warning.
6363

6464
The output shows any aspects where the OpenAPI doesn't meet the standard. If you get too much output, try adding the `--format summary` parameter to the command.
6565

66-
Feeling brave and highly API compliant? Try the `recommended` standard instead and see how yours measures up.
66+
Feeling brave and highly API compliant? Try the `recommended` or `spec` ruleset instead and see how yours measures up.
6767

6868
## Craft a custom ruleset
6969

7070
Redocly CLI has some [great built-in rules](./rules/built-in-rules.md), and you can use these to build up a ruleset that works for you.
7171

72-
For example, let's build a lightweight ruleset using the [minimal ruleset](./rules/minimal.md) and adding some built-in rules to create a custom ruleset. You can see an example in the following snippet:
72+
For example, let's build a lightweight ruleset using the [spec ruleset](./rules/spec-ruleset.md) and adding some built-in rules to create a custom ruleset. You can see an example in the following snippet:
7373

7474
```yaml
7575
extends:
76-
- minimal
76+
- spec
7777

7878
rules:
7979
path-parameters-defined: error

docs/@v2/rules.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Redocly uses rules to describe all the different aspects of API behavior that we
1616

1717
Rulesets are groups of rules that are applied together, and APIs can be checked against as many rulesets as needed during linting. To get you started, there are some built-in rulesets:
1818

19-
- Our [recommended](./rules/recommended.md) ruleset is our unabashedly opinionated recommendation of what we think a good API looks like. It's a great place to start, before adapting to your own context.
19+
- Our [spec](./rules/spec-ruleset.md) ruleset follows the OpenAPI specification as closely as possible and is a good starting point to build your own standards on top of it.
20+
- A [recommended](./rules/recommended.md) ruleset is our unabashedly opinionated recommendation of what we think a good API looks like. It's a great place to start, before adapting to your own context.
2021
- A [recommended-strict](./rules/recommended.md#recommended-strict-ruleset) ruleset is identical to the `recommended`, except it elevates all warnings to errors. It's the ideal option for those who don't want to miss anything.
2122
- A [minimal](./rules/minimal.md) ruleset is a good starting point for an existing API that doesn't currently conform to any standard. It has fewer rules that cause an error, with others either downgraded to a warning or turned off completely.
2223

docs/@v2/rules/arazzo/struct.md

Lines changed: 0 additions & 28 deletions
This file was deleted.

docs/@v2/rules/built-in-rules.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ The rules list is split into sections.
2929

3030
### Special rules
3131

32-
- [no-unresolved-refs](./oas/no-unresolved-refs.md): Every `$ref` must exist
32+
- [no-unresolved-refs](./common/no-unresolved-refs.md): Every `$ref` must exist
3333
- [no-unused-components](./oas/no-unused-components.md): All components must be used
3434
- [security-defined](./oas/security-defined.md): Security rules must be defined, either globally or per-operation
35-
- [struct](./oas/struct.md): Conform to the declared OpenAPI specification version
35+
- [struct](./common/struct.md): Conform to the declared OpenAPI specification version
3636
- [spec-components-invalid-map-name](./oas/spec-components-invalid-map-name.md): Use only alphanumeric and basic punctuation as key names in the components section
3737
- [spec-strict-refs](./oas/spec-strict-refs.md) Restricts the usage of the `$ref` keyword.
3838

0 commit comments

Comments
 (0)