Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
14 changes: 14 additions & 0 deletions tools/spectral/ipa/__tests__/IPA104ValidOperationID.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,18 @@ testRule('xgen-IPA-104-valid-operation-id', [
},
errors: [],
},
{
name: 'valid method that needs ignoreList',
document: {
paths: {
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/fts/indexes/{indexId} ': {
get: {
operationId: 'getGroupClusterFtsIndex',
'x-xgen-operation-id-override': 'getClusterFtsIndex',
},
},
},
},
errors: [],
},
]);
14 changes: 14 additions & 0 deletions tools/spectral/ipa/__tests__/IPA105ValidOperationID.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,18 @@ testRule('xgen-IPA-105-valid-operation-id', [
},
errors: [],
},
{
name: 'valid method that needs ignoreList',
document: {
paths: {
'/api/atlas/v2/groups/{groupId}/hosts/{processId}/fts/metrics': {
get: {
operationId: 'listGroupHostFtsMetrics',
'x-xgen-operation-id-override': 'listHostFtsMetrics',
},
},
},
},
errors: [],
},
]);
14 changes: 14 additions & 0 deletions tools/spectral/ipa/__tests__/IPA106ValidOperationID.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,18 @@ testRule('xgen-IPA-106-valid-operation-id', [
},
errors: [],
},
{
name: 'valid method that needs ignoreList',
document: {
paths: {
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/fts/indexes': {
post: {
operationId: 'createGroupClusterFtsIndex',
'x-xgen-operation-id-override': 'createClusterFtsIndex',
},
},
},
},
errors: [],
},
]);
14 changes: 14 additions & 0 deletions tools/spectral/ipa/__tests__/IPA107ValidOperationID.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,18 @@ testRule('xgen-IPA-107-valid-operation-id', [
},
errors: [],
},
{
name: 'valid method that needs ignoreList',
document: {
paths: {
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/fts/indexes/{indexId}': {
put: {
operationId: 'updateGroupClusterFtsIndex',
'x-xgen-operation-id-override': 'updateClusterFtsIndex',
},
},
},
},
errors: [],
},
]);
14 changes: 14 additions & 0 deletions tools/spectral/ipa/__tests__/IPA108ValidOperationID.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,18 @@ testRule('xgen-IPA-108-valid-operation-id', [
},
errors: [],
},
{
name: 'valid method that needs ignoreList',
document: {
paths: {
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/fts/indexes/{indexId}': {
delete: {
operationId: 'deleteGroupClusterFtsIndex',
'x-xgen-operation-id-override': 'deleteClusterFtsIndex',
},
},
},
},
errors: [],
},
]);
14 changes: 14 additions & 0 deletions tools/spectral/ipa/__tests__/IPA109ValidOperationID.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,18 @@ testRule('xgen-IPA-109-valid-operation-id', [
},
errors: [],
},
{
name: 'valid method that needs ignoreList',
document: {
paths: {
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/fts/indexes/{indexId}:test': {
delete: {
operationId: 'testGroupClusterFtsIndex',
'x-xgen-operation-id-override': 'testClusterFtsIndex',
},
},
},
},
errors: [],
},
]);
2 changes: 2 additions & 0 deletions tools/spectral/ipa/rulesets/IPA-104.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ rules:
function: 'IPA104ValidOperationID'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add to the rule description an explanation of the ignore list option and what it is used for? Similar to

##### Configuration
This rule includes two configuration options:
- `ignoreList`: Words that are allowed to maintain their specific casing (e.g., "API", "AWS", "DNS")
- `grammaticalWords`: Common words that can remain lowercase in titles (e.g., "and", "or", "the")

functionOptions:
methodName: 'get'
ignoreList:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ignoreList:
ignorePluralizationList:

[Nit] Name suggestion, I feel like ignoreList can be interpreted as operation id ignore list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will go back and change now

- 'Fts'
2 changes: 2 additions & 0 deletions tools/spectral/ipa/rulesets/IPA-105.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,5 @@ rules:
function: 'IPA105ValidOperationID'
functionOptions:
methodName: 'list'
ignoreList:
- 'Fts'
2 changes: 2 additions & 0 deletions tools/spectral/ipa/rulesets/IPA-106.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@ rules:
function: 'IPA106ValidOperationID'
functionOptions:
methodName: 'create'
ignoreList:
- 'Fts'
2 changes: 2 additions & 0 deletions tools/spectral/ipa/rulesets/IPA-107.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ rules:
function: 'IPA107ValidOperationID'
functionOptions:
methodName: 'update'
ignoreList:
- 'Fts'
2 changes: 2 additions & 0 deletions tools/spectral/ipa/rulesets/IPA-108.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ rules:
function: 'IPA108ValidOperationID'
functionOptions:
methodName: 'delete'
ignoreList:
- 'Fts'

functions:
- IPA108DeleteMethodResponseShouldNotHaveSchema
Expand Down
3 changes: 3 additions & 0 deletions tools/spectral/ipa/rulesets/IPA-109.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ rules:
given: '$.paths[*][*]'
then:
function: 'IPA109ValidOperationID'
functionOptions:
ignoreList:
- 'Fts'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { validateOperationIdAndReturnErrors } from './utils/validations/validate

const RULE_NAME = 'xgen-IPA-104-valid-operation-id';

export default (input, { methodName }, { path, documentInventory }) => {
export default (input, { methodName, ignoreList }, { path, documentInventory }) => {
const resourcePath = path[1];
const oas = documentInventory.resolved;
const resourcePaths = getResourcePathItems(resourcePath, oas.paths);
Expand All @@ -23,7 +23,7 @@ export default (input, { methodName }, { path, documentInventory }) => {
if (hasMethodVerbOverride(input, methodName)) {
methodName = input[VERB_OVERRIDE_EXTENSION].verb;
}
const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path);
const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path, ignoreList);

return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { validateOperationIdAndReturnErrors } from './utils/validations/validate

const RULE_NAME = 'xgen-IPA-105-valid-operation-id';

export default (input, { methodName }, { path, documentInventory }) => {
export default (input, { methodName, ignoreList }, { path, documentInventory }) => {
const resourcePath = path[1];
const oas = documentInventory.resolved;
const resourcePaths = getResourcePathItems(resourcePath, oas.paths);
Expand All @@ -24,7 +24,7 @@ export default (input, { methodName }, { path, documentInventory }) => {
}

try {
const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path);
const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path, ignoreList);
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,7 +5,7 @@ import { validateOperationIdAndReturnErrors } from './utils/validations/validate

const RULE_NAME = 'xgen-IPA-106-valid-operation-id';

export default (input, { methodName }, { path }) => {
export default (input, { methodName, ignoreList }, { path }) => {
const resourcePath = path[1];

if (hasCustomMethodOverride(input) || isCustomMethodIdentifier(resourcePath)) {
Expand All @@ -17,7 +17,7 @@ export default (input, { methodName }, { path }) => {
}

try {
const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path);
const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path, ignoreList);
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,7 +5,7 @@ import { validateOperationIdAndReturnErrors } from './utils/validations/validate

const RULE_NAME = 'xgen-IPA-107-valid-operation-id';

export default (input, { methodName }, { path }) => {
export default (input, { methodName, ignoreList }, { path }) => {
const resourcePath = path[1];

if (isCustomMethodIdentifier(resourcePath) || hasCustomMethodOverride(input)) {
Expand All @@ -17,7 +17,7 @@ export default (input, { methodName }, { path }) => {
}

try {
const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path);
const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path, ignoreList);
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,7 +5,7 @@ import { validateOperationIdAndReturnErrors } from './utils/validations/validate

const RULE_NAME = 'xgen-IPA-108-valid-operation-id';

export default (input, { methodName }, { path }) => {
export default (input, { methodName, ignoreList }, { path }) => {
const resourcePath = path[1];

if (isCustomMethodIdentifier(resourcePath) || hasCustomMethodOverride(input)) {
Expand All @@ -17,7 +17,7 @@ export default (input, { methodName }, { path }) => {
}

try {
const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path);
const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path, ignoreList);
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,7 +5,7 @@ import { validateOperationIdAndReturnErrors } from './utils/validations/validate

const RULE_NAME = 'xgen-IPA-109-valid-operation-id';

export default (input, _, { path }) => {
export default (input, { ignoreList }, { path }) => {
const resourcePath = path[1];

if (!isCustomMethodIdentifier(resourcePath) && !hasCustomMethodOverride(input)) {
Expand All @@ -28,7 +28,7 @@ export default (input, _, { path }) => {
return;
}

const errors = validateOperationIdAndReturnErrors(methodName, endpointUrl, input, path);
const errors = validateOperationIdAndReturnErrors(methodName, endpointUrl, input, path, ignoreList);
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 @@ -10,7 +10,7 @@ const CAMEL_CASE_WITH_ABBREVIATIONS = /[A-Z]+(?![a-z])|[A-Z]*[a-z]+/g;
* @param method the standard method name (create, update, get etc.), custom method name, or empty string (only for legacy custom methods)
* @param path the path for the endpoint
*/
export function generateOperationID(method, path) {
export function generateOperationID(method, path, ignoreList = []) {
if (!path) {
return method;
}
Expand Down Expand Up @@ -40,7 +40,7 @@ export function generateOperationID(method, path) {

let opID = verb;
for (let i = 0; i < nouns.length - 1; i++) {
opID += inflection.singularize(nouns[i]);
opID += singularize(nouns[i], ignoreList);
}

// singularize final noun, dependent on resource identifier - leave custom nouns alone
Expand All @@ -49,7 +49,7 @@ export function generateOperationID(method, path) {
!camelCaseCustomMethod) ||
verb === 'create'
) {
nouns[nouns.length - 1] = inflection.singularize(nouns[nouns.length - 1]);
nouns[nouns.length - 1] = singularize(nouns[nouns.length - 1], ignoreList);
}

opID += nouns.pop();
Expand Down Expand Up @@ -92,3 +92,10 @@ function deriveActionVerb(method) {
function capitalize(val) {
return String(val).charAt(0).toUpperCase() + String(val).slice(1);
}

function singularize(noun, ignoreList = []) {
if (!ignoreList.includes(noun)) {
return inflection.singularize(noun);
}
return noun;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const TOO_LONG_OP_ID_ERROR_MESSAGE =
* @param path the path to the operation object being evaluated, used for error reporting with Spectral.
* @returns {[{path: string[], message: string}]} an array of error objects, each containing a path and a message, or an empty array if no errors are found.
*/
export function validateOperationIdAndReturnErrors(methodName, resourcePath, operationObject, path) {
export function validateOperationIdAndReturnErrors(methodName, resourcePath, operationObject, path, ignoreList) {
const operationId = operationObject.operationId;
const expectedOperationId = generateOperationID(methodName, resourcePath);
const expectedOperationId = generateOperationID(methodName, resourcePath, ignoreList);

const operationIdPath = path.concat(['operationId']);

Expand Down
Loading