diff --git a/tools/spectral/ipa/__tests__/IPA106CreateMethodRequestBodyIsGetResponse.test.js b/tools/spectral/ipa/__tests__/IPA106CreateMethodRequestBodyIsGetResponse.test.js index 3eff93d3bd..e08a589ba3 100644 --- a/tools/spectral/ipa/__tests__/IPA106CreateMethodRequestBodyIsGetResponse.test.js +++ b/tools/spectral/ipa/__tests__/IPA106CreateMethodRequestBodyIsGetResponse.test.js @@ -563,7 +563,7 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [ content: { 'application/vnd.atlas.2023-01-01+json': { schema: { - $ref: '#/components/schemas/SchemaTwoResponse', + $ref: '#/components/schemas/SchemaThree', }, }, }, diff --git a/tools/spectral/ipa/__tests__/IPA107UpdateMethodRequestBodyIsGetResponse.test.js b/tools/spectral/ipa/__tests__/IPA107UpdateMethodRequestBodyIsGetResponse.test.js index 996cfd4593..effc9505ca 100644 --- a/tools/spectral/ipa/__tests__/IPA107UpdateMethodRequestBodyIsGetResponse.test.js +++ b/tools/spectral/ipa/__tests__/IPA107UpdateMethodRequestBodyIsGetResponse.test.js @@ -681,7 +681,7 @@ testRule('xgen-IPA-107-update-method-request-body-is-get-method-response', [ content: { 'application/vnd.atlas.2023-01-01+json': { schema: { - $ref: '#/components/schemas/SchemaTwoRequest', + $ref: '#/components/schemas/SchemaThree', }, 'x-xgen-IPA-exception': { 'xgen-IPA-107-update-method-request-body-is-get-method-response': 'reason', @@ -689,7 +689,7 @@ testRule('xgen-IPA-107-update-method-request-body-is-get-method-response', [ }, 'application/vnd.atlas.2024-01-01+json': { schema: { - $ref: '#/components/schemas/SchemaTwoRequest', + $ref: '#/components/schemas/SchemaThree', }, 'x-xgen-IPA-exception': { 'xgen-IPA-107-update-method-request-body-is-get-method-response': 'reason', diff --git a/tools/spectral/ipa/ipa-spectral.yaml b/tools/spectral/ipa/ipa-spectral.yaml index 477efa0e83..50b2192fa9 100644 --- a/tools/spectral/ipa/ipa-spectral.yaml +++ b/tools/spectral/ipa/ipa-spectral.yaml @@ -129,3 +129,7 @@ overrides: - '**#/paths/~1api~1atlas~1v2~1groups~1%7BgroupId%7D' rules: xgen-IPA-104-get-method-response-has-no-input-fields: 'off' + - files: # To be removed in CLOUDP-337392 + - '**#/paths/~1api~1atlas~1v2~1groups~1%7BgroupId%7D~1pushBasedLogExport' + rules: + xgen-IPA-106-create-method-request-has-no-readonly-fields: 'off' diff --git a/tools/spectral/ipa/rulesets/functions/IPA105EachResourceHasListMethod.js b/tools/spectral/ipa/rulesets/functions/IPA105EachResourceHasListMethod.js index b8cae59f6b..1fdde1bab5 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA105EachResourceHasListMethod.js +++ b/tools/spectral/ipa/rulesets/functions/IPA105EachResourceHasListMethod.js @@ -4,8 +4,7 @@ import { getResourcePathItems, isResourceCollectionIdentifier, } from './utils/resourceEvaluation.js'; -import { hasException } from './utils/exceptions.js'; -import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; const RULE_NAME = 'xgen-IPA-105-resource-has-list'; const ERROR_MESSAGE = 'APIs must provide a List method for resources.'; @@ -17,16 +16,8 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(oas.paths[input], RULE_NAME)) { - collectException(oas.paths[input], RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(oas.paths[input], input, path); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, oas.paths[input], path); }; function checkViolationsAndReturnErrors(pathItem, input, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA105ListMethodHasNoRequestBody.js b/tools/spectral/ipa/rulesets/functions/IPA105ListMethodHasNoRequestBody.js index 5bc5ea7c9e..2f6b61b456 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA105ListMethodHasNoRequestBody.js +++ b/tools/spectral/ipa/rulesets/functions/IPA105ListMethodHasNoRequestBody.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,9 @@ export default (input, _, { 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(getOperationObject, path) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA105ListMethodResponseIsGetMethodResponse.js b/tools/spectral/ipa/rulesets/functions/IPA105ListMethodResponseIsGetMethodResponse.js index 62ec032466..cb0a843897 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA105ListMethodResponseIsGetMethodResponse.js +++ b/tools/spectral/ipa/rulesets/functions/IPA105ListMethodResponseIsGetMethodResponse.js @@ -4,13 +4,7 @@ import { isSingletonResource, } from './utils/resourceEvaluation.js'; import { resolveObject } from './utils/componentUtils.js'; -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { getSchemaRef, getSchemaNameFromRef, getResponseOfGetMethodByMediaType } from './utils/methodUtils.js'; import { schemaIsPaginated } from './utils/schemaUtils.js'; @@ -38,11 +32,6 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(listMethodResponse, RULE_NAME)) { - collectException(listMethodResponse, RULE_NAME, path); - return; - } - // Get list response schema from ref or inline schema let resolvedListSchema; const listSchemaRef = getSchemaRef(listMethodResponse.schema); @@ -70,11 +59,7 @@ export default (input, _, { path, documentInventory }) => { getMethodResponseContentPerMediaType ); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, listMethodResponse, path); }; function checkViolationsAndReturnErrors(path, listMethodResultItems, getMethodResponseContent) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA105ListResponseCodeShouldBe200OK.js b/tools/spectral/ipa/rulesets/functions/IPA105ListResponseCodeShouldBe200OK.js index 333fb36cf6..2a878c4d35 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA105ListResponseCodeShouldBe200OK.js +++ b/tools/spectral/ipa/rulesets/functions/IPA105ListResponseCodeShouldBe200OK.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, @@ -21,15 +20,7 @@ export default (input, _, { path, documentInventory }) => { ) { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } const errors = checkResponseCodeAndReturnErrors(input, '200', path, RULE_NAME, ERROR_MESSAGE); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - return collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA105ValidOperationID.js b/tools/spectral/ipa/rulesets/functions/IPA105ValidOperationID.js index 72080851de..7b2a3d9b96 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA105ValidOperationID.js +++ b/tools/spectral/ipa/rulesets/functions/IPA105ValidOperationID.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 } from './utils/resourceEvaluation.js'; import { isInvalidListMethod } from './utils/methodLogic.js'; import { hasCustomMethodOverride, hasMethodVerbOverride, VERB_OVERRIDE_EXTENSION } from './utils/extensions.js'; @@ -25,23 +19,13 @@ export default (input, { methodName }, { path, documentInventory }) => { 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); - } - - return 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/IPA106CreateMethodRequestBodyIsGetResponse.js b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodRequestBodyIsGetResponse.js index a28a6324d2..dde7a4ad4c 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodRequestBodyIsGetResponse.js +++ b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodRequestBodyIsGetResponse.js @@ -5,8 +5,7 @@ import { isSingletonResource, } from './utils/resourceEvaluation.js'; import { resolveObject } from './utils/componentUtils.js'; -import { hasException } from './utils/exceptions.js'; -import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; import { getResponseOfGetMethodByMediaType } from './utils/methodUtils.js'; import { checkRequestResponseResourceEqualityAndReturnErrors } from './utils/validations/checkRequestResponseResourceEqualityAndReturnErrors.js'; @@ -43,11 +42,6 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(postRequestContentPerMediaType, RULE_NAME)) { - collectException(postRequestContentPerMediaType, RULE_NAME, path); - return; - } - const postRequestContentPerMediaTypeUnresolved = resolveObject(unresolvedOas, path); const getResponseContentPerMediaTypeUnresolved = getResponseOfGetMethodByMediaType( mediaType, @@ -65,10 +59,5 @@ export default (input, _, { path, documentInventory }) => { 'Get', ERROR_MESSAGE ); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, postRequestContentPerMediaType, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodRequestBodyIsRequestSuffixedObject.js b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodRequestBodyIsRequestSuffixedObject.js index a428acb448..ddeec574c4 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodRequestBodyIsRequestSuffixedObject.js +++ b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodRequestBodyIsRequestSuffixedObject.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, isCustomMethodIdentifier, @@ -27,15 +26,6 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(contentPerMediaType, RULE_NAME)) { - collectException(contentPerMediaType, RULE_NAME, path); - return; - } - const errors = checkSchemaRefSuffixAndReturnErrors(path, contentPerMediaType, 'Request', RULE_NAME); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, contentPerMediaType, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodRequestHasNoReadonlyFields.js b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodRequestHasNoReadonlyFields.js index 9c35c8a1f1..a1d541856d 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodRequestHasNoReadonlyFields.js +++ b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodRequestHasNoReadonlyFields.js @@ -5,8 +5,7 @@ import { isSingletonResource, } from './utils/resourceEvaluation.js'; import { resolveObject } from './utils/componentUtils.js'; -import { hasException } from './utils/exceptions.js'; -import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; import { checkForbiddenPropertyAttributesAndReturnErrors } from './utils/validations/checkForbiddenPropertyAttributesAndReturnErrors.js'; const RULE_NAME = 'xgen-IPA-106-create-method-request-has-no-readonly-fields'; @@ -29,11 +28,6 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(requestContentPerMediaType, RULE_NAME)) { - collectException(requestContentPerMediaType, RULE_NAME, path); - return; - } - const errors = checkForbiddenPropertyAttributesAndReturnErrors( requestContentPerMediaType.schema, 'readOnly', @@ -41,10 +35,5 @@ export default (input, _, { path, documentInventory }) => { [], ERROR_MESSAGE ); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, requestContentPerMediaType, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodResponseCodeIs201Created.js b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodResponseCodeIs201Created.js index 1ad7467148..0c685a7916 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodResponseCodeIs201Created.js +++ b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodResponseCodeIs201Created.js @@ -4,8 +4,7 @@ import { isResourceCollectionIdentifier, isSingletonResource, } from './utils/resourceEvaluation.js'; -import { hasException } from './utils/exceptions.js'; -import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; import { checkResponseCodeAndReturnErrors } from './utils/validations/checkResponseCodeAndReturnErrors.js'; const RULE_NAME = 'xgen-IPA-106-create-method-response-code-is-201'; @@ -22,14 +21,6 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - const errors = checkResponseCodeAndReturnErrors(input, '201', path, RULE_NAME, ERROR_MESSAGE); - 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/IPA106CreateMethodResponseIsGetMethodResponse.js b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodResponseIsGetMethodResponse.js index 1c31dc5d7e..8b99933033 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodResponseIsGetMethodResponse.js +++ b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodResponseIsGetMethodResponse.js @@ -4,13 +4,7 @@ import { isSingletonResource, } from './utils/resourceEvaluation.js'; import { resolveObject } from './utils/componentUtils.js'; -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { getSchemaRef, getResponseOfGetMethodByMediaType } from './utils/methodUtils.js'; const RULE_NAME = 'xgen-IPA-106-create-method-response-is-get-method-response'; @@ -37,11 +31,6 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(createMethodResponse, RULE_NAME)) { - collectException(createMethodResponse, RULE_NAME, path); - return; - } - // Ignore if there is no matching Get method const getMethodResponseContentPerMediaType = getResponseOfGetMethodByMediaType(mediaType, resourcePath, oas); if (!getMethodResponseContentPerMediaType) { @@ -49,12 +38,7 @@ export default (input, _, { path, documentInventory }) => { } const errors = checkViolationsAndReturnErrors(path, createMethodResponse, getMethodResponseContentPerMediaType); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, createMethodResponse, path); }; function checkViolationsAndReturnErrors(path, createMethodResponseContent, getMethodResponseContent) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodShouldNotHaveQueryParameters.js b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodShouldNotHaveQueryParameters.js index eac26dc20b..4f15e782db 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodShouldNotHaveQueryParameters.js +++ b/tools/spectral/ipa/rulesets/functions/IPA106CreateMethodShouldNotHaveQueryParameters.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, isCustomMethodIdentifier, @@ -37,16 +31,8 @@ export default (input, opts, { path, documentInventory }) => { return; } - if (hasException(postMethod, RULE_NAME)) { - collectException(postMethod, RULE_NAME, path); - return; - } - const errors = checkViolationsAndReturnErrors(postMethod.parameters, path, opts); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, postMethod, path); }; function checkViolationsAndReturnErrors(postMethodParameters, path, opts) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA106ValidOperationID.js b/tools/spectral/ipa/rulesets/functions/IPA106ValidOperationID.js index 207f95c827..47842e6adf 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA106ValidOperationID.js +++ b/tools/spectral/ipa/rulesets/functions/IPA106ValidOperationID.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/IPA107UpdateMethodMustNotHaveQueryParams.js b/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodMustNotHaveQueryParams.js index 35e9a8f557..7b5b8cf9cd 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodMustNotHaveQueryParams.js +++ b/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodMustNotHaveQueryParams.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, @@ -38,16 +32,8 @@ export default (input, opts, { path, documentInventory, rule }) => { return; } - if (hasException(input, ruleName)) { - collectException(input, ruleName, path); - return; - } - const errors = checkViolationsAndReturnErrors(input.parameters, path, ruleName, opts); - if (errors.length !== 0) { - return collectAndReturnViolation(path, ruleName, errors); - } - collectAdoption(path, ruleName); + return evaluateAndCollectAdoptionStatus(errors, ruleName, input, path); }; function checkViolationsAndReturnErrors(postMethodParameters, path, ruleName, opts) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestBodyIsGetResponse.js b/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestBodyIsGetResponse.js index 3a43a539ff..da6e85a217 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestBodyIsGetResponse.js +++ b/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestBodyIsGetResponse.js @@ -5,8 +5,7 @@ import { isSingletonResource, } from './utils/resourceEvaluation.js'; import { resolveObject } from './utils/componentUtils.js'; -import { hasException } from './utils/exceptions.js'; -import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; import { getGETMethodResponseSchemaFromPathItem } from './utils/methodUtils.js'; import { checkRequestResponseResourceEqualityAndReturnErrors } from './utils/validations/checkRequestResponseResourceEqualityAndReturnErrors.js'; @@ -43,11 +42,6 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(updateMethodRequest, RULE_NAME)) { - collectException(updateMethodRequest, RULE_NAME, path); - return; - } - // Ignore if there is no matching Get method const getMethodResponse = getGETMethodResponseSchemaFromPathItem(oas.paths[resourcePath], mediaType); if (!getMethodResponse) { @@ -70,10 +64,5 @@ export default (input, _, { path, documentInventory }) => { 'Get', ERROR_MESSAGE ); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, updateMethodRequest, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestBodyIsUpdateRequestSuffixedObject.js b/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestBodyIsUpdateRequestSuffixedObject.js index c451baf7a3..f152c193b9 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestBodyIsUpdateRequestSuffixedObject.js +++ b/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestBodyIsUpdateRequestSuffixedObject.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 { resolveObject } from './utils/componentUtils.js'; import { getResourcePathItems, @@ -26,14 +25,6 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(contentPerMediaType, RULE_NAME)) { - collectException(contentPerMediaType, RULE_NAME, path); - return; - } - const errors = checkSchemaRefSuffixAndReturnErrors(path, contentPerMediaType, 'UpdateRequest', RULE_NAME); - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, contentPerMediaType, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestHasNoReadonlyFields.js b/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestHasNoReadonlyFields.js index b5072599f5..49efdc4ddf 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestHasNoReadonlyFields.js +++ b/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodRequestHasNoReadonlyFields.js @@ -5,8 +5,7 @@ import { isSingletonResource, } from './utils/resourceEvaluation.js'; import { resolveObject } from './utils/componentUtils.js'; -import { hasException } from './utils/exceptions.js'; -import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; import { checkForbiddenPropertyAttributesAndReturnErrors } from './utils/validations/checkForbiddenPropertyAttributesAndReturnErrors.js'; const RULE_NAME = 'xgen-IPA-107-update-method-request-has-no-readonly-fields'; @@ -37,11 +36,6 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(requestContentPerMediaType, RULE_NAME)) { - collectException(requestContentPerMediaType, RULE_NAME, path); - return; - } - const errors = checkForbiddenPropertyAttributesAndReturnErrors( requestContentPerMediaType.schema, 'readOnly', @@ -49,10 +43,5 @@ export default (input, _, { path, documentInventory }) => { [], ERROR_MESSAGE ); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, requestContentPerMediaType, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodResponseIsGetMethodResponse.js b/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodResponseIsGetMethodResponse.js index 3d395e3b05..85433662af 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodResponseIsGetMethodResponse.js +++ b/tools/spectral/ipa/rulesets/functions/IPA107UpdateMethodResponseIsGetMethodResponse.js @@ -5,13 +5,7 @@ import { isSingletonResource, } from './utils/resourceEvaluation.js'; import { resolveObject } from './utils/componentUtils.js'; -import { hasException } from './utils/exceptions.js'; -import { - collectAdoption, - collectAndReturnViolation, - collectException, - handleInternalError, -} from './utils/collectionUtils.js'; +import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js'; import { getSchemaRef, getGETMethodResponseSchemaFromPathItem } from './utils/methodUtils.js'; const RULE_NAME = 'xgen-IPA-107-update-method-response-is-get-method-response'; @@ -46,11 +40,6 @@ export default (input, _, { path, documentInventory }) => { return; } - if (hasException(updateMethodResponse, RULE_NAME)) { - collectException(updateMethodResponse, RULE_NAME, path); - return; - } - // Ignore if there is no matching Get method const getMethodResponseContentPerMediaType = getGETMethodResponseSchemaFromPathItem( oas.paths[resourcePath], @@ -61,12 +50,7 @@ export default (input, _, { path, documentInventory }) => { } const errors = checkViolationsAndReturnErrors(path, updateMethodResponse, getMethodResponseContentPerMediaType); - - if (errors.length !== 0) { - return collectAndReturnViolation(path, RULE_NAME, errors); - } - - collectAdoption(path, RULE_NAME); + return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, updateMethodResponse, path); }; function checkViolationsAndReturnErrors(path, updateMethodResponseContent, getMethodResponseContent) { diff --git a/tools/spectral/ipa/rulesets/functions/IPA107UpdateResponseCodeShouldBe200OK.js b/tools/spectral/ipa/rulesets/functions/IPA107UpdateResponseCodeShouldBe200OK.js index 82c8f969ec..73446ca74e 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA107UpdateResponseCodeShouldBe200OK.js +++ b/tools/spectral/ipa/rulesets/functions/IPA107UpdateResponseCodeShouldBe200OK.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, @@ -24,14 +23,6 @@ export default (input, _, { path, documentInventory, rule }) => { return; } - if (hasException(input, ruleName)) { - collectException(input, ruleName, path); - return; - } - const errors = checkResponseCodeAndReturnErrors(input, '200', path, ruleName, ERROR_MESSAGE); - if (errors.length !== 0) { - return collectAndReturnViolation(path, ruleName, errors); - } - collectAdoption(path, ruleName); + return evaluateAndCollectAdoptionStatus(errors, ruleName, input, path); }; diff --git a/tools/spectral/ipa/rulesets/functions/IPA107ValidOperationID.js b/tools/spectral/ipa/rulesets/functions/IPA107ValidOperationID.js index 94875e702b..65f1769ccb 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA107ValidOperationID.js +++ b/tools/spectral/ipa/rulesets/functions/IPA107ValidOperationID.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); }