DodoPayments.Schema (dodo_payments v0.1.0)

Copy Markdown View Source

Minimal response schema support.

Known fields become atom-keyed struct fields. Unknown fields are retained under :extra, allowing Dodo to add response data without waiting for an SDK release. Model declarations may attach field-specific types without changing decoding; nested response objects remain string-keyed maps for compatibility.

use DodoPayments.Schema accepts legacy atom fields such as fields: [:id] and typed fields such as fields: [id: String.t()]. Both forms may be mixed; each field name must occur exactly once. Declared enum values decode to atoms; values introduced after this SDK release decode to DodoPayments.UnknownEnum without creating atoms dynamically. JSON numbers retain Jason's normal integer/float representation; response decoding does not synthesize Decimal values. Request-side Decimal values encode as exact decimal strings, while endpoints that specify integer minor units should receive integers.

The configured response byte limit bounds wire input, not transient heap use: JSON parsing and schema construction necessarily allocate beyond the body size.

Summary

Functions

Casts known response fields into a schema while retaining unknown fields.

Functions

cast(module, value)

@spec cast(module(), term()) :: term()

Casts known response fields into a schema while retaining unknown fields.

iex> product =
...>   DodoPayments.Schema.cast(
...>     DodoPayments.Product,
...>     %{"product_id" => "pdt_1", "future_field" => true}
...>   )
iex> {product.product_id, product.extra}
{"pdt_1", %{"future_field" => true}}