Skip to content

Commit

Permalink
Update camara-casing-convention.js
Browse files Browse the repository at this point in the history
  • Loading branch information
VijayKesharwani authored Oct 31, 2023
1 parent f891d6f commit 235d3fc
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions lint_function/camara-casing-convention.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
// lint_function/camara-casing-convention.js

export default async function (input) {
const errors = [];
const suggestions = [];

// Iterate over the paths in the API definition
for (const path in input.paths) {
for (const method in input.paths[path]) {
const operation = input.paths[path][method];
if (operation.operationId) {
const operationId = operation.operationId;
// Check if operationId is not in camelCase
if (!isCamelCase(operationId)) {
errors.push(operationId);
suggestions.push(`OperationId '${operationId}' should be in camelCase.`);
}
} else {
errors.push('OperationId missing');
suggestions.push(`OperationId is missing for the ${method} operation on path '${path}'.`);
}
for (const operationId of input) {
if (!isCamelCase(operationId)) {
errors.push(operationId);
suggestions.push(`OperationId '${operationId}' should be in camelCase.`);
}
}

// Check if any errors were found
if (errors.length > 0) {
console.log('Hint: OperationId casing convention issues found: ' + suggestions.join(', '));
}
}

function isCamelCase(str) {
// Check if a string is in camelCase
return /^[a-z][a-zA-Z0-9]*$/.test(str);
}

0 comments on commit 235d3fc

Please sign in to comment.