Skip to content

Commit b00db53

Browse files
committed
Fixes #3376 - Check to make sure properties is the root (first) instance of properties before running plugins
1 parent f620497 commit b00db53

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/specmap/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ class SpecMap {
9494
}
9595
}
9696
else {
97-
const parent = path[path.length - 1]
97+
const parentIndex = path.length - 1
98+
const parent = path[parentIndex]
99+
const indexOfFirstProperties = path.indexOf('properties')
100+
const isRootProperties = parent === 'properties' && parentIndex === indexOfFirstProperties
98101

99102
for (const key of Object.keys(obj)) {
100103
const val = obj[key]
@@ -103,7 +106,8 @@ class SpecMap {
103106
if (lib.isObject(val)) {
104107
yield* traverse(val, updatedPath, patch)
105108
}
106-
if (parent !== 'properties' && key === pluginObj.key) {
109+
110+
if (!isRootProperties && key === pluginObj.key) {
107111
yield pluginObj.plugin(val, key, updatedPath, specmap, patch)
108112
}
109113
}

test/specmap/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,38 @@ describe('specmap', function () {
728728
})
729729
})
730730
})
731+
732+
it('should merge sub-properties', function () {
733+
return mapSpec({
734+
plugins: [plugins.refs, plugins.allOf],
735+
spec: {
736+
properties: {
737+
test: {
738+
type: 'object',
739+
properties: {
740+
color: {
741+
type: 'integer'
742+
}
743+
}
744+
}
745+
}
746+
}
747+
}).then((res) => {
748+
expect(res.errors.length).toEqual(0)
749+
expect(res.spec).toEqual({
750+
properties: {
751+
test: {
752+
type: 'object',
753+
properties: {
754+
color: {
755+
type: 'integer'
756+
}
757+
}
758+
}
759+
}
760+
})
761+
})
762+
})
731763
})
732764

733765
describe('context', function () {

0 commit comments

Comments
 (0)