forked from camaraproject/QualityOnDemand
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f891d6f
commit 235d3fc
Showing
1 changed file
with
4 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |