Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/spectral/ipa/ipa-spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Original file line number Diff line number Diff line change
@@ -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.';
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.';
Expand All @@ -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);
};
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 { isSingleResourceIdentifier } from './utils/resourceEvaluation.js';

const RULE_NAME = 'xgen-IPA-108-delete-response-should-be-empty';
Expand All @@ -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<string>} - errors array ()
* @param {object} input - The object to verify
* @param {Array<string>} jsonPathArray - The jsonPathArray covering location in the OpenAPI schema
* @return {Array<{path: Array<string>, message: string}>} - errors array ()
*/
function checkViolationsAndReturnErrors(input, jsonPathArray) {
const errors = [];
Expand Down
20 changes: 2 additions & 18 deletions tools/spectral/ipa/rulesets/functions/IPA108ValidOperationID.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -25,24 +19,21 @@ 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) {
try {
// 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.';
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

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

Expand All @@ -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);
}
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,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);
};
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,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);
};
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,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);
};
Loading
Loading