Skip to content

Commit

Permalink
Merge pull request #1108 from owenconti/bug/3376-properties-keyboard-fix
Browse files Browse the repository at this point in the history
Fixes #3376 - Keyword properties fix
  • Loading branch information
shockey committed Jul 18, 2017
2 parents f620497 + b00db53 commit 570013f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/specmap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ class SpecMap {
}
}
else {
const parent = path[path.length - 1]
const parentIndex = path.length - 1
const parent = path[parentIndex]
const indexOfFirstProperties = path.indexOf('properties')
const isRootProperties = parent === 'properties' && parentIndex === indexOfFirstProperties

for (const key of Object.keys(obj)) {
const val = obj[key]
Expand All @@ -103,7 +106,8 @@ class SpecMap {
if (lib.isObject(val)) {
yield* traverse(val, updatedPath, patch)
}
if (parent !== 'properties' && key === pluginObj.key) {

if (!isRootProperties && key === pluginObj.key) {
yield pluginObj.plugin(val, key, updatedPath, specmap, patch)
}
}
Expand Down
32 changes: 32 additions & 0 deletions test/specmap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,38 @@ describe('specmap', function () {
})
})
})

it('should merge sub-properties', function () {
return mapSpec({
plugins: [plugins.refs, plugins.allOf],
spec: {
properties: {
test: {
type: 'object',
properties: {
color: {
type: 'integer'
}
}
}
}
}
}).then((res) => {
expect(res.errors.length).toEqual(0)
expect(res.spec).toEqual({
properties: {
test: {
type: 'object',
properties: {
color: {
type: 'integer'
}
}
}
}
})
})
})
})

describe('context', function () {
Expand Down

0 comments on commit 570013f

Please sign in to comment.