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

🐍🐪 Snake vs. camel casing, nested objects #962

Open
mrienstra opened this issue Oct 6, 2023 · 0 comments
Open

🐍🐪 Snake vs. camel casing, nested objects #962

mrienstra opened this issue Oct 6, 2023 · 0 comments

Comments

@mrienstra
Copy link

This library converts snake_case API responses to camelCase, e.g.:
https://github.com/twilio/twilio-node/blob/a23ee16/src/rest/lookups/v2/phoneNumber.ts#L218-L232

This is only occurring at the top level, but not within nested objects, e.g. lineTypeIntelligence / line_type_intelligence:
https://www.twilio.com/docs/lookup/v2-api/identity-match

If the intent is to continue hardcoding these case conversions, a fix (shown only for one possible nested object) might look something like this:

    this.lineTypeIntelligence = payload.line_type_intelligence && {
      errorCode: payload.line_type_intelligence.error_code,
      mobileCountryCode: payload.line_type_intelligence.mobile_country_code,
      mobileNetworkCode: payload.line_type_intelligence.mobile_network_code,
      carrierName: payload.line_type_intelligence.carrier_name,
      type: payload.line_type_intelligence.type,
    };

or

    if (payload.line_type_intelligence) {
      const {
        error_code,
        mobile_country_code,
        mobile_network_code,
        carrier_name,
        type,
      } = payload.line_type_intelligence;
      this.lineTypeIntelligence = {
        errorCode: error_code,
        mobileCountryCode: mobile_country_code,
        mobileNetworkCode: mobile_network_code,
        carrierName: carrier_name,
        type: type,
      };
    } else {
      this.lineTypeIntelligence = payload.line_type_intelligence;
    }

Alternately, rather than hardcoding case conversions, a library (e.g. https://www.npmjs.com/package/case-anythinghttps://github.com/mesqueeb/case-anything) could be used


The docs (e.g. https://www.twilio.com/docs/lookup/v2-api/identity-match) are a little confusing, they always show snake_case, even when the selected library is "NODE.JS". I think that's a known issue, I found a mention of it from May 2018: #344 (comment)

Would be nice to see if docs folks can tweak that, or at least add a note about helper libraries changing property casing. Obviously most devs will clock this right away, but still, it adds unnecessary cognitive overhead when referring to API docs.

Happy to open another issue for that, but this repo is probably not the place for that work to be tracked anyway.

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

No branches or pull requests

1 participant