Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The test case didn't have an exception on an invalid schema, updated

},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,15 @@ 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',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The test case didn't have an exception on an invalid schema, updated

},
'x-xgen-IPA-exception': {
'xgen-IPA-107-update-method-request-body-is-get-method-response': 'reason',
},
},
'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',
Expand Down
4 changes: 4 additions & 0 deletions tools/spectral/ipa/ipa-spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- '**#/paths/~1api~1atlas~1v2~1groups~1%7BgroupId%7D~1pushBasedLogExport'
rules:
xgen-IPA-106-create-method-request-has-no-readonly-fields: 'off'
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
};
20 changes: 2 additions & 18 deletions tools/spectral/ipa/rulesets/functions/IPA105ValidOperationID.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand All @@ -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);
};
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -29,22 +28,12 @@ export default (input, _, { path, documentInventory }) => {
return;
}

if (hasException(requestContentPerMediaType, RULE_NAME)) {
collectException(requestContentPerMediaType, RULE_NAME, path);
return;
}

const errors = checkForbiddenPropertyAttributesAndReturnErrors(
requestContentPerMediaType.schema,
'readOnly',
path,
[],
ERROR_MESSAGE
);

if (errors.length !== 0) {
return collectAndReturnViolation(path, RULE_NAME, errors);
}

collectAdoption(path, RULE_NAME);
return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, requestContentPerMediaType, path);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -37,24 +31,14 @@ 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) {
return;
}

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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
Loading
Loading