Skip to content

Commit

Permalink
chore: apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Phil Adams <[email protected]>
  • Loading branch information
dpopp07 and padamstx authored Sep 8, 2023
1 parent ec5b8c0 commit 702f7cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/ruleset/src/functions/schema-naming-convention.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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];

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ruleset/test/schema-naming-convention.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down

0 comments on commit 702f7cb

Please sign in to comment.