mirror of
https://github.com/justinrainbow/json-schema.git
synced 2025-06-02 03:44:53 +02:00
fix: create deep copy before checking each sub schema in oneOf when only check_mode_apply_defaults is set (#795)
Fixes https://github.com/jsonrainbow/json-schema/issues/510
This commit is contained in:
parent
649793d2b9
commit
a94f60c332
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Create deep copy before checking each sub schema in oneOf ([#791](https://github.com/jsonrainbow/json-schema/pull/791))
|
||||
- Create deep copy before checking each sub schema in anyOf ([#792](https://github.com/jsonrainbow/json-schema/pull/792))
|
||||
- Correctly set the schema ID when passing it as assoc array ([#794](https://github.com/jsonrainbow/json-schema/pull/794))
|
||||
- Create deep copy before checking each sub schema in oneOf when only check_mode_apply_defaults is set ([#795](https://github.com/jsonrainbow/json-schema/pull/795))
|
||||
|
||||
### Changed
|
||||
- Used PHPStan's int-mask-of<T> type where applicable ([#779](https://github.com/jsonrainbow/json-schema/pull/779))
|
||||
|
@ -359,13 +359,13 @@ class UndefinedConstraint extends Constraint
|
||||
$allErrors = [];
|
||||
$matchedSchemas = [];
|
||||
$startErrors = $this->getErrors();
|
||||
$coerce = $this->factory->getConfig(self::CHECK_MODE_COERCE_TYPES);
|
||||
$coerceOrDefaults = $this->factory->getConfig(self::CHECK_MODE_COERCE_TYPES | self::CHECK_MODE_APPLY_DEFAULTS);
|
||||
|
||||
foreach ($schema->oneOf as $oneOf) {
|
||||
try {
|
||||
$this->errors = [];
|
||||
|
||||
$oneOfValue = $coerce ? DeepCopy::copyOf($value) : $value;
|
||||
$oneOfValue = $coerceOrDefaults ? DeepCopy::copyOf($value) : $value;
|
||||
$this->checkUndefined($oneOfValue, $oneOf, $path, $i);
|
||||
if (count($this->getErrors()) === 0) {
|
||||
$matchedSchemas[] = ['schema' => $oneOf, 'value' => $oneOfValue];
|
||||
|
@ -70,6 +70,56 @@ JSON
|
||||
,
|
||||
'checkMode' => Constraint::CHECK_MODE_COERCE_TYPES
|
||||
],
|
||||
'oneOf with apply defaults should not affect value passed to each sub schema (#510)' => [
|
||||
'input' => <<<JSON
|
||||
{"foo": {"name": "bar"}}
|
||||
JSON
|
||||
,
|
||||
'schema' => <<<JSON
|
||||
{
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"foo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {"enum":["baz"],"default":"baz"},
|
||||
"meta": {"enum":["baz"],"default":"baz"}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"foo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {"enum":["bar"],"default":"bar"},
|
||||
"meta": {"enum":["bar"],"default":"bar"}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"foo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {"enum":["zip"],"default":"zip"},
|
||||
"meta": {"enum":["zip"],"default":"zip"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON
|
||||
,
|
||||
'checkMode' => Constraint::CHECK_MODE_APPLY_DEFAULTS
|
||||
],
|
||||
'anyOf with apply defaults should not affect value passed to each sub schema (#711)' => [
|
||||
'input' => <<<JSON
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user