-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom message for built-in rules (#1834)
* feat: support custom message for built-in rules * add docs * fix docs * Update docs/configuration/reference/rules.md Co-authored-by: Heather Cloward <[email protected]> * Update docs/configuration/reference/rules.md Co-authored-by: Heather Cloward <[email protected]> * fix prettier issues --------- Co-authored-by: Heather Cloward <[email protected]>
- Loading branch information
Showing
13 changed files
with
260 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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/openapi-core": minor | ||
"@redocly/cli": minor | ||
--- | ||
|
||
Added the ability to override default problem messages for built-in rules. |
This file contains 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,13 @@ | ||
openapi: 3.1.0 | ||
info: | ||
version: 1.0.0 | ||
title: Custom messages test | ||
paths: | ||
/test: | ||
get: | ||
responses: | ||
200: | ||
content: | ||
application/json: | ||
schema: | ||
type: object |
This file contains 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 @@ | ||
apis: | ||
built-in-rule-message-override: | ||
root: ./openapi.yaml | ||
rules: | ||
info-contact: | ||
message: 'API LEVEL MESSAGE' # should override teh root-level message | ||
severity: warn | ||
operation-operationId: | ||
severity: warn | ||
message: 'API LEVEL WITH ORIGINAL MSG: {{message}}' # should enhance the original message | ||
split-documentation: | ||
root: split/openapi.yaml | ||
|
||
rules: | ||
info-contact: | ||
message: ROOT LEVEL MESSAGE # should be replaced with api-level message | ||
severity: error | ||
struct: | ||
message: 'ROOT LEVEL WITH ORIGINAL MSG: {{message}}' # should enhance the original message | ||
severity: error | ||
rule/operationId: | ||
subject: | ||
type: Operation | ||
message: 'Original problem: {{problems}}' # should not interfere with assertion messages | ||
severity: error | ||
assertions: | ||
required: | ||
- operationId |
This file contains 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,109 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`E2E lint default-message-override 1`] = ` | ||
validating openapi.yaml... | ||
[1] openapi.yaml:7:5 at #/paths/~1test/get | ||
Original problem: operationId is required | ||
5 | paths: | ||
6 | /test: | ||
7 | get: | ||
| ^^^ | ||
8 | responses: | ||
9 | 200: | ||
Error was generated by the rule/operationId rule. | ||
[2] openapi.yaml:9:9 at #/paths/~1test/get/responses/200 | ||
ROOT LEVEL WITH ORIGINAL MSG: The field \`description\` must be present on this level. | ||
7 | get: | ||
8 | responses: | ||
9 | 200: | ||
| ^^^ | ||
10 | content: | ||
11 | application/json: | ||
Error was generated by the struct rule. | ||
[3] openapi.yaml:2:1 at #/info/contact | ||
API LEVEL MESSAGE | ||
1 | openapi: 3.1.0 | ||
2 | info: | ||
| ^^^^ | ||
3 | version: 1.0.0 | ||
4 | title: Custom messages test | ||
Warning was generated by the info-contact rule. | ||
[4] openapi.yaml:7:5 at #/paths/~1test/get/operationId | ||
API LEVEL WITH ORIGINAL MSG: Operation object should contain \`operationId\` field. | ||
5 | paths: | ||
6 | /test: | ||
7 | get: | ||
| ^^^ | ||
8 | responses: | ||
9 | 200: | ||
Warning was generated by the operation-operationId rule. | ||
openapi.yaml: validated in <test>ms | ||
validating split/openapi.yaml... | ||
[1] split/info.yaml:1:1 at #/contact | ||
ROOT LEVEL MESSAGE | ||
1 | version: 1.0.0 | ||
| ^^^^^^^^^^^^^^ | ||
2 | title: Custom messages test | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
3 | | ||
Error was generated by the info-contact rule. | ||
[2] split/paths/test.yaml:1:1 at #/get | ||
Original problem: operationId is required | ||
1 | get: | ||
| ^^^ | ||
2 | responses: | ||
3 | '200': | ||
Error was generated by the rule/operationId rule. | ||
[3] split/paths/test.yaml:3:5 at #/get/responses/200 | ||
ROOT LEVEL WITH ORIGINAL MSG: The field \`description\` must be present on this level. | ||
1 | get: | ||
2 | responses: | ||
3 | '200': | ||
| ^^^^^ | ||
4 | content: | ||
5 | application/json: | ||
Error was generated by the struct rule. | ||
split/openapi.yaml: validated in <test>ms | ||
❌ Validation failed with 5 errors and 2 warnings. | ||
run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file. | ||
`; |
This file contains 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,2 @@ | ||
version: 1.0.0 | ||
title: Custom messages test |
This file contains 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 @@ | ||
openapi: 3.1.0 | ||
info: | ||
$ref: ./info.yaml | ||
paths: | ||
/test: | ||
$ref: paths/test.yaml |
7 changes: 7 additions & 0 deletions
7
__tests__/lint/default-message-override/split/paths/test.yaml
This file contains 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,7 @@ | ||
get: | ||
responses: | ||
'200': | ||
content: | ||
application/json: | ||
schema: | ||
type: object |
This file contains 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 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 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 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 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.
cd768f9
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.
Coverage report
Test suite run success
833 tests passing in 120 suites.
Report generated by 🧪jest coverage report action from cd768f9