Capture extensions on the discriminator - #2
Merged
Conversation
CONTEXT.md states that an extension is "captured on every model that can
carry one". Discriminator was the exception: the reader built it from
propertyName and mapping and dropped every x- key alongside them, so an
extension nested inside a discriminator was unreachable from the parsed
Specification.
This matters because the standard mapping is single-valued — it maps one
property value to one schema. A union whose members are told apart by a
combination of properties cannot be expressed with it. Appwrite's spec
carries the full rule set in `x-mapping`:
"discriminator": {
"propertyName": "type",
"mapping": { "string": ".../attributeString" },
"x-mapping": {
".../attributeEmail": { "type": "string", "format": "email" },
".../attributeString": { "type": "string" }
}
}
Five of its attribute models share `type: "string"` and differ only by
`format`, so `mapping` can name just one of them and consumers reading
only `mapping` silently collapse the other four into it.
The reader already has Value::extensions(); this passes its result to the
constructor. Nothing here interprets the extension — it is captured and
handed to the consumer, which is the contract every other model follows.
Greptile SummaryThe PR preserves
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The new constructor argument is optional and trailing, all discriminator construction paths remain compatible, and object-form extensions are captured consistently through the existing shared helper. Important Files Changed
Reviews (1): Last reviewed commit: "fix: capture extensions on the discrimin..." | Re-trigger Greptile |
ChiragAgg5k
added a commit
to appwrite/sdk-generator
that referenced
this pull request
Aug 14, 2026
A discriminated union whose members are told apart by more than one
property cannot be expressed with the standard `mapping`, which maps a
single property value to a single schema. Five attribute models share
`type: "string"` and differ only by `format`, so `mapping` names just
one of them and the spec carries the real rule set in `x-mapping`.
Reading only `mapping` collapsed attributeEmail, attributeEnum,
attributeUrl and attributeIp into attributeString: getAttribute() and
getColumn() returned the wrong model, silently, with format dropped.
Ten cases became six. The dispatch is emitted into runtime request code
in 22 templates, so every SDK was affected, and nothing failed loudly.
Cases are now ordered most-specific-first, because the one-condition
`{type: string}` case would otherwise match an email before its own
two-condition case was ever tested.
`x-mapping` was unreachable until utopia-php/openapi#2, which captures
extensions on Discriminator the way every other model already does;
composer.lock moves to that merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CONTEXT.md states that an extension is "captured on every model that can carry one; never interpreted."
Discriminatorwas the one model that did not follow it — the reader built it frompropertyNameandmappingand discarded everyx-key sitting beside them, so an extension nested inside a discriminator was unreachable from the parsedSpecification.Why it matters
The standard
mappingis single-valued: it maps one property value to one schema. A union whose members are distinguished by a combination of properties cannot be expressed with it at all.Appwrite's spec hits this directly. Five of its attribute models share
type: "string"and differ only byformat, somappingcan name exactly one of them:A consumer reading only
mappingsees 6 of the 10 union members and silently collapses email, enum, url and ip intoattributeString. With no way to reachx-mapping, there is no workaround on the consumer side.The change
Discriminatorgains anextensionsarray, defaulting to[], and the reader passesValue::extensions($value)— the helper it already uses for every other model. Nothing here interprets the extension; it is captured and handed to the consumer, which is the contract the rest of the library follows.Compatibility
Additive.
extensionsis a new optional constructor argument in last position, so existing construction sites are unaffected, and the string form of the discriminator keeps defaulting to[].Tests
Two added to
tests/Schema/ReaderTest.php, both verified to fail without thesrc/change and pass with it:test_discriminator_captures_extensions—x-mappingandx-propertyNamessurvive alongsidepropertyNameandmappingtest_discriminator_extensions_default_to_empty— the string form, and the object form with no extensions, both yield[]composer check(lint, pint, rector, phpunit) is green: 44 tests, 363 assertions.