Skip to content

Release 1.11

Choose a tag to compare

@igorpocta igorpocta released this 22 Apr 07:49
· 59 commits to main since this release

What's Changed

Bug Fixes

  • Fix TypeError when a parent DTO has an invalid enum and a valid non-nullable typed array on the same level — the shared denormalizer instance (singleton in TypeResolver) reused $this->errors across recursive denormalize() calls. An error from a parent property (e.g. invalid enum value) leaked into nested ObjectType / ArrayType element processing, was re-thrown as a ValidationException, caught as null, and then assigned to a non-nullable property — producing a PHP TypeError (HTTP 500) instead of the expected ValidationException (HTTP 422) with the real field path.

    Concretely: sending {"client": {"entityType": "Legal Entity", "addresses": [...]}} with a bad entityType would fail with Cannot assign null to property ClientSimpleRequest::$addresses of type array instead of a clean validation error on client.entityType.

    The fix isolates errors produced inside each denormalize() invocation from errors inherited from a parent invocation (snapshot + array_diff_key), switches setPropertyValue() from count-based to value-aware error detection (catches same-key overwrites), and adds a defensive guard against assigning null to non-nullable properties.

Tests

  • Add EnumWithArrayErrorIsolationTest with 11 regression cases covering:
    • invalid enum + valid nested array (top-level and nested DTO)
    • valid enum + invalid nested element
    • invalid enum + invalid nested element (both errors surfaced)
    • empty / missing / null nested arrays
    • deep recursion error isolation
    • constructor-based DTO reproduction
    • exact production reproduction via fromJson

Affected files

  • src/Denormalizer/Denormalizer.php — denormalize(), createWithConstructor(), setPropertyValue()

Full Changelog: v1.10...v1.11