fix(sdk): preserve payment instrument extensions - #333
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Spellcheck now passes after adding the four project terms used by the generated model and regression test. The remaining The Google CLA check is a separate contributor action and is not a code failure. |
Problem
AP2 allows a payment instrument
typeto define additional properties, but the generated PythonPaymentInstrumentcurrently uses Pydantic's defaultextra='ignore'behavior. Callers can pass a type-specific field without an error, yet the field disappears beforemodel_dump()and is therefore absent from the signed mandate.The Python x402 sample exposes the effect: it supplies
payee_addressandfacilitator, but the generated model drops both values before signing.Root cause
The common Payment Instrument JSON Schema leaves additional properties implicit.
datamodel-code-generatordoes not translate that implicit JSON Schema default into an explicit Pydantic setting, so the generated model silently ignores fields outsideid,type, anddescription.Fix
additionalProperties: trueexplicitly inpayment_instrument.json.PaymentInstrument, which addsConfigDict(extra='allow').The test checks the full boundary requested in #299:
PaymentInstrumentconstruction andmodel_dump()retain the fields.PaymentMandateretains them.PaymentMandateChain.parse()return the same signed values on the typed instrument.This keeps the common AP2 model extensible as described by the specification. Validation of a type-specific field's format and semantics remains the responsibility of that payment-instrument profile; this change only prevents accepted values from being silently removed.
Verification
upstream/mainin a clean Python 3.12 environment.git diff --checkpassed.Addresses the remaining extension-preservation item in #299. It does not overlap the verified-amount fix in #300 or the
(type, id)matching fix in #301.