Skip to content

Add runtime support for V2 int64 string-encoded fields#1814

Merged
mbroshi-stripe merged 3 commits intomasterfrom
mbroshi/v2-int64-as-string
Mar 18, 2026
Merged

Add runtime support for V2 int64 string-encoded fields#1814
mbroshi-stripe merged 3 commits intomasterfrom
mbroshi/v2-int64-as-string

Conversation

@mbroshi-stripe
Copy link
Copy Markdown
Contributor

@mbroshi-stripe mbroshi-stripe commented Mar 15, 2026

Why?

V2 APIs represent int64 fields as JSON strings on the wire (e.g. "12345" instead of 12345) to avoid precision loss. The SDK should transparently convert between native Ruby Integer and this wire format so users don't need to handle string encoding themselves.

What?

  • Added field_encodings class method and coerce_value/coerce_params helpers to RequestParams for request-side coercion (Integer → String), handling scalars, nested objects, and arrays
  • Generated code will declare field_encodings on V2 params classes and call coerce_params in service methods for Hash-typed params
  • Response-side coercion uses StripeObject#field_encodings (existing pattern from codegen)

@mbroshi-stripe mbroshi-stripe force-pushed the mbroshi/v2-int64-as-string branch from ae1145c to b6ec428 Compare March 15, 2026 22:04
@mbroshi-stripe mbroshi-stripe changed the title Mbroshi/v2 int64 as string Add runtime support for V2 int64 string-encoded fields Mar 15, 2026
@mbroshi-stripe mbroshi-stripe changed the base branch from private-preview to master March 15, 2026 22:32
@mbroshi-stripe mbroshi-stripe marked this pull request as ready for review March 16, 2026 00:46
@mbroshi-stripe mbroshi-stripe requested a review from a team as a code owner March 16, 2026 00:46
@mbroshi-stripe mbroshi-stripe requested review from Copilot and jar-stripe and removed request for a team March 16, 2026 00:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds request-side runtime coercion so V2 int64 fields are serialized as JSON strings (to match V2 wire format), complementing existing response-side decoding.

Changes:

  • Adds field_encodings, coerce_value, and coerce_params to Stripe::RequestParams and applies coercion during #to_h.
  • Introduces recursive encoding schemas for nested objects/arrays, with :int64_string leaf handling.
  • Expands RequestParams unit tests to cover new coercion behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/stripe/request_params.rb Implements encoding schema support and coercion helpers for request serialization.
test/stripe/request_params_test.rb Adds tests validating scalar/array/object coercion and #to_h integration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mbroshi-stripe mbroshi-stripe force-pushed the mbroshi/v2-int64-as-string branch from a8fc711 to 9ed5327 Compare March 18, 2026 12:56
@mbroshi-stripe mbroshi-stripe merged commit 63c6581 into master Mar 18, 2026
15 checks passed
@mbroshi-stripe mbroshi-stripe deleted the mbroshi/v2-int64-as-string branch March 18, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants