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
andinspect
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:
- Model Name: Clearly identifies the object type.
- Property Details: Displays key-value pairs of populated fields.
Example Outputs
- PHP
- Python
- Ruby
- Go
$order = OrderBuilder::init()
->orderId(123)
->status('completed')
->total(99.99)
->build();
echo $order; // Output: Order [orderId: 123, status: completed, total: 99.99]
order = Order(order_id=123, status='completed', total=99.99)
print(order) # Output: Order(order_id=123, status=completed, total=99.99)
order = Order.new(123, 'completed', 99.99)
puts(order) # Output: <Order order_id: 123, status: completed, total: 99.99>
order := models.Order{
OrderId: 123,
Status: "completed",
Total: 99.99,
}
fmt.Println(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.