geraintluff / jsv4-php

A (coercive) JSON Schema v4 Validator for PHP
Other
114 stars 31 forks source link

Coerce not recursive #31

Open oniramarf opened 7 years ago

oniramarf commented 7 years ago

Hi, I am having an issue while using the coerce functionality. I'm using the coerce functionality in order to add properties to my JSON object according to schema. The issue I've found is that if the object has several layers of properties, only the first is filled with missing properties. For instance, if this is my schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "foo": {
            "type": "object",
            "properties": {
                "foobar": {"type": "numeric"}
            },
            "required": ["foobar"]
        },
        "bar": { "type": "object" }
    },
    "required": ["foo", "bar"]
}

and the JSON to coerce is:

{"bar": {"name":"John"}}

the result is

{"bar": {"name":"John"}, "foo": {}}

while I expected that foo would have been

{"bar": {"name":"John"}, "foo": {"foobar": 0}}

Could you please help me with this issue?