Skip to content

Commit

Permalink
Don't use object spread (for compatibility reasons)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruzicka committed Mar 27, 2020
1 parent 2924e93 commit daed1e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Expand Up @@ -171,14 +171,14 @@ class ToJsonSchema {

commmonPostProcessDefault(type, schema, value) { // eslint-disable-line no-unused-vars
if (this.options.required) {
return {...schema, required: true}
return merge({}, schema, {required: true})
}
return schema
}

objectPostProcessDefault(schema, obj) {
if (this.options.objects.additionalProperties === false && Object.getOwnPropertyNames(obj).length > 0) {
return {...schema, additionalProperties: false}
return merge({}, schema, {additionalProperties: false})
}
return schema
}
Expand Down
6 changes: 4 additions & 2 deletions test/schema/objects.js
Expand Up @@ -2,6 +2,7 @@

const should = require('chai').should()
const omit = require('lodash.omit')
const merge = require('lodash.merge')

const testSchemaWithAndWithoutMerge = require('../helpers/testSchema').tesSchemaWithAndWithoutArrayMerge
const testSchemaNormal = require('../helpers/testSchema').testSchemaWithoutArrayMerge
Expand Down Expand Up @@ -211,7 +212,7 @@ describe('Objects', () => {
it('should return proper schema when postProcessFnc is used', () => {
const options = {
postProcessFnc: (type, schema, value, defaultFunc) =>
(type === 'integer') ? {...schema, required: true} : defaultFunc(type, schema, value),
(type === 'integer') ? merge({}, schema, {required: true}) : defaultFunc(type, schema, value),
}

const instance = {
Expand Down Expand Up @@ -341,7 +342,8 @@ describe('Objects', () => {
it('Custom objects.postProcessFnc makes properties required on parent type level', () => {
const options = {
objects: {
postProcessFnc: (schema, obj, defaultFnc) => ({...defaultFnc(schema, obj), required: Object.getOwnPropertyNames(obj)}),
postProcessFnc: (schema, obj, defaultFnc) =>
(merge({}, defaultFnc(schema, obj), {required: Object.getOwnPropertyNames(obj)})),
},
}
testSchemaNormal({}, {type: 'object', required: []}, options)
Expand Down

0 comments on commit daed1e1

Please sign in to comment.