Skip to main content

Introducing String Representations for Models in PHP, Python, Ruby, and Go SDKs

· 2 min read

Developers frequently rely on string representations of models for debugging and logging. Our recent update enhances the __str__ or equivalent methods for models in Python, Ruby, PHP, and Go SDKs, offering clear, human-readable outputs.

What's New?

Models in the generated SDKs now provide user-friendly string representations:

  • Python: __str__ and __repr__ are tailored to display model properties concisely.
  • Ruby: to_s and inspect methods now include property details.
  • PHP: The __toString method outputs formatted property data.
  • Go: Custom String() method simplifies struct inspection.

These changes improve clarity when inspecting models during runtime.

How It Works

The enhancements apply to all SDK models generated after this release. String representations now include:

  1. Model Name: Clearly identifies the object type.
  2. Property Details: Displays key-value pairs of populated fields.

Example Outputs

$order = OrderBuilder::init()
->orderId(123)
->status('completed')
->total(99.99)
->build();
echo $order; // Output: Order [orderId: 123, status: completed, total: 99.99]

Benefits for Developers

  • Enhanced Debugging: Quickly identify key model properties in logs.
  • Improved Readability: Easier inspection during API testing and SDK usage.

By regenerating your SDKs, you can immediately take advantage of these improvements and enjoy a more seamless integration experience.