Skip to content

Commit d1e9526

Browse files
fix(ipa): return internal errors as Spectral errors
1 parent 31550b0 commit d1e9526

File tree

45 files changed

+242
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+242
-101
lines changed

tools/spectral/ipa/rulesets/functions/IPA005ExceptionExtensionFormat.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { evaluateAndCollectAdoptionStatusWithoutExceptions, handleInternalError } from './utils/collectionUtils.js';
1+
import {
2+
evaluateAndCollectAdoptionStatusWithoutExceptions,
3+
handleInternalError,
4+
} from './utils/collectionUtils.js';
25

36
const RULE_NAME = 'xgen-IPA-005-exception-extension-format';
47
const ERROR_MESSAGE = 'IPA exceptions must have a valid rule name and a reason.';
@@ -29,6 +32,6 @@ function checkViolationsAndReturnErrors(input, path) {
2932
});
3033
return errors;
3134
} catch (e) {
32-
handleInternalError(RULE_NAME, path, e);
35+
return handleInternalError(RULE_NAME, path, e);
3336
}
3437
}

tools/spectral/ipa/rulesets/functions/IPA102CollectionIdentifierCamelCase.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js';
1+
import {
2+
evaluateAndCollectAdoptionStatus,
3+
handleInternalError,
4+
} from './utils/collectionUtils.js';
25
import { isPathParam } from './utils/componentUtils.js';
36
import { casing } from '@stoplight/spectral-functions';
47
import { findExceptionInPathHierarchy } from './utils/exceptions.js';
@@ -106,7 +109,7 @@ function checkViolations(pathKey, path, ignoredValues = []) {
106109
}
107110
});
108111
} catch (e) {
109-
handleInternalError(RULE_NAME, [...path, pathKey], e);
112+
return handleInternalError(RULE_NAME, [...path, pathKey], e);
110113
}
111114

112115
return violations;

tools/spectral/ipa/rulesets/functions/IPA102EachPathAlternatesBetweenResourceNameAndPathParam.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { isPathParam } from './utils/componentUtils.js';
2-
import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js';
2+
import {
3+
evaluateAndCollectAdoptionStatus,
4+
handleInternalError,
5+
} from './utils/collectionUtils.js';
36
import { AUTH_PREFIX, UNAUTH_PREFIX } from './utils/resourceEvaluation.js';
47
import { findExceptionInPathHierarchy } from './utils/exceptions.js';
58

@@ -67,6 +70,6 @@ function checkViolationsAndReturnErrors(suffixWithLeadingSlash, path) {
6770
}
6871
return [];
6972
} catch (e) {
70-
handleInternalError(RULE_NAME, path, e);
73+
return handleInternalError(RULE_NAME, path, e);
7174
}
7275
}

tools/spectral/ipa/rulesets/functions/IPA104EachResourceHasGetMethod.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import {
2-
hasGetMethod,
3-
isSingletonResource,
42
getResourcePathItems,
3+
hasGetMethod,
54
isResourceCollectionIdentifier,
65
isSingleResourceIdentifier,
6+
isSingletonResource,
77
} from './utils/resourceEvaluation.js';
8-
import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js';
8+
import {
9+
evaluateAndCollectAdoptionStatus,
10+
handleInternalError,
11+
} from './utils/collectionUtils.js';
912

1013
const RULE_NAME = 'xgen-IPA-104-resource-has-GET';
1114
const ERROR_MESSAGE = 'APIs must provide a get method for resources.';
@@ -42,6 +45,6 @@ function checkViolationsAndReturnErrors(oasPaths, input, path) {
4245
}
4346
return [];
4447
} catch (e) {
45-
handleInternalError(RULE_NAME, path, e);
48+
return handleInternalError(RULE_NAME, path, e);
4649
}
4750
}

tools/spectral/ipa/rulesets/functions/IPA104GetMethodReturnsSingleResource.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import {
44
isSingleResourceIdentifier,
55
isSingletonResource,
66
} from './utils/resourceEvaluation.js';
7-
import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js';
7+
import {
8+
evaluateAndCollectAdoptionStatus,
9+
handleInternalError,
10+
} from './utils/collectionUtils.js';
811
import { schemaIsArray, schemaIsPaginated } from './utils/schemaUtils.js';
912
import { resolveObject } from './utils/componentUtils.js';
1013

@@ -52,6 +55,6 @@ function checkViolationsAndReturnErrors(contentPerMediaType, path, isSingleton)
5255
}
5356
return [];
5457
} catch (e) {
55-
handleInternalError(RULE_NAME, path, e);
58+
return handleInternalError(RULE_NAME, path, e);
5659
}
5760
}

tools/spectral/ipa/rulesets/functions/IPA105ListMethodResponseIsGetMethodResponse.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ import {
44
isSingletonResource,
55
} from './utils/resourceEvaluation.js';
66
import { resolveObject } from './utils/componentUtils.js';
7-
import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js';
8-
import { getSchemaRef, getSchemaNameFromRef, getResponseOfGetMethodByMediaType } from './utils/methodUtils.js';
7+
import {
8+
evaluateAndCollectAdoptionStatus,
9+
handleInternalError,
10+
} from './utils/collectionUtils.js';
11+
import {
12+
getResponseOfGetMethodByMediaType,
13+
getSchemaNameFromRef,
14+
getSchemaRef,
15+
} from './utils/methodUtils.js';
916
import { schemaIsPaginated } from './utils/schemaUtils.js';
1017

1118
const RULE_NAME = 'xgen-IPA-105-list-method-response-is-get-method-response';
@@ -93,6 +100,6 @@ function checkViolationsAndReturnErrors(path, listMethodResultItems, getMethodRe
93100
}
94101
return [];
95102
} catch (e) {
96-
handleInternalError(RULE_NAME, path, e);
103+
return handleInternalError(RULE_NAME, path, e);
97104
}
98105
}

tools/spectral/ipa/rulesets/functions/IPA106CreateMethodResponseIsGetMethodResponse.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ import {
44
isSingletonResource,
55
} from './utils/resourceEvaluation.js';
66
import { resolveObject } from './utils/componentUtils.js';
7-
import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js';
8-
import { getSchemaRef, getResponseOfGetMethodByMediaType } from './utils/methodUtils.js';
7+
import {
8+
evaluateAndCollectAdoptionStatus,
9+
handleInternalError,
10+
} from './utils/collectionUtils.js';
11+
import {
12+
getResponseOfGetMethodByMediaType,
13+
getSchemaRef,
14+
} from './utils/methodUtils.js';
915

1016
const RULE_NAME = 'xgen-IPA-106-create-method-response-is-get-method-response';
1117
const ERROR_MESSAGE =
@@ -72,6 +78,6 @@ function checkViolationsAndReturnErrors(path, createMethodResponseContent, getMe
7278
}
7379
return [];
7480
} catch (e) {
75-
handleInternalError(RULE_NAME, path, e);
81+
return handleInternalError(RULE_NAME, path, e);
7682
}
7783
}

tools/spectral/ipa/rulesets/functions/IPA106CreateMethodShouldNotHaveQueryParameters.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js';
1+
import {
2+
evaluateAndCollectAdoptionStatus,
3+
handleInternalError,
4+
} from './utils/collectionUtils.js';
25
import {
36
getResourcePathItems,
47
isCustomMethodIdentifier,
@@ -50,6 +53,6 @@ function checkViolationsAndReturnErrors(postMethodParameters, path, opts) {
5053
}
5154
return errors;
5255
} catch (e) {
53-
handleInternalError(RULE_NAME, path, e);
56+
return handleInternalError(RULE_NAME, path, e);
5457
}
5558
}

tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodMustNotHaveQueryParams.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js';
1+
import {
2+
evaluateAndCollectAdoptionStatus,
3+
handleInternalError,
4+
} from './utils/collectionUtils.js';
25
import {
36
getResourcePathItems,
47
isResourceCollectionIdentifier,
@@ -51,6 +54,6 @@ function checkViolationsAndReturnErrors(postMethodParameters, path, ruleName, op
5154
}
5255
return errors;
5356
} catch (e) {
54-
handleInternalError(ruleName, path, e);
57+
return handleInternalError(ruleName, path, e);
5558
}
5659
}

tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodResponseIsGetMethodResponse.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import {
55
isSingletonResource,
66
} from './utils/resourceEvaluation.js';
77
import { resolveObject } from './utils/componentUtils.js';
8-
import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js';
9-
import { getSchemaRef, getGETMethodResponseSchemaFromPathItem } from './utils/methodUtils.js';
8+
import {
9+
evaluateAndCollectAdoptionStatus,
10+
handleInternalError,
11+
} from './utils/collectionUtils.js';
12+
import {
13+
getGETMethodResponseSchemaFromPathItem,
14+
getSchemaRef,
15+
} from './utils/methodUtils.js';
1016

1117
const RULE_NAME = 'xgen-IPA-107-update-method-response-is-get-method-response';
1218
const ERROR_MESSAGE =
@@ -84,6 +90,6 @@ function checkViolationsAndReturnErrors(path, updateMethodResponseContent, getMe
8490
}
8591
return [];
8692
} catch (e) {
87-
handleInternalError(RULE_NAME, path, e);
93+
return handleInternalError(RULE_NAME, path, e);
8894
}
8995
}

0 commit comments

Comments
 (0)