Skip to content

Commit

Permalink
fix: set content type in python, go, ruby, php (#585)
Browse files Browse the repository at this point in the history
<!--
We appreciate the effort for this pull request but before that please
make sure you read the contribution guidelines, then fill out the blanks
below.

Please format the PR title appropriately based on the type of change:
  <type>[!]: <description>
Where <type> is one of: docs, chore, feat, fix, test, misc.
Add a '!' after the type for breaking changes (e.g. feat!: new breaking
feature).

**All third-party contributors acknowledge that any contributions they
provide will be made under the same open-source license that the
open-source project is provided under.**

Please enter each Issue number you are resolving in your PR after one of
the following words [Fixes, Closes, Resolves]. This will auto-link these
issues and close them when this PR is merged!
e.g.
Fixes #1
Closes #2
-->

# Fixes #

Setting default content type

### Checklist
- [x] I acknowledge that all my contributions will be made under the
project's license
- [ ] Run `make test-docker`
- [ ] Verify affected language:
- [ ] Generate [twilio-go](https://github.com/twilio/twilio-go) from our
[OpenAPI specification](https://github.com/twilio/twilio-oai) using the
[build_twilio_go.py](./examples/build_twilio_go.py) using `python
examples/build_twilio_go.py path/to/twilio-oai/spec/yaml
path/to/twilio-go` and inspect the diff
    - [ ] Run `make test` in `twilio-go`
    - [ ] Create a pull request in `twilio-go`
    - [ ] Provide a link below to the pull request
- [ ] I have made a material change to the repo (functionality, testing,
spelling, grammar)
- [ ] I have read the [Contribution
Guidelines](https://github.com/twilio/twilio-oai-generator/blob/main/CONTRIBUTING.md)
and my PR follows them
- [ ] I have titled the PR appropriately
- [ ] I have updated my branch with the main branch
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added the necessary documentation about the functionality
in the appropriate .md file
- [ ] I have added inline documentation to the code I modified

If you have questions, please create a GitHub Issue in this repository.
  • Loading branch information
tiwarishubham635 authored Jun 18, 2024
1 parent 4c05370 commit 60be17d
Show file tree
Hide file tree
Showing 34 changed files with 184 additions and 116 deletions.
20 changes: 15 additions & 5 deletions examples/go/go-client/helper/rest/api/v2010/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func (c *ApiService) CreateAccount(params *CreateAccountParams) (*TestResponseOb
path := "/2010-04-01/Accounts.json"

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

if params != nil && params.RecordingStatusCallback != nil {
data.Set("RecordingStatusCallback", *params.RecordingStatusCallback)
Expand Down Expand Up @@ -94,7 +96,9 @@ func (c *ApiService) DeleteAccount(Sid string) error {
path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers)
if err != nil {
Expand All @@ -111,7 +115,9 @@ func (c *ApiService) FetchAccount(Sid string) (*TestResponseObject, error) {
path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
if err != nil {
Expand Down Expand Up @@ -174,7 +180,9 @@ func (c *ApiService) PageAccount(params *ListAccountParams, pageToken, pageNumbe
path := "/2010-04-01/Accounts.json"

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

if params != nil && params.DateCreated != nil {
data.Set("DateCreated", fmt.Sprint((*params.DateCreated).Format(time.RFC3339)))
Expand Down Expand Up @@ -322,7 +330,9 @@ func (c *ApiService) UpdateAccount(Sid string, params *UpdateAccountParams) (*Te
path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

if params != nil && params.PauseBehavior != nil {
data.Set("PauseBehavior", *params.PauseBehavior)
Expand Down
12 changes: 9 additions & 3 deletions examples/go/go-client/helper/rest/api/v2010/accounts_calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ func (c *ApiService) CreateCall(params *CreateCallParams) (*TestResponseObject,
}

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

if params != nil && params.RequiredStringProperty != nil {
data.Set("RequiredStringProperty", *params.RequiredStringProperty)
Expand Down Expand Up @@ -120,7 +122,9 @@ func (c *ApiService) DeleteCall(TestInteger int, params *DeleteCallParams) error
path = strings.Replace(path, "{"+"TestInteger"+"}", fmt.Sprint(TestInteger), -1)

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers)
if err != nil {
Expand Down Expand Up @@ -153,7 +157,9 @@ func (c *ApiService) FetchCall(TestInteger int, params *FetchCallParams) (*TestR
path = strings.Replace(path, "{"+"TestInteger"+"}", fmt.Sprint(TestInteger), -1)

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func (c *ApiService) UpdateCallFeedbackSummary(Sid string, params *UpdateCallFee
path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

if params != nil && params.AccountSid != nil {
data.Set("AccountSid", *params.AccountSid)
Expand Down
20 changes: 15 additions & 5 deletions examples/go/go-client/helper/rest/flex/v1/credentials_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ func (c *ApiService) CreateCredentialAws(params *CreateCredentialAwsParams) (*Te
path := "/v1/Credentials/AWS"

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

if params != nil && params.TestString != nil {
data.Set("TestString", *params.TestString)
Expand Down Expand Up @@ -239,7 +241,9 @@ func (c *ApiService) DeleteCredentialAws(Sid string) error {
path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers)
if err != nil {
Expand All @@ -256,7 +260,9 @@ func (c *ApiService) FetchCredentialAws(Sid string) (*TestResponseObject, error)
path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
if err != nil {
Expand Down Expand Up @@ -295,7 +301,9 @@ func (c *ApiService) PageCredentialAws(params *ListCredentialAwsParams, pageToke
path := "/v1/Credentials/AWS"

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

if params != nil && params.PageSize != nil {
data.Set("PageSize", fmt.Sprint(*params.PageSize))
Expand Down Expand Up @@ -431,7 +439,9 @@ func (c *ApiService) UpdateCredentialAws(Sid string, params *UpdateCredentialAws
path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

if params != nil && params.TestString != nil {
data.Set("TestString", *params.TestString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func (c *ApiService) FetchCredentialHistory(Sid string, params *FetchCredentialH
path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

if params != nil && params.AddOnsData != nil {
v, err := json.Marshal(params.AddOnsData)
Expand Down
4 changes: 3 additions & 1 deletion examples/go/go-client/helper/rest/flex/v1/voice.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func (c *ApiService) UpdateCall(Sid string) (*UpdateCallResponse, error) {
path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)

data := url.Values{}
headers := make(map[string]interface{})
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}

resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions examples/java/integration-test/rest/TestRestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public Response request(final Request request) {
// manipulate string for mock server url
sb.replace(0, 5, scheme);
Request testRequest = new Request(request.getMethod(), sb.toString());
testRequest.setContentType(request.getContentType());
// updating the query and post params
request.getPostParams().forEach((key, value) -> value.forEach(listValue -> testRequest.addPostParam(key, listValue)));
request.getQueryParams().forEach((key, value) -> value.forEach(listValue -> testRequest.addPostParam(key, listValue)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function update(\DateTime $endDate, \DateTime $startDate, array $options
$options['accountSid'],
]);

$payload = $this->version->update('POST', $this->uri, [], $data);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->update('POST', $this->uri, [], $data, $headers);

return new FeedbackCallSummaryInstance(
$this->version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public function __construct(
public function delete(): bool
{

return $this->version->delete('DELETE', $this->uri);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
return $this->version->delete('DELETE', $this->uri, [], [], $headers);
}


Expand All @@ -85,7 +86,8 @@ public function delete(): bool
public function fetch(): CallInstance
{

$payload = $this->version->fetch('GET', $this->uri, [], []);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->fetch('GET', $this->uri, [], [], $headers);

return new CallInstance(
$this->version,
Expand Down
3 changes: 2 additions & 1 deletion examples/php/src/Twilio/Rest/Api/V2010/Account/CallList.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public function create(string $requiredStringProperty, string $testMethod, array
Serialize::map($options['testArrayOfUri'], function ($e) { return $e; }),
]);

$payload = $this->version->create('POST', $this->uri, [], $data);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->create('POST', $this->uri, [], $data, $headers);

return new CallInstance(
$this->version,
Expand Down
9 changes: 6 additions & 3 deletions examples/php/src/Twilio/Rest/Api/V2010/AccountContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function __construct(
public function delete(): bool
{

return $this->version->delete('DELETE', $this->uri);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
return $this->version->delete('DELETE', $this->uri, [], [], $headers);
}


Expand All @@ -83,7 +84,8 @@ public function delete(): bool
public function fetch(): AccountInstance
{

$payload = $this->version->fetch('GET', $this->uri, [], []);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->fetch('GET', $this->uri, [], [], $headers);

return new AccountInstance(
$this->version,
Expand Down Expand Up @@ -113,7 +115,8 @@ public function update(string $status, array $options = []): AccountInstance
$options['pauseBehavior'],
]);

$payload = $this->version->update('POST', $this->uri, [], $data);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->update('POST', $this->uri, [], $data, $headers);

return new AccountInstance(
$this->version,
Expand Down
3 changes: 1 addition & 2 deletions examples/php/src/Twilio/Rest/Api/V2010/AccountList.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public function create(array $options = []): AccountInstance
$options['twiml'],
]);

$headers = Values::of(['X-Twilio-Webhook-Enabled' => $options['xTwilioWebhookEnabled']]);

$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' , 'X-Twilio-Webhook-Enabled' => $options['xTwilioWebhookEnabled']]);
$payload = $this->version->create('POST', $this->uri, [], $data, $headers);

return new AccountInstance(
Expand Down
3 changes: 2 additions & 1 deletion examples/php/src/Twilio/Rest/FlexApi/V1/CallContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function __construct(
public function update(): CallInstance
{

$payload = $this->version->update('POST', $this->uri, [], []);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->update('POST', $this->uri, [], [], $headers);

return new CallInstance(
$this->version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function fetch(array $options = []): HistoryInstance
]);
$params = \array_merge($params, Serialize::prefixedCollapsibleMap($options['addOnsData'], 'AddOns'));

$payload = $this->version->fetch('GET', $this->uri, $params, []);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->fetch('GET', $this->uri, $params, [], $headers);

return new HistoryInstance(
$this->version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function __construct(
public function delete(): bool
{

return $this->version->delete('DELETE', $this->uri);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
return $this->version->delete('DELETE', $this->uri, [], [], $headers);
}


Expand All @@ -83,7 +84,8 @@ public function delete(): bool
public function fetch(): AwsInstance
{

$payload = $this->version->fetch('GET', $this->uri, [], []);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->fetch('GET', $this->uri, [], [], $headers);

return new AwsInstance(
$this->version,
Expand Down Expand Up @@ -112,7 +114,8 @@ public function update(array $options = []): AwsInstance
Serialize::booleanToString($options['testBoolean']),
]);

$payload = $this->version->update('POST', $this->uri, [], $data);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->update('POST', $this->uri, [], $data, $headers);

return new AwsInstance(
$this->version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public function create(string $testString, array $options = []): NewCredentialsI
$options['someA2PThing'],
]);

$payload = $this->version->create('POST', $this->uri, [], $data);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->create('POST', $this->uri, [], $data, $headers);

return new NewCredentialsInstance(
$this->version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function __construct(
public function fetch(): FleetInstance
{

$payload = $this->version->fetch('GET', $this->uri, [], []);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->fetch('GET', $this->uri, [], [], $headers);

return new FleetInstance(
$this->version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function create(array $options = []): FleetInstance
$options['name'],
]);

$payload = $this->version->create('POST', $this->uri, [], $data);
$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded' ]);
$payload = $this->version->create('POST', $this->uri, [], $data, $headers);

return new FleetInstance(
$this->version,
Expand Down
2 changes: 2 additions & 0 deletions examples/python/twilio/rest/api/v2010/account/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ def create(
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
"Content-Type": "application/x-www-form-urlencoded",
}
)

Expand Down Expand Up @@ -467,6 +468,7 @@ async def create_async(
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
"Content-Type": "application/x-www-form-urlencoded",
}
)

Expand Down
10 changes: 4 additions & 6 deletions examples/python/twilio/rest/api/v2010/account/call/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,10 @@ def create(
"TestArrayOfUri": serialize.map(test_array_of_uri, lambda e: e),
}
)
headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
method="POST", uri=self._uri, data=data, headers=headers
)

return CallInstance(
Expand Down Expand Up @@ -343,11 +342,10 @@ async def create_async(
"TestArrayOfUri": serialize.map(test_array_of_uri, lambda e: e),
}
)
headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
method="POST", uri=self._uri, data=data, headers=headers
)

return CallInstance(
Expand Down
Loading

0 comments on commit 60be17d

Please sign in to comment.