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

fix: add support for null response fields #27

Merged
merged 2 commits into from
Feb 22, 2021
Merged

fix: add support for null response fields #27

merged 2 commits into from
Feb 22, 2021

Conversation

eshanholtz
Copy link
Contributor

This PR adds support for receiving null fields in the response json. Also fixes enum naming conflict.

Copy link
Contributor

@thinkingserious thinkingserious left a comment

Choose a reason for hiding this comment

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

I verified these changes no longer cause an exception when generating a python client with the following steps:

git clone git@github.com:twilio/twilio-oai.git
cd twilio-oai
git fetch --all
git checkout origin/nullable
git pull origin nullable
npm install @openapitools/openapi-generator-cli -g
npx @openapitools/openapi-generator-cli generate -i ~/Projects/code-reviews/1183/twilio-oai/spec/yaml/twilio_api_v2010.yaml -g python -o ./tmp/test/
cd tmp/test
pip install python-dateutil
python setup.py install

I then created a test script that used to cause an exception and verified that the exception is no longer thrown:

import openapi_client
import os
from openapi_client.api import default_api
from pprint import pprint

configuration = openapi_client.Configuration(
    host = "http://api.twilio.com"
)

configuration = openapi_client.Configuration(
    username = os.environ['TWILIO_ACCOUNT_SID'],
    password = os.environ['TWILIO_AUTH_TOKEN']
)

with openapi_client.ApiClient(configuration) as api_client:
    api_instance = default_api.DefaultApi(api_client)
    account_sid = os.environ['TWILIO_ACCOUNT_SID']
    to = os.environ['TWILIO_TO_PHONE_NUMBER']
    body = "Hello World!"
    _from = os.environ['TWILIO_FROM_PHONE_NUMBER']

    try:
        api_response = api_instance.create_message(account_sid, to, _from=_from, body=body)
        pprint(api_response)
    except openapi_client.ApiException as e:
        print("Exception when calling DefaultApi->create_message: %s\n" % e)

@shwetha-manvinkurke
Copy link
Contributor

Have you tried regenerating the twilio-go from the new specs?

@eshanholtz
Copy link
Contributor Author

eshanholtz commented Feb 22, 2021

@shwetha-manvinkurke yes, the only thing it changes is that properties in the response object struct are now pointers, so they can have a null value. golang handles pointer/non-pointer values by design.

@eshanholtz eshanholtz merged commit a89a022 into main Feb 22, 2021
@eshanholtz eshanholtz deleted the nullable branch February 22, 2021 22:52
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