Skip to content

Properties of nested objects aren't always serialized #79

@florianreinhart

Description

@florianreinhart

If a nested object has a property, which is also present in the parent, it is not serialized.

I've already created a test case.

'use strict'

const test = require('tap').test
const build = require('..')

test('nested objects with same properties', (t) => {
  t.plan(1)

  const schema = {
    title: 'nested objects with same propertie',
    type: 'object',
    properties: {
      stringProperty: {
        type: 'string'
      },
      objectProperty: {
        type: 'object',
        additionalProperties: true
      }
    }
  }
  const stringify = build(schema)

  try {
    const value = stringify({
      stringProperty: 'string1',
      objectProperty: {
        stringProperty: 'string2',
        numberProperty: 42
      }
    })
    t.is(value, '{"stringProperty":"string1","objectProperty":{"stringProperty":"string2","numberProperty":42}}')
  } catch (e) {
    t.fail()
  }
})

Expected result

{
  "stringProperty": "string1",
  "objectProperty": {
    "stringProperty": "string2",
    "numberProperty": 42
  }
}

Actual result

{
  "stringProperty": "string1",
  "objectProperty": {
    "numberProperty": 42
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions