Skip to content

Commit 13e753a

Browse files
authored
feat: refine the predefined rulesets (#2366)
1 parent dab0dcd commit 13e753a

File tree

14 files changed

+749
-795
lines changed

14 files changed

+749
-795
lines changed

.changeset/calm-olives-kiss.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+
Added the `no-invalid-schema-examples` and `no-invalid-parameter-examples` to the `recommended` ruleset.
7+
Added the `no-duplicated-tag-names` to the `spec` ruleset.

CONTRIBUTING.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,17 @@ It only checks links within the local docs (it can't check links to other docs s
175175
## Built-in rules changes
176176

177177
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.
178-
The defaults are `off` for `minimal` and `recommended` and `error` for `all`.
178+
The defaults are `off` or `warn` for `minimal` and `recommended` and `error` for `all`.
179179
Also add the rule to the built-in rules list in [the config types tree](./packages/core/src/types/redocly-yaml.ts).
180180

181+
If the rule reflects a specification requirement, prefix it with `spec-` and add it to the [spec ruleset](./packages/core/src/rules/oas3/spec-ruleset.ts).
182+
181183
Separately, open a merge request with the corresponding documentation changes.
184+
To make changes to documentation:
185+
186+
1. Create a new page for the rule in the `docs/@v2` folder.
187+
2. Add the link to the rule page to the [built-in rules list](docs/@v2/rules/built-in-rules.md) and the [sidebar](docs/@v2/sidebars.yaml).
188+
3. Update the rulesets pages and [ruleset templates](docs/@v2/rules/ruleset-templates.md).
182189

183190
## Arguments usage
184191

__tests__/lint/oas3.1/openapi.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ paths:
3434
schema:
3535
type: array
3636
prefixItems:
37-
- type: 'string'
37+
- type: string
3838
items: false
3939
400:
4040
description: An error response
@@ -109,10 +109,10 @@ paths:
109109
/unevaluated-properties:
110110
get:
111111
operationId: getUnevaluatedProperties
112-
summary: Checks if unevaluetedProperties work
112+
summary: Checks if unevaluatedProperties work
113113
responses:
114114
200:
115-
description: 'OK'
115+
description: OK
116116
content:
117117
application/json:
118118
schema:
@@ -177,11 +177,11 @@ components:
177177
pathItems: {}
178178
schemas:
179179
Problem:
180-
id: 'https://tools.ietf.org/rfc/rfc7807.txt'
180+
id: https://tools.ietf.org/rfc/rfc7807.txt
181181
$schema: 'http://json-schema.org/draft-06/schema#'
182-
description: 'schema for a rfc7807'
182+
description: schema for a rfc7807
183183
definitions: {}
184-
type: 'object'
184+
type: object
185185
properties:
186186
type:
187187
description: A URI reference [RFC3986] that identifies the problem type.

__tests__/lint/oas3.1/snapshot.txt

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
1-
[1] openapi.yaml:179:5 at #/components/schemas/Problem
1+
[1] openapi.yaml:180:7 at #/components/schemas/Problem/schema
2+
3+
Example validation errored: NOT SUPPORTED: keyword "id", use "$id" for schema ID.
4+
5+
178 | schemas:
6+
179 | Problem:
7+
180 | id: https://tools.ietf.org/rfc/rfc7807.txt
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9+
181 | $schema: 'http://json-schema.org/draft-06/schema#'
10+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
… | < 32 more lines >
12+
214 | Pet:
13+
| ^
14+
215 | required:
15+
216 | - id
16+
17+
referenced from openapi.yaml:180:7 at #/components/schemas/Problem
18+
19+
Warning was generated by the no-invalid-schema-examples rule.
20+
21+
22+
[2] openapi.yaml:179:5 at #/components/schemas/Problem
223

324
Component: "Problem" is never used.
425

526
177 | pathItems: {}
627
178 | schemas:
728
179 | Problem:
829
| ^^^^^^^
9-
180 | id: 'https://tools.ietf.org/rfc/rfc7807.txt'
30+
180 | id: https://tools.ietf.org/rfc/rfc7807.txt
1031
181 | $schema: 'http://json-schema.org/draft-06/schema#'
1132

1233
Warning was generated by the no-unused-components rule.
@@ -17,5 +38,5 @@ validating openapi.yaml using lint rules for api 'main'...
1738
openapi.yaml: validated in <test>ms
1839

1940
Woohoo! Your API description is valid. 🎉
20-
You have 1 warning.
41+
You have 2 warnings.
2142

docs/@v2/rules/minimal.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Errors:
1111
- [no-server-trailing-slash](./oas/no-server-trailing-slash.md)
1212
- [no-server-variables-empty-enum](./oas/no-server-variables-empty-enum.md)
1313
- [no-unresolved-refs](./common/no-unresolved-refs.md)
14-
- [struct](./common/struct.md)
1514
- [stepId-unique](./arazzo/stepId-unique.md)
15+
- [struct](./common/struct.md)
1616
- [workflowId-unique](./arazzo/workflowId-unique.md)
1717

1818
Warnings:
@@ -21,27 +21,29 @@ Warnings:
2121
- [no-ambiguous-paths](./oas/no-ambiguous-paths.md)
2222
- [no-empty-servers](./oas/no-empty-servers.md)
2323
- [no-enum-type-mismatch](./common/no-enum-type-mismatch.md)
24-
- [no-required-schema-properties-undefined](./common/no-required-schema-properties-undefined.md)
25-
- [no-schema-type-mismatch](./common/no-schema-type-mismatch.md)
2624
- [no-example-value-and-externalValue](./oas/no-example-value-and-externalValue.md)
2725
- [no-identical-paths](./oas/no-identical-paths.md)
2826
- [no-invalid-media-type-examples](./oas/no-invalid-media-type-examples.md)
2927
- [no-path-trailing-slash](./oas/no-path-trailing-slash.md)
28+
- [no-required-schema-properties-undefined](./common/no-required-schema-properties-undefined.md)
29+
- [no-schema-type-mismatch](./common/no-schema-type-mismatch.md)
3030
- [no-server-example.com](./oas/no-server-example-com.md)
3131
- [no-undefined-server-variable](./oas/no-undefined-server-variable.md)
3232
- [no-unused-components](./oas/no-unused-components.md)
3333
- [nullable-type-sibling](./oas/nullable-type-sibling.md)
3434
- [operation-2xx-response](./oas/operation-2xx-response.md)
35+
- [operation-operationId](./oas/operation-operationId.md)
3536
- [operation-operationId-unique](./oas/operation-operationId-unique.md)
3637
- [operation-operationId-url-safe](./oas/operation-operationId-url-safe.md)
37-
- [operation-operationId](./oas/operation-operationId.md)
3838
- [operation-parameters-unique](./oas/operation-parameters-unique.md)
3939
- [operation-summary](./oas/operation-summary.md)
4040
- [path-declaration-must-exist](./oas/path-declaration-must-exist.md)
41-
- [path-not-include-query](./oas/path-not-include-query.md)d
41+
- [path-not-include-query](./oas/path-not-include-query.md)
4242
- [path-parameters-defined](./oas/path-parameters-defined.md)
4343
- [security-defined](./oas/security-defined.md)
4444
- [spec-components-invalid-map-name](./oas/spec-components-invalid-map-name.md)
45+
- [spec-no-invalid-encoding-combinations](./oas/spec-no-invalid-encoding-combinations.md)
46+
- [spec-no-invalid-tag-parents](./oas/spec-no-invalid-tag-parents.md)
4547
- [tag-description](./oas/tag-description.md)
4648

4749
A copy-pastable version of this ruleset is available as a [ruleset template](./ruleset-templates.md).

docs/@v2/rules/recommended.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Errors:
1010

1111
- [no-empty-servers](./oas/no-empty-servers.md)
1212
- [no-enum-type-mismatch](./common/no-enum-type-mismatch.md)
13-
- [no-schema-type-mismatch](./common/no-schema-type-mismatch.md)
1413
- [no-example-value-and-externalValue](./oas/no-example-value-and-externalValue.md)
1514
- [no-identical-paths](./oas/no-identical-paths.md)
1615
- [no-path-trailing-slash](./oas/no-path-trailing-slash.md)
16+
- [no-schema-type-mismatch](./common/no-schema-type-mismatch.md)
1717
- [no-server-trailing-slash](./oas/no-server-trailing-slash.md)
1818
- [no-server-variables-empty-enum](./oas/no-server-variables-empty-enum.md)
1919
- [no-undefined-server-variable](./oas/no-undefined-server-variable.md)
@@ -23,36 +23,45 @@ Errors:
2323
- [operation-operationId-url-safe](./oas/operation-operationId-url-safe.md)
2424
- [operation-parameters-unique](./oas/operation-parameters-unique.md)
2525
- [operation-summary](./oas/operation-summary.md)
26+
- [parameters-unique](./arazzo/parameters-unique.md)
2627
- [path-declaration-must-exist](./oas/path-declaration-must-exist.md)
2728
- [path-not-include-query](./oas/path-not-include-query.md)
2829
- [path-parameters-defined](./oas/path-parameters-defined.md)
2930
- [security-defined](./oas/security-defined.md)
30-
- [spec-components-invalid-map-name](./oas/spec-components-invalid-map-name.md)
31-
- [struct](./common/struct.md)
32-
- [parameters-unique](./arazzo/parameters-unique.md)
33-
- [sourceDescription-type](./arazzo/sourceDescriptions-type.md)
3431
- [sourceDescription-name-unique](./arazzo/sourceDescriptions-name-unique.md)
32+
- [sourceDescription-type](./arazzo/sourceDescriptions-type.md)
33+
- [sourceDescriptions-not-empty](./arazzo/sourceDescriptions-not-empty.md)
34+
- [spec-components-invalid-map-name](./oas/spec-components-invalid-map-name.md)
35+
- [spec-example-values](./oas/spec-example-values.md)
36+
- [spec-no-invalid-encoding-combinations](./oas/spec-no-invalid-encoding-combinations.md)
37+
- [spec-no-invalid-tag-parents](./oas/spec-no-invalid-tag-parents.md)
3538
- [stepId-unique](./arazzo/stepId-unique.md)
39+
- [struct](./common/struct.md)
3640
- [workflow-dependsOn](./arazzo/workflow-dependsOn.md)
3741
- [workflowId-unique](./arazzo/workflowId-unique.md)
3842

3943
Warnings:
4044

4145
- [configurable rules](./configurable-rules.md)
46+
- [criteria-unique](./arazzo/criteria-unique.md)
4247
- [info-license](./oas/info-license.md)
4348
- [info-license-strict](./oas/info-license-strict.md)
4449
- [no-ambiguous-paths](./oas/no-ambiguous-paths.md)
50+
- [no-duplicated-tag-names](./oas/no-duplicated-tag-names.md)
4551
- [no-invalid-media-type-examples](./oas/no-invalid-media-type-examples.md)
52+
- [no-invalid-parameter-examples](./oas/no-invalid-parameter-examples.md)
53+
- [no-invalid-schema-examples](./oas/no-invalid-schema-examples.md)
4654
- [no-required-schema-properties-undefined](./common/no-required-schema-properties-undefined.md)
4755
- [no-server-example.com](./oas/no-server-example-com.md)
4856
- [no-unused-components](./oas/no-unused-components.md)
4957
- [operation-2xx-response](./oas/operation-2xx-response.md)
5058
- [operation-4xx-response](./oas/operation-4xx-response.md)
5159
- [operation-operationId](./oas/operation-operationId.md)
52-
- [tag-description](./oas/tag-description.md)
5360
- [requestBody-replacements-unique](./arazzo/requestBody-replacements-unique.md)
61+
- [spec-discriminator-defaultMapping](./oas/spec-discriminator-defaultMapping.md)
5462
- [step-onFailure-unique](./arazzo/step-onFailure-unique.md)
5563
- [step-onSuccess-unique](./arazzo/step-onSuccess-unique.md)
64+
- [tag-description](./oas/tag-description.md)
5665

5766
## Recommended strict ruleset
5867

0 commit comments

Comments
 (0)