Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InstanceResource properties are camelCase, leading to confusion against snake_case API documentation #743

Open
stevebauman opened this issue Aug 17, 2022 · 1 comment
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@stevebauman
Copy link

stevebauman commented Aug 17, 2022

The Twilio API documentation shows PHP examples with return structures containing properties that are snake_case:

https://www.twilio.com/docs/usage/api/applications

{
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "api_version": "2010-04-01",
  "date_created": "Mon, 22 Aug 2011 20:59:45 +0000",
  "date_updated": "Tue, 18 Aug 2015 16:48:57 +0000",
  "friendly_name": "Phone Me",
  "message_status_callback": "http://www.example.com/sms-status-callback",
}

Yet these properties are transformed into camelCase, leading to confusion when transforming these instances ->toArray() and expecting the same response that the API documentation displays:

$this->properties = [
'accountSid' => Values::array_get($payload, 'account_sid'),
'apiVersion' => Values::array_get($payload, 'api_version'),
'dateCreated' => Deserialize::dateTime(Values::array_get($payload, 'date_created')),
'dateUpdated' => Deserialize::dateTime(Values::array_get($payload, 'date_updated')),
'friendlyName' => Values::array_get($payload, 'friendly_name'),
'messageStatusCallback' => Values::array_get($payload, 'message_status_callback'),

// [
//     "accountSid" => "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
//     "apiVersion" => "2010-04-01",
//     "dateCreated" => "Mon, 22 Aug 2011 20:59:45 +0000",
//     "dateUpdated" => "Tue, 18 Aug 2015 16:48:57 +0000",
//     "friendlyName" => "Phone Me",
//     "messageStatusCallback" => "http://www.example.com/sms-status-callback",
// ]
$application->toArray()

Since the InstanceResource classes already use a magic __get(), could we preserve the structure of the API response in $properties and then snake the requested $property?

public function __get($property)
{
    $property = strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1_', $property));
    
    return $this->properties[$property] ?? null;
}

This would also remove the need to parse the payload and camelCase all of their properties manually (even though this is automated via your API generation tool).

Thanks for your time!

@rakatyal
Copy link
Contributor

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

@rakatyal rakatyal added type: twilio enhancement feature request on Twilio's roadmap status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap and removed type: twilio enhancement feature request on Twilio's roadmap labels Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

2 participants