Skip to content
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

Add scoring feature #686

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Add scoring feature #686

wants to merge 10 commits into from

Conversation

dpopp07
Copy link
Member

@dpopp07 dpopp07 commented Sep 27, 2024

This is a big PR to add a feature that translates the rule violations reported by the validator into simple scores that capture the impact of the rule violations on the API.

Any feedback is welcome. The majority of the changes are stable but I'm still adding a couple more pieces of documentation and maybe one or two more tests. That said, it's ready to review.

The commit breakdown is probably not very helpful - I'm going to try and clean it up before merging.

dpopp07 and others added 8 commits September 27, 2024 15:52
…sts paths

I found some odd behavior in which Spectral messes with the path strings reported
in the "path" array in the rule's context. This led to our code crashing when we
couldn't find the string in the API. This change skips the rule and logs an error.

In the future, we may want to address the problem on the Spectral side or fix the
path in-line and proceed with the check.

Signed-off-by: Dustin Popp <[email protected]>
Signed-off-by: Dustin Popp <[email protected]>
Signed-off-by: Dustin Popp <[email protected]>
Signed-off-by: Dustin Popp <[email protected]>
`${ruleId}: could not find path string ${pathString} in paths object. Skipping check...`
);
return [];
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A strange bug I ran into while testing the scoring logic on different APIs. I'll add a test to reproduce before I merge.

@@ -4,7 +4,7 @@
*/

/**
* Takes an unresolved path to a schema and un-resolves it to the format in which
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing a typo

"find-up": "5.0.0",
"globby": "^11.0.4",
"js-yaml": "^3.14.1",
"json-dup-key-validator": "^1.0.3",
"lodash": "^4.17.21",
"nimma": "^0.7.0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"@stoplight/spectral-ref-resolver" and "nimma" were already installed dependencies through Spectral, but this makes it obvious that we need them.

);

// Populate the metrics for the API.
await metrics.compute();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code needed for nimma to do this is sorta complicated - this file just makes it look nice and neat for us to define new "metrics" as we need them.

* SPDX-License-Identifier: Apache2.0
*/

module.exports = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be adding some documentation around what this file is, what things mean, and how one should go about updating it when adding a new rule.

@@ -79,14 +83,12 @@ function convertResults(spectralResults, { config, logger }) {
finalResultsObject.hasResults = true;
finalResultsObject[severity].summary.total++;

if (!summaryOnly) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to filter this here anymore, because we want to be able to use the rule violations to compute the quality scores. This filtering is moved to the end of run-validator.js, right before printing output.

Signed-off-by: Dustin Popp <[email protected]>
...require('./get-captured-text'),
...require('./get-captured-text'),
...require('./get-message-and-path-from-captured-text'),
...require('./strip-ansi'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purely "syntactic sugar" changes.


const ibmRuleset = require('@ibm-cloud/openapi-ruleset');

describe('scoring-tool rubric tests', function () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are essentially "linters" for the rubric, to make sure it stays up to date and uses the right data.

@dpopp07
Copy link
Member Author

dpopp07 commented Sep 27, 2024

Example output with the new flag:

Screenshot 2024-09-27 at 4 12 38 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants