-
-
Notifications
You must be signed in to change notification settings - Fork 241
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
feat(core): scoring data customizable #2353
Open
PagoNxt-Trade
wants to merge
15
commits into
stoplightio:develop
Choose a base branch
from
PagoNxt-Trade:feature-AT-458-scoring_data_customizable
base: develop
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.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fb5ec2f
feat(core): scoring data customizable added with config file and CLI …
PagoNxt-Trade b74588c
feat(core): cli new parameter alias removed
PagoNxt-Trade 294ec3a
feat(core): cli results version output removed
PagoNxt-Trade ded50ec
feat(core): scoring config file readed with promises
PagoNxt-Trade c086041
feat(core): added unique error specified
PagoNxt-Trade 7909d08
feat(core): changed NOT PASSED message to FAILED on results
PagoNxt-Trade d8cd9b6
feat(core): changed NOT PASSED message to FAILED on results
PagoNxt-Trade 0ed625a
feat(core): lintern changes
PagoNxt-Trade 69cd341
docs(cli): remove -s alias from docs
PagoNxt-Trade fdea3e9
Merge branch 'develop' into feature-AT-458-scoring_data_customizable
PagoNxt-Trade 5f33c1b
docs(cli): apply suggested changes
PagoNxt-Trade aeb85a4
docs(cli): clarified info and changes applied
PagoNxt-Trade 2ab64a9
docs(cli): fixed lint errors
PagoNxt-Trade 90d024c
Merge branch 'develop' into feature-AT-458-scoring_data_customizable
PagoNxt-Trade 3815428
Merge branch 'develop' into feature-AT-458-scoring_data_customizable
mnaumanali94 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 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 |
---|---|---|
|
@@ -39,6 +39,7 @@ Other options include: | |
--stdin-filepath path to a file to pretend that stdin comes from [string] | ||
--resolver path to custom json-ref-resolver instance [string] | ||
-r, --ruleset path/URL to a ruleset file [string] | ||
--scoring-config path/URL to a scoring config file [string] | ||
-F, --fail-severity results of this level or above will trigger a failure exit code | ||
[string] [choices: "error", "warn", "info", "hint"] [default: "error"] | ||
-D, --display-only-failures only output results equal to or greater than --fail-severity [boolean] [default: false] | ||
|
@@ -60,6 +61,99 @@ Here you can build a [custom ruleset](../getting-started/3-rulesets.md), or exte | |
- [OpenAPI ruleset](../reference/openapi-rules.md) | ||
- [AsyncAPI ruleset](../reference/asyncapi-rules.md) | ||
|
||
## Scoring the API | ||
|
||
Scoring an API definition is a way to understand at a high level how compliant the API definition is with the rulesets provided. This helps teams to understand the quality of the APIs regarding the definition. | ||
|
||
The scoring is produced in two different metrics: | ||
|
||
- A number scoring: Calculated by subtracting any error or warning from 100%. | ||
- A letter scoring, which groups numeric scoring in letters from A to Z, with A being the best score. | ||
|
||
Also it introduces a quality gate, were an API scoring below the specific threshold will fail in a pipeline. | ||
|
||
Enabling scoring is done using a new parameter called --scoring-config and the scoring configuration file, where you can define how an error or a warning affects to the scoring | ||
|
||
Usage: | ||
|
||
```bash | ||
spectral lint ./reference/**/*.oas*.{json,yml,yaml} --ruleset mycustomruleset.js --scoring-config ./scoringFile.json | ||
``` | ||
|
||
Heres an example of this scoringFile config file: | ||
|
||
``` | ||
{ | ||
"scoringSubtract": | ||
{ | ||
"error": | ||
{ | ||
1:55, | ||
2:65, | ||
3:75, | ||
6:85, | ||
10:95 | ||
} | ||
"warn": | ||
{ | ||
1:3, | ||
2:7, | ||
3:10, | ||
6:15, | ||
10:18 | ||
} | ||
}, | ||
"scoringLetter": | ||
{ | ||
"A":75, | ||
"B":65, | ||
"C":55, | ||
"D":45, | ||
"E":0 | ||
}, | ||
"threshold":50, | ||
"onlySubtractHigherSeverityLevel": true, | ||
"uniqueErrors": false | ||
} | ||
``` | ||
|
||
Where: | ||
|
||
- scoringSubtract : An object with key/value pair objects for every result level we want to subtract percentage, with the percentage to subtract from number of results on every result type | ||
- scoringLetter : An object with key/value pairs with scoring letter and scoring percentage, that the result must be greater, for this letter | ||
- threshold : A number with minimum percentage value to provide valid the file we are checking. Any scoring below this thresold will mark the API as a failure in the scoring. | ||
- onlySubtractHigherSeverityLevel : A boolean to decide if only the higher severity level who appears in the results for the API to analize, are subtracted from scoring or every severity level are subtracted from scoring. | ||
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. analize-> analyze |
||
|
||
See sample: | ||
|
||
true | ||
|
||
API with Errors and Warnings, only Errors substract from scoring | ||
API with Warnings, Warnings substract from scoring | ||
|
||
false | ||
|
||
API with Errors and Warnings, Errors and Warnings substracts from scoring | ||
API with Warnings, Warnings substract from scoring | ||
|
||
- uniqueErrors : A boolean to count unique errors or all errors. An error is considered unique if its code and message have not been seen yet | ||
|
||
Example: | ||
|
||
With previous scoring config file, if we have: | ||
|
||
1 error, the scoring is 45% and D | ||
2 errors, the scoring is 35% and E | ||
3 errors, the scoring is 25% and E | ||
4 errors, the scoring is 25% and E | ||
and so on | ||
|
||
Output: | ||
|
||
Below your output log you can see the scoring, like: | ||
|
||
✖ SCORING: A (93%) | ||
|
||
## Error Results | ||
|
||
Spectral has a few different error severities: `error`, `warn`, `info`, and `hint`, and they're in order from highest to lowest. By default, all results are shown regardless of severity, but since v5.0, only the presence of errors causes a failure status code of 1. Seeing results and getting a failure code for it are now two different things. | ||
|
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.
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.
@pamgoodrich do you want to have a quick look at the docs here?