diff --git a/src/specmap/helpers.js b/src/specmap/helpers.js index 57c0b6bcf..4a7b121e2 100644 --- a/src/specmap/helpers.js +++ b/src/specmap/helpers.js @@ -1,4 +1,7 @@ -export const freelyNamedKeyParents = [ +const freelyNamedKeyParents = [ + 'properties', +] +const freelyNamedPaths = [ // Swagger 2.0 'definitions', 'parameters', @@ -11,3 +14,12 @@ export const freelyNamedKeyParents = [ 'components/parameters', 'components/securitySchemes', ] + +export function isFreelyNamed(parent) { + const parentKey = parent[parent.length - 1] + const parentStr = parent.join('/') + return ( + (freelyNamedKeyParents.indexOf(parentKey) > -1) || + (freelyNamedPaths.indexOf(parentStr) > -1) + ) +} diff --git a/src/specmap/lib/all-of.js b/src/specmap/lib/all-of.js index 76d10576c..6953d960c 100644 --- a/src/specmap/lib/all-of.js +++ b/src/specmap/lib/all-of.js @@ -1,4 +1,4 @@ -import {freelyNamedKeyParents} from '../helpers' +import {isFreelyNamed} from '../helpers' export default { key: 'allOf', @@ -11,9 +11,7 @@ export default { } const parent = fullPath.slice(0, -1) - const parentStr = parent.join('/') - - if (freelyNamedKeyParents.indexOf(parentStr) > -1) { + if (isFreelyNamed(parent)) { return } diff --git a/src/specmap/lib/refs.js b/src/specmap/lib/refs.js index 9ad5ceeb1..f8a22b811 100644 --- a/src/specmap/lib/refs.js +++ b/src/specmap/lib/refs.js @@ -2,7 +2,7 @@ import {fetch} from 'cross-fetch' import url from 'url' import lib from '../lib' import createError from '../lib/create-error' -import {freelyNamedKeyParents} from '../helpers' +import {isFreelyNamed} from '../helpers' const ABSOLUTE_URL_REGEXP = new RegExp('^([a-z]+://|//)', 'i') @@ -42,13 +42,11 @@ const plugin = { key: '$ref', plugin: (ref, key, fullPath, specmap) => { const parent = fullPath.slice(0, -1) - const parentStr = parent.join('/') - const baseDoc = specmap.getContext(fullPath).baseDoc - - if (freelyNamedKeyParents.indexOf(parentStr) > -1) { + if (isFreelyNamed(parent)) { return } + const baseDoc = specmap.getContext(fullPath).baseDoc if (typeof ref !== 'string') { return new JSONRefError('$ref: must be a string (JSON-Ref)', { $ref: ref, diff --git a/test/specmap/all-of.js b/test/specmap/all-of.js index 60de3e514..4deeeeab7 100644 --- a/test/specmap/all-of.js +++ b/test/specmap/all-of.js @@ -212,6 +212,11 @@ describe('allOf', function () { a: 123 } }, + properties: { + allOf: { + a: 123 + } + }, } return mapSpec({ diff --git a/test/specmap/refs.js b/test/specmap/refs.js index 98b21ec92..b7cc8fece 100644 --- a/test/specmap/refs.js +++ b/test/specmap/refs.js @@ -378,6 +378,9 @@ describe('refs', function () { }, securityDefinitions: { $ref: '#/a' + }, + properties: { + $ref: '#/a' } }, plugins: [refs], @@ -395,6 +398,9 @@ describe('refs', function () { }, securityDefinitions: { $ref: '#/a' + }, + properties: { + $ref: '#/a' } }) })