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

fix: ingore violations from invalid locations of an api definition #716

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/validator/src/spectral/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ function convertResults(spectralResults, { config, logger }) {
continue;
}

// Ingore any rule violations that occur in sections of the spec that are
// not valid locations for API validation.
if (invalidLocation(r.path)) {
continue;
}

const severity = convertSpectralSeverity(r.severity);
// only collect errors when "errors only" is true
if (errorsOnly && r.severity > 0) {
Expand Down Expand Up @@ -224,3 +230,10 @@ function convertSpectralSeverity(s) {
const mapping = { 0: 'error', 1: 'warning', 2: 'info', 3: 'hint' };
return mapping[s];
}

function invalidLocation(pathArray) {
// The 'x-sdk-apiref' extension is an IBM internal section for providing
// SDK-related metadata. It is not appropriate for the validator to consider.
const invalidLocations = ['x-sdk-apiref'];
return invalidLocations.some(l => pathArray.includes(l));
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,10 @@ components:
UnusedString:
description: string
type: string

x-sdk-apiref:
type: int64
enum:
- this would trigger spectrals 'typed-enum' rule
- without our custom filter for invalid openapi locations
- this just tests that no warning is emitted for the 'x-sdk-apiref' location
Loading