From d463d8fd2addbf150e2dc3ac3bddaeb3c886f9e9 Mon Sep 17 00:00:00 2001 From: Athira Sabu <102021496+AsabuHere@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:13:43 +0530 Subject: [PATCH] feat: Generator changes for go json ingress support (#542) # Fixes # https://issues.corp.twilio.com/browse/DII-1245 A short description of what this PR does. Generator changes for go json ingress support ### 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 - [x] 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. --- .../go/go-client/helper/rest/api/v2010/accounts.go | 1 - src/main/resources/twilio-go/api.mustache | 11 ++++++++++- .../twilio-go/partial_serialization.mustache | 6 +++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/go/go-client/helper/rest/api/v2010/accounts.go b/examples/go/go-client/helper/rest/api/v2010/accounts.go index 1e60583c7..d53c8080a 100644 --- a/examples/go/go-client/helper/rest/api/v2010/accounts.go +++ b/examples/go/go-client/helper/rest/api/v2010/accounts.go @@ -74,7 +74,6 @@ func (c *ApiService) CreateAccount(params *CreateAccountParams) (*TestResponseOb if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) if err != nil { return nil, err diff --git a/src/main/resources/twilio-go/api.mustache b/src/main/resources/twilio-go/api.mustache index decd84cdf..abe13cfdd 100644 --- a/src/main/resources/twilio-go/api.mustache +++ b/src/main/resources/twilio-go/api.mustache @@ -47,8 +47,17 @@ func (c *ApiService) {{{nickname}}}({{#allParams}}{{#required}}{{paramName}} {{{ } {{/headerParams}} {{/hasHeaderParams}} - +{{#vendorExtensions.x-is-create-operation}} +{{#vendorExtensions.x-is-json-type}} + resp, err := c.requestHandler.{{httpMethod}}(c.baseURL+path, data, headers, body...) +{{/vendorExtensions.x-is-json-type}} +{{^vendorExtensions.x-is-json-type}} + resp, err := c.requestHandler.{{httpMethod}}(c.baseURL+path, data, headers) +{{/vendorExtensions.x-is-json-type}} +{{/vendorExtensions.x-is-create-operation}} +{{^vendorExtensions.x-is-create-operation}} resp, err := c.requestHandler.{{httpMethod}}(c.baseURL+path, data, headers) +{{/vendorExtensions.x-is-create-operation}} {{#returnType}} if err != nil { return nil, err diff --git a/src/main/resources/twilio-go/partial_serialization.mustache b/src/main/resources/twilio-go/partial_serialization.mustache index f3055b8ba..25b9f207e 100644 --- a/src/main/resources/twilio-go/partial_serialization.mustache +++ b/src/main/resources/twilio-go/partial_serialization.mustache @@ -24,13 +24,13 @@ if params != nil && params.PathAccountSid != nil { {{#hasOptionalParams}} {{#optionalParams}} {{#vendorExtensions.x-is-body-param}} + body := []byte{} if params != nil && params.{{paramName}} != nil { - v, err := json.Marshal(*params.{{paramName}}) + b, err := json.Marshal(*params.{{paramName}}) if err != nil { return nil, err } - urlEncodedData := url.QueryEscape(string(v)) - data.Set("{{baseName}}", urlEncodedData) + body = b } {{/vendorExtensions.x-is-body-param}} {{^vendorExtensions.x-is-body-param}}