diff --git a/tools/spectral/ipa/ipa-spectral.yaml b/tools/spectral/ipa/ipa-spectral.yaml index 50b2192fa9..95a3677643 100644 --- a/tools/spectral/ipa/ipa-spectral.yaml +++ b/tools/spectral/ipa/ipa-spectral.yaml @@ -133,3 +133,7 @@ overrides: - '**#/paths/~1api~1atlas~1v2~1groups~1%7BgroupId%7D~1pushBasedLogExport' rules: xgen-IPA-106-create-method-request-has-no-readonly-fields: 'off' + - files: # To be removed in CLOUDP-337392 + - '**#/components/schemas/AWSHardwareSpec20240805/properties/ebsVolumeType' + rules: + xgen-IPA-112-field-names-are-camel-case: 'off' diff --git a/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethod204Response.js b/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethod204Response.js index 5cf73a6f22..082f11c638 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethod204Response.js +++ b/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethod204Response.js @@ -1,11 +1,5 @@ -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { isSingleResourceIdentifier } from './utils/resourceEvaluation.js'; -import { hasException } from './utils/exceptions.js'; const RULE_NAME = 'xgen-IPA-108-delete-method-return-204-response'; const ERROR_MESSAGE = 'DELETE method should return 204 No Content status code.'; @@ -25,16 +19,8 @@ export default (input, _, { path }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(input, path); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; function checkViolationsAndReturnErrors(input, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethodNoRequestBody.js b/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethodNoRequestBody.js index 5a9f9a50c1..74700713c9 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethodNoRequestBody.js +++ b/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethodNoRequestBody.js @@ -1,6 +1,5 @@ -import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; import { isSingleResourceIdentifier } from './utils/resourceEvaluation.js'; -import { hasException } from './utils/exceptions.js'; const RULE_NAME = 'xgen-IPA-108-delete-request-no-body'; const ERROR_MESSAGE = 'DELETE method should not have a request body.'; @@ -20,14 +19,14 @@ export default (input, _, { path }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - - const requestBody = input.requestBody; - if (requestBody) { - return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); + let errors = []; + if (input.requestBody) { + errors = [ + { + path, + message: ERROR_MESSAGE, + }, + ]; } - return collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethodResponseShouldNotHaveSchema.js b/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethodResponseShouldNotHaveSchema.js index dc4f897083..ab4b083ebd 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethodResponseShouldNotHaveSchema.js +++ b/tools/spectral/ipa/rulesets/functions/IPA108DeleteMethodResponseShouldNotHaveSchema.js @@ -1,10 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { isSingleResourceIdentifier } from './utils/resourceEvaluation.js'; const RULE_NAME = 'xgen-IPA-108-delete-response-should-be-empty'; @@ -22,26 +16,15 @@ export default (input, _, { path }) => { return; } - // 1. Handle exception on OpenAPI schema - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - - // 2. Validation const errors = checkViolationsAndReturnErrors(input, path); - if (errors.length > 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; /** * Check if the operation has validation issues - * @param {object} input - The object to vefify - * @param {object} jsonPathArray - The jsonPathArray covering location in the OpenAPI schema - * @return {Array} - errors array () + * @param {object} input - The object to verify + * @param {Array} jsonPathArray - The jsonPathArray covering location in the OpenAPI schema + * @return {Array<{path: Array, message: string}>} - errors array () */ function checkViolationsAndReturnErrors(input, jsonPathArray) { const errors = []; diff --git a/tools/spectral/ipa/rulesets/functions/IPA108ValidOperationID.js b/tools/spectral/ipa/rulesets/functions/IPA108ValidOperationID.js index 2c2c3d9759..d306735575 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA108ValidOperationID.js +++ b/tools/spectral/ipa/rulesets/functions/IPA108ValidOperationID.js @@ -1,10 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectException, - collectAndReturnViolation, - handleInternalError, -} from './utils/collectionUtils.js'; +import { handleInternalError, evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; import { isCustomMethodIdentifier } from './utils/resourceEvaluation.js'; import { hasCustomMethodOverride, hasMethodVerbOverride, VERB_OVERRIDE_EXTENSION } from './utils/extensions.js'; import { validateOperationIdAndReturnErrors } from './utils/validations/validateOperationIdAndReturnErrors.js'; @@ -18,23 +12,13 @@ export default (input, { methodName }, { path }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - if (hasMethodVerbOverride(input, methodName)) { methodName = input[VERB_OVERRIDE_EXTENSION].verb; } try { const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path); - - if (errors.length > 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); } catch (e) { return handleInternalError(RULE_NAME, path, e); } diff --git a/tools/spectral/ipa/rulesets/functions/IPA109CustomMethodIdentifierFormat.js b/tools/spectral/ipa/rulesets/functions/IPA109CustomMethodIdentifierFormat.js index f21318161d..5a4de133b0 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA109CustomMethodIdentifierFormat.js +++ b/tools/spectral/ipa/rulesets/functions/IPA109CustomMethodIdentifierFormat.js @@ -1,11 +1,5 @@ -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { isCustomMethodIdentifier } from './utils/resourceEvaluation.js'; -import { hasException } from './utils/exceptions.js'; const RULE_NAME = 'xgen-IPA-109-custom-method-identifier-format'; @@ -25,16 +19,8 @@ export default (input, _, { path }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(pathKey, path); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; function checkViolationsAndReturnErrors(pathKey, path) { @@ -42,7 +28,12 @@ function checkViolationsAndReturnErrors(pathKey, path) { // Check for multiple colons const colonCount = (pathKey.match(/:/g) || []).length; if (colonCount > 1) { - return [{ path, message: `Multiple colons found in "${pathKey}".` }]; + return [ + { + path, + message: `Multiple colons found in "${pathKey}".`, + }, + ]; } // Check for slash before colon diff --git a/tools/spectral/ipa/rulesets/functions/IPA109EachCustomMethodMustBeGetOrPost.js b/tools/spectral/ipa/rulesets/functions/IPA109EachCustomMethodMustBeGetOrPost.js index bfa76b4e39..c1f3dc4c39 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA109EachCustomMethodMustBeGetOrPost.js +++ b/tools/spectral/ipa/rulesets/functions/IPA109EachCustomMethodMustBeGetOrPost.js @@ -1,11 +1,5 @@ import { isCustomMethodIdentifier } from './utils/resourceEvaluation.js'; -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; const RULE_NAME = 'xgen-IPA-109-custom-method-must-be-GET-or-POST'; const ERROR_MESSAGE = 'The HTTP method for custom methods must be GET or POST.'; @@ -20,16 +14,8 @@ export default (input, _, { path }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(input, path); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; function checkViolationsAndReturnErrors(input, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA109EachCustomMethodMustUseCamelCase.js b/tools/spectral/ipa/rulesets/functions/IPA109EachCustomMethodMustUseCamelCase.js index 65edf7bbb1..a84d0dd19d 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA109EachCustomMethodMustUseCamelCase.js +++ b/tools/spectral/ipa/rulesets/functions/IPA109EachCustomMethodMustUseCamelCase.js @@ -1,12 +1,6 @@ import { getCustomMethodName, isCustomMethodIdentifier } from './utils/resourceEvaluation.js'; -import { hasException } from './utils/exceptions.js'; import { casing } from '@stoplight/spectral-functions'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; const RULE_NAME = 'xgen-IPA-109-custom-method-must-use-camel-case'; @@ -18,16 +12,8 @@ export default (input, opts, { path }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(pathKey, path); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; function checkViolationsAndReturnErrors(pathKey, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js index 50fdc24fe2..9be8269c49 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js +++ b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js @@ -1,10 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectException, - collectAndReturnViolation, - handleInternalError, -} from './utils/collectionUtils.js'; +import { handleInternalError, evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; import { isCustomMethodIdentifier, getCustomMethodName, stripCustomMethodName } from './utils/resourceEvaluation.js'; import { hasCustomMethodOverride, VERB_OVERRIDE_EXTENSION, hasVerbOverride } from './utils/extensions.js'; import { validateOperationIdAndReturnErrors } from './utils/validations/validateOperationIdAndReturnErrors.js'; @@ -18,11 +12,6 @@ export default (input, _, { path }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - let methodName; let endpointUrl = resourcePath; @@ -40,12 +29,7 @@ export default (input, _, { path }) => { } const errors = validateOperationIdAndReturnErrors(methodName, endpointUrl, input, path); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); } catch (e) { return handleInternalError(RULE_NAME, path, e); } diff --git a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestHasItemsPerPageQueryParam.js b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestHasItemsPerPageQueryParam.js index 23862488d7..22b71bd8f4 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestHasItemsPerPageQueryParam.js +++ b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestHasItemsPerPageQueryParam.js @@ -1,5 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; import { getResourcePathItems, isResourceCollectionIdentifier, @@ -20,17 +19,6 @@ export default (input, _, { path, documentInventory }) => { return; } - // Check for exception - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkPaginationQueryParameterAndReturnErrors(input, path, 'itemsPerPage', 100, RULE_NAME); - - if (errors.length > 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestHasPageNumQueryParam.js b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestHasPageNumQueryParam.js index 6808dd1e63..18c652ac51 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestHasPageNumQueryParam.js +++ b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestHasPageNumQueryParam.js @@ -1,5 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; import { getResourcePathItems, isResourceCollectionIdentifier, @@ -20,17 +19,6 @@ export default (input, _, { path, documentInventory }) => { return; } - // Check for exception - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkPaginationQueryParameterAndReturnErrors(input, path, 'pageNum', 1, RULE_NAME); - - if (errors.length > 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestIncludeCountNotRequired.js b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestIncludeCountNotRequired.js index 457aab74ba..cb67a2420e 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestIncludeCountNotRequired.js +++ b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsRequestIncludeCountNotRequired.js @@ -1,5 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; import { getResourcePathItems, isResourceCollectionIdentifier, @@ -20,19 +19,19 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const includeCountParam = input?.parameters?.find((p) => p.name === 'includeCount' && p.in === 'query'); if (!includeCountParam) { return; } + let errors = []; if (includeCountParam.required) { - return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE); + errors = [ + { + path, + message: ERROR_MESSAGE, + }, + ]; } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsResponseDefineLinksArray.js b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsResponseDefineLinksArray.js index 2b8e427443..4ca4265c75 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsResponseDefineLinksArray.js +++ b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsResponseDefineLinksArray.js @@ -1,10 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { getResourcePathItems, isResourceCollectionIdentifier, @@ -19,10 +13,8 @@ const ERROR_MESSAGE = export default (input, _, { path, documentInventory }) => { const oas = documentInventory.resolved; const resourcePath = path[1]; - const mediaType = input; - if ( - !mediaType.endsWith('json') || + !input.endsWith('json') || !isResourceCollectionIdentifier(resourcePath) || (isResourceCollectionIdentifier(resourcePath) && isSingletonResource(getResourcePathItems(resourcePath, oas.paths))) ) { @@ -34,18 +26,8 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(listMethodResponse, RULE_NAME)) { - collectException(listMethodResponse, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(listMethodResponse.schema, oas, path); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, listMethodResponse, path); }; function checkViolationsAndReturnErrors(listResponseSchema, oas, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsResponseDefineResultsArray.js b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsResponseDefineResultsArray.js index 36a61741b2..785f7e6445 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsResponseDefineResultsArray.js +++ b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsResponseDefineResultsArray.js @@ -1,10 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { getResourcePathItems, isResourceCollectionIdentifier, @@ -19,10 +13,8 @@ const ERROR_MESSAGE = 'The response for collections must define an array of resu export default (input, _, { path, documentInventory }) => { const oas = documentInventory.resolved; const resourcePath = path[1]; - const mediaType = input; - if ( - !mediaType.endsWith('json') || + !input.endsWith('json') || !isResourceCollectionIdentifier(resourcePath) || isSingletonResource(getResourcePathItems(resourcePath, oas.paths)) ) { @@ -34,18 +26,8 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(listMethodResponse, RULE_NAME)) { - collectException(listMethodResponse, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(listMethodResponse.schema, oas, path); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, listMethodResponse, path); }; function checkViolationsAndReturnErrors(listResponseSchema, oas, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsUsePaginatedPrefix.js b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsUsePaginatedPrefix.js index a8d2a91fd4..a33fdb88c5 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA110CollectionsUsePaginatedPrefix.js +++ b/tools/spectral/ipa/rulesets/functions/IPA110CollectionsUsePaginatedPrefix.js @@ -1,10 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { getResourcePathItems, isResourceCollectionIdentifier, @@ -19,10 +13,8 @@ const ERROR_MESSAGE = 'List methods response must reference a paginated response export default (input, _, { path, documentInventory }) => { const oas = documentInventory.unresolved; const resourcePath = path[1]; - const mediaType = input; - if ( - !mediaType.endsWith('json') || + !input.endsWith('json') || !isResourceCollectionIdentifier(resourcePath) || isSingletonResource(getResourcePathItems(resourcePath, oas.paths)) ) { @@ -31,18 +23,8 @@ export default (input, _, { path, documentInventory }) => { const listMethodResponse = resolveObject(oas, path); - if (hasException(listMethodResponse, RULE_NAME)) { - collectException(listMethodResponse, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(listMethodResponse, oas, path); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, listMethodResponse, path); }; function checkViolationsAndReturnErrors(listMethodResponse, oas, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA112AvoidProjectFieldNames.js b/tools/spectral/ipa/rulesets/functions/IPA112AvoidProjectFieldNames.js index 9bed356e77..efcfaa479f 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA112AvoidProjectFieldNames.js +++ b/tools/spectral/ipa/rulesets/functions/IPA112AvoidProjectFieldNames.js @@ -1,10 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { resolveObject } from './utils/componentUtils.js'; import { splitCamelCase } from './utils/schemaUtils.js'; @@ -25,16 +19,8 @@ export default (input, options, { path, documentInventory }) => { return; } - if (hasException(property, RULE_NAME)) { - collectException(property, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(input, options, path); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, property, path); }; function checkViolationsAndReturnErrors(input, options, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA112BooleanFieldNamesAvoidIsPrefix.js b/tools/spectral/ipa/rulesets/functions/IPA112BooleanFieldNamesAvoidIsPrefix.js index 41b582dd93..00b2b67d70 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA112BooleanFieldNamesAvoidIsPrefix.js +++ b/tools/spectral/ipa/rulesets/functions/IPA112BooleanFieldNamesAvoidIsPrefix.js @@ -1,10 +1,4 @@ -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; -import { hasException } from './utils/exceptions.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { resolveObject } from './utils/componentUtils.js'; const RULE_NAME = 'xgen-IPA-112-boolean-field-names-avoid-is-prefix'; @@ -20,16 +14,8 @@ export default (input, options, { path, documentInventory }) => { return; } - if (hasException(property, RULE_NAME)) { - collectException(property, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(input, path); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, property, path); }; function checkViolationsAndReturnErrors(input, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA112FieldNamesAreCamelCase.js b/tools/spectral/ipa/rulesets/functions/IPA112FieldNamesAreCamelCase.js index 4ba51a4054..a0a693ab29 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA112FieldNamesAreCamelCase.js +++ b/tools/spectral/ipa/rulesets/functions/IPA112FieldNamesAreCamelCase.js @@ -1,11 +1,5 @@ import { casing } from '@stoplight/spectral-functions'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; -import { hasException } from './utils/exceptions.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { resolveObject } from './utils/componentUtils.js'; const RULE_NAME = 'xgen-IPA-112-field-names-are-camel-case'; @@ -20,16 +14,8 @@ export default (input, options, { path, documentInventory }) => { return; } - if (hasException(property, RULE_NAME)) { - collectException(property, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(input, path); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, property, path); }; function checkViolationsAndReturnErrors(input, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasNoDeleteMethod.js b/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasNoDeleteMethod.js index d53eb86646..3868a958fb 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasNoDeleteMethod.js +++ b/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasNoDeleteMethod.js @@ -4,13 +4,7 @@ import { isResourceCollectionIdentifier, hasDeleteMethod, } from './utils/resourceEvaluation.js'; -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; const RULE_NAME = 'xgen-IPA-113-singleton-must-not-have-delete-method'; const ERROR_MESSAGE = @@ -25,16 +19,8 @@ export default (input, opts, { path, documentInventory }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(input, path); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; function checkViolationsAndReturnErrors(input, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasNoId.js b/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasNoId.js index a8b3152456..1d62a1cc62 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasNoId.js +++ b/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasNoId.js @@ -4,14 +4,8 @@ import { isSingletonResource, isResourceCollectionIdentifier, } from './utils/resourceEvaluation.js'; -import { hasException } from './utils/exceptions.js'; import { getAllSuccessfulResponseSchemas } from './utils/methodUtils.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; const RULE_NAME = 'xgen-IPA-113-singleton-must-not-have-id'; const ERROR_MESSAGE = 'Singleton resources must not have a user-provided or system-generated ID.'; @@ -29,16 +23,8 @@ export default (input, opts, { path, documentInventory }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(input, path); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; function schemaHasIdProperty(schema) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasUpdateMethod.js b/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasUpdateMethod.js index fa31bad858..cba8c897e5 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasUpdateMethod.js +++ b/tools/spectral/ipa/rulesets/functions/IPA113SingletonHasUpdateMethod.js @@ -5,13 +5,7 @@ import { hasPutMethod, hasPatchMethod, } from './utils/resourceEvaluation.js'; -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; const RULE_NAME = 'xgen-IPA-113-singleton-should-have-update-method'; const ERROR_MESSAGE = @@ -26,16 +20,8 @@ export default (input, opts, { path, documentInventory }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(input, path); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; function checkViolationsAndReturnErrors(input, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA114ApiErrorHasBadRequestDetail.js b/tools/spectral/ipa/rulesets/functions/IPA114ApiErrorHasBadRequestDetail.js index b1ac069135..978e0fc8a9 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA114ApiErrorHasBadRequestDetail.js +++ b/tools/spectral/ipa/rulesets/functions/IPA114ApiErrorHasBadRequestDetail.js @@ -1,4 +1,4 @@ -import { collectAdoption, collectAndReturnViolation, handleInternalError } from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; const RULE_NAME = 'xgen-IPA-114-api-error-has-bad-request-detail'; @@ -11,11 +11,7 @@ const RULE_NAME = 'xgen-IPA-114-api-error-has-bad-request-detail'; */ export default (input, _, { path, documentInventory }) => { const errors = checkViolationsAndReturnErrors(input, documentInventory, path); - if (errors.length > 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; /** @@ -63,6 +59,11 @@ function checkViolationsAndReturnErrors(apiErrorSchema, documentInventory, path) return []; } catch (e) { handleInternalError(RULE_NAME, path, e); - return [{ path, message: `Internal error during validation: ${e.message}` }]; + return [ + { + path, + message: `Internal error during validation: ${e.message}`, + }, + ]; } } diff --git a/tools/spectral/ipa/rulesets/functions/IPA114AuthenticatedEndpointsHaveAuthErrors.js b/tools/spectral/ipa/rulesets/functions/IPA114AuthenticatedEndpointsHaveAuthErrors.js index fd3a809a36..440296ce4a 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA114AuthenticatedEndpointsHaveAuthErrors.js +++ b/tools/spectral/ipa/rulesets/functions/IPA114AuthenticatedEndpointsHaveAuthErrors.js @@ -1,10 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; const RULE_NAME = 'xgen-IPA-114-authenticated-endpoints-have-auth-errors'; @@ -33,18 +27,8 @@ export default (input, _, { path }) => { return; } - // Check for exception at operation level - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(input.responses, path); - if (errors.length > 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; function checkViolationsAndReturnErrors(responses, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA114ErrorResponsesReferToApiError.js b/tools/spectral/ipa/rulesets/functions/IPA114ErrorResponsesReferToApiError.js index 02d0ede00f..f55723051a 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA114ErrorResponsesReferToApiError.js +++ b/tools/spectral/ipa/rulesets/functions/IPA114ErrorResponsesReferToApiError.js @@ -1,10 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { resolveObject } from './utils/componentUtils.js'; import { getSchemaNameFromRef } from './utils/methodUtils.js'; @@ -22,18 +16,8 @@ export default (input, _, { path, documentInventory }) => { const apiResponseObject = resolveObject(oas, path); const errorCode = path[path.length - 1]; - // Check for exception at response level - if (hasException(apiResponseObject, RULE_NAME)) { - collectException(apiResponseObject, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(apiResponseObject, oas, path, errorCode); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, apiResponseObject, path); }; function checkViolationsAndReturnErrors(apiResponseObject, oas, path, errorCode) { @@ -47,11 +31,21 @@ function checkViolationsAndReturnErrors(apiResponseObject, oas, path, errorCode) const schemaName = getSchemaNameFromRef(apiResponseObject.$ref); const responseSchema = resolveObject(oas, ['components', 'responses', schemaName]); if (!responseSchema) { - return [{ path, message: `${errorCode} response must define content with a valid reference.` }]; + return [ + { + path, + message: `${errorCode} response must define content with a valid reference.`, + }, + ]; } content = responseSchema.content; } else { - return [{ path, message: `${errorCode} response must define content with ApiError schema reference.` }]; + return [ + { + path, + message: `${errorCode} response must define content with ApiError schema reference.`, + }, + ]; } for (const [mediaType, mediaTypeObj] of Object.entries(content)) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA114ParameterizedPathsHave404NotFound.js b/tools/spectral/ipa/rulesets/functions/IPA114ParameterizedPathsHave404NotFound.js index da92f7ad9f..11f0ed674d 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA114ParameterizedPathsHave404NotFound.js +++ b/tools/spectral/ipa/rulesets/functions/IPA114ParameterizedPathsHave404NotFound.js @@ -1,10 +1,4 @@ -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; const RULE_NAME = 'xgen-IPA-114-parameterized-paths-have-404-not-found'; const ERROR_MESSAGE = `Parameterized path must define a 404 response.`; @@ -24,18 +18,8 @@ export default (input, _, { path }) => { return; } - // Check for exception at operation level - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(input.responses, path); - if (errors.length > 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; /**