From 702f7cb207bd460c800be77ee890ed5628b695f5 Mon Sep 17 00:00:00 2001 From: Dustin Popp Date: Fri, 8 Sep 2023 13:32:06 -0500 Subject: [PATCH] chore: apply suggestions from code review Co-authored-by: Phil Adams --- packages/ruleset/src/functions/schema-naming-convention.js | 7 +++++-- packages/ruleset/test/schema-naming-convention.test.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/ruleset/src/functions/schema-naming-convention.js b/packages/ruleset/src/functions/schema-naming-convention.js index e9d573e6a..efd649995 100644 --- a/packages/ruleset/src/functions/schema-naming-convention.js +++ b/packages/ruleset/src/functions/schema-naming-convention.js @@ -388,7 +388,7 @@ function computeRefsAtPaths(nodes) { * @returns {string} - the name of the referenced schema at a given path, or undefined */ function getSchemaNameAtPath(path, pathToReferencesMap) { - if (!path && typeof path !== 'string') { + if (!path || typeof path !== 'string') { return; } @@ -399,6 +399,9 @@ function getSchemaNameAtPath(path, pathToReferencesMap) { // See the function documentation above for more info. let pathBuilder = ''; for (const pathSegment of path.split('.')) { + if (pathBuilder) { + pathBuilder += '.'; + } pathBuilder += `${pathSegment}`; const schemaReference = pathToReferencesMap[pathBuilder]; @@ -431,7 +434,7 @@ function getSchemaNameAtPath(path, pathToReferencesMap) { * @returns {string} - the name of the schema (e.g. 'Thing') */ function getSchemaNameFromReference(reference) { - if (!reference && typeof reference !== 'string') { + if (!reference || typeof reference !== 'string') { return; } diff --git a/packages/ruleset/test/schema-naming-convention.test.js b/packages/ruleset/test/schema-naming-convention.test.js index 8b574b841..9d2121e10 100644 --- a/packages/ruleset/test/schema-naming-convention.test.js +++ b/packages/ruleset/test/schema-naming-convention.test.js @@ -291,7 +291,7 @@ describe(`Spectral rule: ${ruleId}`, () => { expect(results).toHaveLength(0); }); - it('Prototype schema in PUT request body is correctly named but the path is not resource-oriented', async () => { + it('Prototype schema in PUT request body is incorrectly named but the path is not resource-oriented', async () => { const testDocument = makeCopy(rootDocument); testDocument.components.schemas.Mess = {};