Repository navigation
Isolate PropertyProxy attribute mutations from the shared underlying property - #151
torian257x wants to merge 1 commit into
Conversation
|
This PR addresses the B4 feedback from PR #150. I am an AI assistant working on behalf of @torian257x.
Approach: PropertyProxy::getAttributes() now merges local proxy attributes with the underlying property's attributes via a generic merge. When the same attribute FQCN appears in both lists, the proxy's local version wins. This covers ReadOnly, WriteOnly, Deprecated and any future attribute types automatically. The old approach (enumerating SchemaName, JsonPointer, Required in processReference()) was removed. SchemaName is still set per-instance on the proxy. Everything else inherits. Why correct: resolveReference() includes $required in its cache key, so different requiredness produces separate Properties (never a proxy). Inherited Required is always correct. |
- Strip verbose comments from PropertyProxy::getAttributes() docblock - Remove removeAttribute() from AttributesTrait (callers now use filterAttributes) - Replace removeAttribute calls with filterAttributes - Move test to tests/Issues/Issue/Issue151Test.php - Add clear docblock explaining the merge mechanism
50b5d69 to
c3babca
Compare
…property PropertyProxy::addAttribute() delegated to the shared underlying property, so an attribute added to one proxy (e.g. by a post processor) leaked onto every sibling property referencing the same $def. Store proxy-added attributes locally (via AttributesTrait) and merge them in getAttributes(), local attributes winning by type. Inherited ReadOnly/WriteOnly/Deprecated and the SchemaName/JsonPointer overrides are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
7afdff4 to
200333d
Compare
|
@wol-soft — heads up, I rebased this PR onto current
Proving test |
Use tests/Schema/Issues/151/*.json instead of inline PHP-array schemas, matching the rest of the issue test suite, and fold the duplicate-JsonPointer regression test into Issue151Test alongside the original leak test rather than a separate class. The regression test now also asserts the JsonPointer attribute's actual value and that both the composed property and its plain sibling still function correctly, not just an attribute count.
|
@torian257x thanks for the cleanup. This currently introduces a regression on top of the leak fix. Reproduced with a schema where a $ref'd property foo is defined in both an allOf and an anyOf branch (plus a warmup sibling whose only job is to consume the first, non-proxy resolution of the shared $ref, forcing foo to resolve as a PropertyProxy). That makes JsonPointer synthesis run twice against the same proxy instance, leaving two Compare (based on your commit): https://github.com/wol-soft/php-json-schema-model-generator/compare/claude/pr-151-review-oaznmm |
Summary
Rebased onto current
masterand narrowed to the one issue that still reproduces there.The attribute merge-on-read you asked for in the original B4 review is already present on
master—PropertyProxy::getAttributes()reads from the underlying property, soReadOnly,WriteOnlyandDeprecatedare already inherited. Verified with tests; those pass onmasterunchanged.What still reproduces on
masteris an attribute leak:PropertyProxy::addAttribute()delegates to the shared underlying property. So when two properties$refthe same$def(the second becomes aPropertyProxysharing the first's underlying object) and something adds an attribute to one proxy — e.g. a post processor tagging a single propertyDeprecated— it lands on the shared underlying and every sibling reference inherits it.Fix
PropertyProxynow stores added attributes on itself (viaAttributesTrait, whose backing array is madeprotected) instead of on the underlying, andgetAttributes()merges them in with local attributes winning by type. The existingSchemaNamerename andoverrideJsonPointerbehaviour are unchanged.Test
tests/Issues/Issue/Issue151Test.php— a post processor addsDeprecatedtoref_two; the test assertsref_onedoes not inherit it. Fails onmaster, passes with this change.