From e9240831e1620f7e1e743f3ff69812640b2b6474 Mon Sep 17 00:00:00 2001 From: Shubham Date: Thu, 2 Nov 2023 11:18:26 +0530 Subject: [PATCH] feat: added support for nested enum in request body in node (#534) # Fixes # Fixed the handling of nested enum objects in request body of node ### Checklist - [x] I acknowledge that all my contributions will be made under the project's license - [x] Run `make test-docker` - [x] 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 - [x] I have made a material change to the repo (functionality, testing, spelling, grammar) - [x] 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. --------- Co-authored-by: sbansla <104902068+sbansla@users.noreply.github.com> Co-authored-by: Athira Sabu <102021496+AsabuHere@users.noreply.github.com> --- .../helper/rest/api/v2010/accounts.go | 375 ++++++----- .../helper/rest/api/v2010/accounts_calls.go | 242 ++++--- .../v2010/accounts_calls_feedback_summary.go | 102 ++- .../helper/rest/api/v2010/api_service.go | 6 +- .../api/v2010/model_list_account_response.go | 25 +- .../api/v2010/model_test_response_object.go | 102 +-- ...t_response_object_test_array_of_objects.go | 12 +- .../model_test_response_object_test_object.go | 13 +- .../helper/rest/flex/v1/api_service.go | 6 +- .../helper/rest/flex/v1/credentials_aws.go | 598 +++++++++--------- .../rest/flex/v1/credentials_aws_history.go | 59 +- .../v1/model_list_credential_aws_response.go | 11 +- ...model_list_credential_aws_response_meta.go | 19 +- .../flex/v1/model_test_response_object.go | 15 +- .../flex/v1/model_update_call_200_response.go | 9 +- .../go/go-client/helper/rest/flex/v1/voice.go | 38 +- .../resources/api/v2010/api_default.go | 334 +++++----- .../resources/flex/v1/api_default.go | 206 +++--- .../twilio/rest/api/v2010/AccountCreator.java | 4 +- .../twilio/rest/api/v2010/AccountDeleter.java | 2 +- .../twilio/rest/api/v2010/AccountFetcher.java | 2 +- .../twilio/rest/api/v2010/AccountReader.java | 2 +- .../twilio/rest/api/v2010/AccountUpdater.java | 2 +- .../rest/api/v2010/account/CallCreator.java | 3 +- .../rest/api/v2010/account/CallDeleter.java | 2 +- .../rest/api/v2010/account/CallFetcher.java | 2 +- .../call/FeedbackCallSummaryUpdater.java | 2 +- .../twilio/rest/flexapi/v1/CallUpdater.java | 2 +- .../flexapi/v1/credential/AwsDeleter.java | 2 +- .../flexapi/v1/credential/AwsFetcher.java | 2 +- .../rest/flexapi/v1/credential/AwsReader.java | 2 +- .../flexapi/v1/credential/AwsUpdater.java | 2 +- .../v1/credential/NewCredentialsCreator.java | 3 +- .../v1/credential/aws/HistoryFetcher.java | 2 +- .../deployedDevices/FleetCreator.java | 3 +- .../deployedDevices/FleetFetcher.java | 2 +- .../understand/AssistantReader.java | 2 +- examples/python/Dockerfile | 2 +- .../com/twilio/oai/TwilioGoGenerator.java | 4 + .../com/twilio/oai/TwilioNodeGenerator.java | 12 +- .../twilio/oai/api/ApiResourceBuilder.java | 5 +- .../oai/api/FluentApiResourceBuilder.java | 2 +- .../oai/api/JavaApiResourceBuilder.java | 3 +- .../oai/api/NodeApiResourceBuilder.java | 66 +- .../java/com/twilio/oai/common/Utility.java | 10 + ...CodegenModelContainerDataTypeResolver.java | 17 +- .../resolver/common/CodegenModelResolver.java | 29 +- ...CodegenModelContainerDataTypeResolver.java | 35 + .../NodeCodegenModelDataTypeResolver.java | 77 +++ .../node/NodeCodegenModelResolver.java | 89 +++ .../twilio-go/partial_serialization.mustache | 94 ++- .../resources/twilio-java/creator.mustache | 3 +- .../resources/twilio-java/deleter.mustache | 2 +- .../resources/twilio-java/fetcher.mustache | 2 +- .../resources/twilio-java/models.mustache | 2 +- .../resources/twilio-java/reader.mustache | 2 +- .../resources/twilio-java/updater.mustache | 2 +- src/main/resources/twilio-node/model.mustache | 2 +- .../resources/twilio-node/operation.mustache | 1 + .../com/twilio/oai/TwilioGeneratorTest.java | 13 +- 60 files changed, 1466 insertions(+), 1223 deletions(-) create mode 100644 src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelContainerDataTypeResolver.java create mode 100644 src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelDataTypeResolver.java create mode 100644 src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelResolver.java 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 c1c30d2dd..1e60583c7 100644 --- a/examples/go/go-client/helper/rest/api/v2010/accounts.go +++ b/examples/go/go-client/helper/rest/api/v2010/accounts.go @@ -18,208 +18,201 @@ import ( "encoding/json" "fmt" "net/url" + "strings" + "time" - "github.com/twilio/twilio-go/client" + "github.com/twilio/twilio-go/client" ) - // Optional parameters for the method 'CreateAccount' type CreateAccountParams struct { - // - XTwilioWebhookEnabled *string `json:"X-Twilio-Webhook-Enabled,omitempty"` - // - RecordingStatusCallback *string `json:"RecordingStatusCallback,omitempty"` - // - RecordingStatusCallbackEvent *[]string `json:"RecordingStatusCallbackEvent,omitempty"` - // - Twiml *string `json:"Twiml,omitempty"` + // + XTwilioWebhookEnabled *string `json:"X-Twilio-Webhook-Enabled,omitempty"` + // + RecordingStatusCallback *string `json:"RecordingStatusCallback,omitempty"` + // + RecordingStatusCallbackEvent *[]string `json:"RecordingStatusCallbackEvent,omitempty"` + // + Twiml *string `json:"Twiml,omitempty"` } -func (params *CreateAccountParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnabled string) (*CreateAccountParams){ - params.XTwilioWebhookEnabled = &XTwilioWebhookEnabled - return params +func (params *CreateAccountParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnabled string) *CreateAccountParams { + params.XTwilioWebhookEnabled = &XTwilioWebhookEnabled + return params } -func (params *CreateAccountParams) SetRecordingStatusCallback(RecordingStatusCallback string) (*CreateAccountParams){ - params.RecordingStatusCallback = &RecordingStatusCallback - return params +func (params *CreateAccountParams) SetRecordingStatusCallback(RecordingStatusCallback string) *CreateAccountParams { + params.RecordingStatusCallback = &RecordingStatusCallback + return params } -func (params *CreateAccountParams) SetRecordingStatusCallbackEvent(RecordingStatusCallbackEvent []string) (*CreateAccountParams){ - params.RecordingStatusCallbackEvent = &RecordingStatusCallbackEvent - return params +func (params *CreateAccountParams) SetRecordingStatusCallbackEvent(RecordingStatusCallbackEvent []string) *CreateAccountParams { + params.RecordingStatusCallbackEvent = &RecordingStatusCallbackEvent + return params } -func (params *CreateAccountParams) SetTwiml(Twiml string) (*CreateAccountParams){ - params.Twiml = &Twiml - return params +func (params *CreateAccountParams) SetTwiml(Twiml string) *CreateAccountParams { + params.Twiml = &Twiml + return params } func (c *ApiService) CreateAccount(params *CreateAccountParams) (*TestResponseObject, error) { - path := "/2010-04-01/Accounts.json" - -data := url.Values{} -headers := make(map[string]interface{}) + path := "/2010-04-01/Accounts.json" -if params != nil && params.RecordingStatusCallback != nil { - data.Set("RecordingStatusCallback", *params.RecordingStatusCallback) -} -if params != nil && params.RecordingStatusCallbackEvent != nil { - for _, item := range *params.RecordingStatusCallbackEvent { - data.Add("RecordingStatusCallbackEvent", item) - } -} -if params != nil && params.Twiml != nil { - data.Set("Twiml", *params.Twiml) -} + data := url.Values{} + headers := make(map[string]interface{}) + if params != nil && params.RecordingStatusCallback != nil { + data.Set("RecordingStatusCallback", *params.RecordingStatusCallback) + } + if params != nil && params.RecordingStatusCallbackEvent != nil { + for _, item := range *params.RecordingStatusCallbackEvent { + data.Add("RecordingStatusCallbackEvent", item) + } + } + if params != nil && params.Twiml != nil { + data.Set("Twiml", *params.Twiml) + } 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 - } + resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - defer resp.Body.Close() + defer resp.Body.Close() - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } - return ps, err + return ps, err } -func (c *ApiService) DeleteAccount(Sid string, ) (error) { - path := "/2010-04-01/Accounts/{Sid}.json" - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) - -data := url.Values{} -headers := make(map[string]interface{}) - - +func (c *ApiService) DeleteAccount(Sid string) error { + path := "/2010-04-01/Accounts/{Sid}.json" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) + data := url.Values{} + headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) - if err != nil { - return err - } + resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + if err != nil { + return err + } - defer resp.Body.Close() + defer resp.Body.Close() - return nil + return nil } -func (c *ApiService) FetchAccount(Sid string, ) (*TestResponseObject, error) { - path := "/2010-04-01/Accounts/{Sid}.json" - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) - -data := url.Values{} -headers := make(map[string]interface{}) - +func (c *ApiService) FetchAccount(Sid string) (*TestResponseObject, error) { + path := "/2010-04-01/Accounts/{Sid}.json" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) + data := url.Values{} + headers := make(map[string]interface{}) + resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } - - defer resp.Body.Close() + defer resp.Body.Close() - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } - return ps, err + return ps, err } // Optional parameters for the method 'ListAccount' type ListAccountParams struct { - // - DateCreated *time.Time `json:"DateCreated,omitempty"` - // - DateTest *string `json:"Date.Test,omitempty"` - // - DateCreatedBefore *time.Time `json:"DateCreated<,omitempty"` - // - DateCreatedAfter *time.Time `json:"DateCreated>,omitempty"` - // - PageSize *int `json:"PageSize,omitempty"` - // Max number of records to return. - Limit *int `json:"limit,omitempty"` + // + DateCreated *time.Time `json:"DateCreated,omitempty"` + // + DateTest *string `json:"Date.Test,omitempty"` + // + DateCreatedBefore *time.Time `json:"DateCreated<,omitempty"` + // + DateCreatedAfter *time.Time `json:"DateCreated>,omitempty"` + // + PageSize *int `json:"PageSize,omitempty"` + // Max number of records to return. + Limit *int `json:"limit,omitempty"` } -func (params *ListAccountParams) SetDateCreated(DateCreated time.Time) (*ListAccountParams){ - params.DateCreated = &DateCreated - return params +func (params *ListAccountParams) SetDateCreated(DateCreated time.Time) *ListAccountParams { + params.DateCreated = &DateCreated + return params } -func (params *ListAccountParams) SetDateTest(DateTest string) (*ListAccountParams){ - params.DateTest = &DateTest - return params +func (params *ListAccountParams) SetDateTest(DateTest string) *ListAccountParams { + params.DateTest = &DateTest + return params } -func (params *ListAccountParams) SetDateCreatedBefore(DateCreatedBefore time.Time) (*ListAccountParams){ - params.DateCreatedBefore = &DateCreatedBefore - return params +func (params *ListAccountParams) SetDateCreatedBefore(DateCreatedBefore time.Time) *ListAccountParams { + params.DateCreatedBefore = &DateCreatedBefore + return params } -func (params *ListAccountParams) SetDateCreatedAfter(DateCreatedAfter time.Time) (*ListAccountParams){ - params.DateCreatedAfter = &DateCreatedAfter - return params +func (params *ListAccountParams) SetDateCreatedAfter(DateCreatedAfter time.Time) *ListAccountParams { + params.DateCreatedAfter = &DateCreatedAfter + return params } -func (params *ListAccountParams) SetPageSize(PageSize int) (*ListAccountParams){ - params.PageSize = &PageSize - return params +func (params *ListAccountParams) SetPageSize(PageSize int) *ListAccountParams { + params.PageSize = &PageSize + return params } -func (params *ListAccountParams) SetLimit(Limit int) (*ListAccountParams){ - params.Limit = &Limit - return params +func (params *ListAccountParams) SetLimit(Limit int) *ListAccountParams { + params.Limit = &Limit + return params } // Retrieve a single page of Account records from the API. Request is executed immediately. func (c *ApiService) PageAccount(params *ListAccountParams, pageToken, pageNumber string) (*ListAccountResponse, error) { - path := "/2010-04-01/Accounts.json" + path := "/2010-04-01/Accounts.json" - -data := url.Values{} -headers := make(map[string]interface{}) + data := url.Values{} + headers := make(map[string]interface{}) -if params != nil && params.DateCreated != nil { - data.Set("DateCreated", fmt.Sprint((*params.DateCreated).Format(time.RFC3339))) -} -if params != nil && params.DateTest != nil { - data.Set("Date.Test", fmt.Sprint(*params.DateTest)) -} -if params != nil && params.DateCreatedBefore != nil { - data.Set("DateCreated<", fmt.Sprint((*params.DateCreatedBefore).Format(time.RFC3339))) -} -if params != nil && params.DateCreatedAfter != nil { - data.Set("DateCreated>", fmt.Sprint((*params.DateCreatedAfter).Format(time.RFC3339))) -} -if params != nil && params.PageSize != nil { - data.Set("PageSize", fmt.Sprint(*params.PageSize)) -} + if params != nil && params.DateCreated != nil { + data.Set("DateCreated", fmt.Sprint((*params.DateCreated).Format(time.RFC3339))) + } + if params != nil && params.DateTest != nil { + data.Set("Date.Test", fmt.Sprint(*params.DateTest)) + } + if params != nil && params.DateCreatedBefore != nil { + data.Set("DateCreated<", fmt.Sprint((*params.DateCreatedBefore).Format(time.RFC3339))) + } + if params != nil && params.DateCreatedAfter != nil { + data.Set("DateCreated>", fmt.Sprint((*params.DateCreatedAfter).Format(time.RFC3339))) + } + if params != nil && params.PageSize != nil { + data.Set("PageSize", fmt.Sprint(*params.PageSize)) + } - if pageToken != "" { - data.Set("PageToken", pageToken) - } - if pageNumber != "" { - data.Set("Page", pageNumber) - } + if pageToken != "" { + data.Set("PageToken", pageToken) + } + if pageNumber != "" { + data.Set("Page", pageNumber) + } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } + resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - defer resp.Body.Close() + defer resp.Body.Close() - ps := &ListAccountResponse{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + ps := &ListAccountResponse{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } - return ps, err + return ps, err } // Lists Account records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. @@ -260,7 +253,6 @@ func (c *ApiService) StreamAccount(params *ListAccountParams) (chan TestResponse return recordChannel, errorChannel } - func (c *ApiService) streamAccount(response *ListAccountResponse, params *ListAccountParams, recordChannel chan TestResponseObject, errorChannel chan error) { curRecord := 1 @@ -292,68 +284,65 @@ func (c *ApiService) streamAccount(response *ListAccountResponse, params *ListAc } func (c *ApiService) getNextListAccountResponse(nextPageUrl string) (interface{}, error) { - if nextPageUrl == "" { - return nil, nil - } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) - if err != nil { - return nil, err - } - - defer resp.Body.Close() - - ps := &ListAccountResponse{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } - return ps, nil -} + if nextPageUrl == "" { + return nil, nil + } + resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + if err != nil { + return nil, err + } + + defer resp.Body.Close() + ps := &ListAccountResponse{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } + return ps, nil +} // Optional parameters for the method 'UpdateAccount' type UpdateAccountParams struct { - // - PauseBehavior *string `json:"PauseBehavior,omitempty"` - // - Status *string `json:"Status,omitempty"` + // + PauseBehavior *string `json:"PauseBehavior,omitempty"` + // + Status *string `json:"Status,omitempty"` } -func (params *UpdateAccountParams) SetPauseBehavior(PauseBehavior string) (*UpdateAccountParams){ - params.PauseBehavior = &PauseBehavior - return params +func (params *UpdateAccountParams) SetPauseBehavior(PauseBehavior string) *UpdateAccountParams { + params.PauseBehavior = &PauseBehavior + return params } -func (params *UpdateAccountParams) SetStatus(Status string) (*UpdateAccountParams){ - params.Status = &Status - return params +func (params *UpdateAccountParams) SetStatus(Status string) *UpdateAccountParams { + params.Status = &Status + return params } func (c *ApiService) UpdateAccount(Sid string, params *UpdateAccountParams) (*TestResponseObject, error) { - path := "/2010-04-01/Accounts/{Sid}.json" - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) - -data := url.Values{} -headers := make(map[string]interface{}) - -if params != nil && params.PauseBehavior != nil { - data.Set("PauseBehavior", *params.PauseBehavior) -} -if params != nil && params.Status != nil { - data.Set("Status", *params.Status) -} + path := "/2010-04-01/Accounts/{Sid}.json" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) + data := url.Values{} + headers := make(map[string]interface{}) + if params != nil && params.PauseBehavior != nil { + data.Set("PauseBehavior", *params.PauseBehavior) + } + if params != nil && params.Status != nil { + data.Set("Status", *params.Status) + } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } + resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - defer resp.Body.Close() + defer resp.Body.Close() - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } - return ps, err + return ps, err } diff --git a/examples/go/go-client/helper/rest/api/v2010/accounts_calls.go b/examples/go/go-client/helper/rest/api/v2010/accounts_calls.go index cc4c87699..f6e2259e0 100644 --- a/examples/go/go-client/helper/rest/api/v2010/accounts_calls.go +++ b/examples/go/go-client/helper/rest/api/v2010/accounts_calls.go @@ -18,164 +18,154 @@ import ( "encoding/json" "fmt" "net/url" - - "github.com/twilio/twilio-go/client" + "strings" ) - // Optional parameters for the method 'CreateCall' type CreateCallParams struct { - // - PathAccountSid *string `json:"PathAccountSid,omitempty"` - // - RequiredStringProperty *string `json:"RequiredStringProperty,omitempty"` - // - TestArrayOfStrings *[]string `json:"TestArrayOfStrings,omitempty"` - // - TestArrayOfUri *[]string `json:"TestArrayOfUri,omitempty"` - // The HTTP method that we should use to request the `TestArrayOfUri`. - TestMethod *string `json:"TestMethod,omitempty"` + // + PathAccountSid *string `json:"PathAccountSid,omitempty"` + // + RequiredStringProperty *string `json:"RequiredStringProperty,omitempty"` + // + TestArrayOfStrings *[]string `json:"TestArrayOfStrings,omitempty"` + // + TestArrayOfUri *[]string `json:"TestArrayOfUri,omitempty"` + // The HTTP method that we should use to request the `TestArrayOfUri`. + TestMethod *string `json:"TestMethod,omitempty"` } -func (params *CreateCallParams) SetPathAccountSid(PathAccountSid string) (*CreateCallParams){ - params.PathAccountSid = &PathAccountSid - return params +func (params *CreateCallParams) SetPathAccountSid(PathAccountSid string) *CreateCallParams { + params.PathAccountSid = &PathAccountSid + return params } -func (params *CreateCallParams) SetRequiredStringProperty(RequiredStringProperty string) (*CreateCallParams){ - params.RequiredStringProperty = &RequiredStringProperty - return params +func (params *CreateCallParams) SetRequiredStringProperty(RequiredStringProperty string) *CreateCallParams { + params.RequiredStringProperty = &RequiredStringProperty + return params } -func (params *CreateCallParams) SetTestArrayOfStrings(TestArrayOfStrings []string) (*CreateCallParams){ - params.TestArrayOfStrings = &TestArrayOfStrings - return params +func (params *CreateCallParams) SetTestArrayOfStrings(TestArrayOfStrings []string) *CreateCallParams { + params.TestArrayOfStrings = &TestArrayOfStrings + return params } -func (params *CreateCallParams) SetTestArrayOfUri(TestArrayOfUri []string) (*CreateCallParams){ - params.TestArrayOfUri = &TestArrayOfUri - return params +func (params *CreateCallParams) SetTestArrayOfUri(TestArrayOfUri []string) *CreateCallParams { + params.TestArrayOfUri = &TestArrayOfUri + return params } -func (params *CreateCallParams) SetTestMethod(TestMethod string) (*CreateCallParams){ - params.TestMethod = &TestMethod - return params +func (params *CreateCallParams) SetTestMethod(TestMethod string) *CreateCallParams { + params.TestMethod = &TestMethod + return params } func (c *ApiService) CreateCall(params *CreateCallParams) (*TestResponseObject, error) { - path := "/2010-04-01/Accounts/{AccountSid}/Calls.json" - if params != nil && params.PathAccountSid != nil { - path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) -} else { - path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) -} - -data := url.Values{} -headers := make(map[string]interface{}) - -if params != nil && params.RequiredStringProperty != nil { - data.Set("RequiredStringProperty", *params.RequiredStringProperty) -} -if params != nil && params.TestArrayOfStrings != nil { - for _, item := range *params.TestArrayOfStrings { - data.Add("TestArrayOfStrings", item) - } -} -if params != nil && params.TestArrayOfUri != nil { - for _, item := range *params.TestArrayOfUri { - data.Add("TestArrayOfUri", item) - } -} -if params != nil && params.TestMethod != nil { - data.Set("TestMethod", *params.TestMethod) -} - - - - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } - - defer resp.Body.Close() - - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } - - return ps, err + path := "/2010-04-01/Accounts/{AccountSid}/Calls.json" + if params != nil && params.PathAccountSid != nil { + path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) + } else { + path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) + } + + data := url.Values{} + headers := make(map[string]interface{}) + + if params != nil && params.RequiredStringProperty != nil { + data.Set("RequiredStringProperty", *params.RequiredStringProperty) + } + if params != nil && params.TestArrayOfStrings != nil { + for _, item := range *params.TestArrayOfStrings { + data.Add("TestArrayOfStrings", item) + } + } + if params != nil && params.TestArrayOfUri != nil { + for _, item := range *params.TestArrayOfUri { + data.Add("TestArrayOfUri", item) + } + } + if params != nil && params.TestMethod != nil { + data.Set("TestMethod", *params.TestMethod) + } + + resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } + + defer resp.Body.Close() + + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } + + return ps, err } // Optional parameters for the method 'DeleteCall' type DeleteCallParams struct { - // - PathAccountSid *string `json:"PathAccountSid,omitempty"` -} - -func (params *DeleteCallParams) SetPathAccountSid(PathAccountSid string) (*DeleteCallParams){ - params.PathAccountSid = &PathAccountSid - return params + // + PathAccountSid *string `json:"PathAccountSid,omitempty"` } -func (c *ApiService) DeleteCall(TestInteger int, params *DeleteCallParams) (error) { - path := "/2010-04-01/Accounts/{AccountSid}/Calls/{TestInteger}.json" - if params != nil && params.PathAccountSid != nil { - path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) -} else { - path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) +func (params *DeleteCallParams) SetPathAccountSid(PathAccountSid string) *DeleteCallParams { + params.PathAccountSid = &PathAccountSid + return params } - path = strings.Replace(path, "{"+"TestInteger"+"}", fmt.Sprint(TestInteger), -1) - -data := url.Values{} -headers := make(map[string]interface{}) +func (c *ApiService) DeleteCall(TestInteger int, params *DeleteCallParams) error { + path := "/2010-04-01/Accounts/{AccountSid}/Calls/{TestInteger}.json" + if params != nil && params.PathAccountSid != nil { + path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) + } else { + path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) + } + path = strings.Replace(path, "{"+"TestInteger"+"}", fmt.Sprint(TestInteger), -1) + data := url.Values{} + headers := make(map[string]interface{}) + resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + if err != nil { + return err + } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) - if err != nil { - return err - } + defer resp.Body.Close() - defer resp.Body.Close() - - return nil + return nil } // Optional parameters for the method 'FetchCall' type FetchCallParams struct { - // - PathAccountSid *string `json:"PathAccountSid,omitempty"` + // + PathAccountSid *string `json:"PathAccountSid,omitempty"` } -func (params *FetchCallParams) SetPathAccountSid(PathAccountSid string) (*FetchCallParams){ - params.PathAccountSid = &PathAccountSid - return params +func (params *FetchCallParams) SetPathAccountSid(PathAccountSid string) *FetchCallParams { + params.PathAccountSid = &PathAccountSid + return params } func (c *ApiService) FetchCall(TestInteger int, params *FetchCallParams) (*TestResponseObject, error) { - path := "/2010-04-01/Accounts/{AccountSid}/Calls/{TestInteger}.json" - if params != nil && params.PathAccountSid != nil { - path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) -} else { - path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) -} - path = strings.Replace(path, "{"+"TestInteger"+"}", fmt.Sprint(TestInteger), -1) - -data := url.Values{} -headers := make(map[string]interface{}) - - - - - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } - - defer resp.Body.Close() - - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } - - return ps, err + path := "/2010-04-01/Accounts/{AccountSid}/Calls/{TestInteger}.json" + if params != nil && params.PathAccountSid != nil { + path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) + } else { + path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) + } + path = strings.Replace(path, "{"+"TestInteger"+"}", fmt.Sprint(TestInteger), -1) + + data := url.Values{} + headers := make(map[string]interface{}) + + resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } + + defer resp.Body.Close() + + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } + + return ps, err } diff --git a/examples/go/go-client/helper/rest/api/v2010/accounts_calls_feedback_summary.go b/examples/go/go-client/helper/rest/api/v2010/accounts_calls_feedback_summary.go index f95684b1b..2af1473db 100644 --- a/examples/go/go-client/helper/rest/api/v2010/accounts_calls_feedback_summary.go +++ b/examples/go/go-client/helper/rest/api/v2010/accounts_calls_feedback_summary.go @@ -18,75 +18,71 @@ import ( "encoding/json" "fmt" "net/url" - - "github.com/twilio/twilio-go/client" + "strings" ) - // Optional parameters for the method 'UpdateCallFeedbackSummary' type UpdateCallFeedbackSummaryParams struct { - // - PathAccountSid *string `json:"PathAccountSid,omitempty"` - // - AccountSid *string `json:"AccountSid,omitempty"` - // - EndDate *string `json:"EndDate,omitempty"` - // - StartDate *string `json:"StartDate,omitempty"` + // + PathAccountSid *string `json:"PathAccountSid,omitempty"` + // + AccountSid *string `json:"AccountSid,omitempty"` + // + EndDate *string `json:"EndDate,omitempty"` + // + StartDate *string `json:"StartDate,omitempty"` } -func (params *UpdateCallFeedbackSummaryParams) SetPathAccountSid(PathAccountSid string) (*UpdateCallFeedbackSummaryParams){ - params.PathAccountSid = &PathAccountSid - return params +func (params *UpdateCallFeedbackSummaryParams) SetPathAccountSid(PathAccountSid string) *UpdateCallFeedbackSummaryParams { + params.PathAccountSid = &PathAccountSid + return params } -func (params *UpdateCallFeedbackSummaryParams) SetAccountSid(AccountSid string) (*UpdateCallFeedbackSummaryParams){ - params.AccountSid = &AccountSid - return params +func (params *UpdateCallFeedbackSummaryParams) SetAccountSid(AccountSid string) *UpdateCallFeedbackSummaryParams { + params.AccountSid = &AccountSid + return params } -func (params *UpdateCallFeedbackSummaryParams) SetEndDate(EndDate string) (*UpdateCallFeedbackSummaryParams){ - params.EndDate = &EndDate - return params +func (params *UpdateCallFeedbackSummaryParams) SetEndDate(EndDate string) *UpdateCallFeedbackSummaryParams { + params.EndDate = &EndDate + return params } -func (params *UpdateCallFeedbackSummaryParams) SetStartDate(StartDate string) (*UpdateCallFeedbackSummaryParams){ - params.StartDate = &StartDate - return params +func (params *UpdateCallFeedbackSummaryParams) SetStartDate(StartDate string) *UpdateCallFeedbackSummaryParams { + params.StartDate = &StartDate + return params } func (c *ApiService) UpdateCallFeedbackSummary(Sid string, params *UpdateCallFeedbackSummaryParams) (*TestResponseObject, error) { - path := "/2010-04-01/Accounts/{AccountSid}/Calls/Feedback/Summary/{Sid}.json" - if params != nil && params.PathAccountSid != nil { - path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) -} else { - path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) -} - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) - -data := url.Values{} -headers := make(map[string]interface{}) - -if params != nil && params.AccountSid != nil { - data.Set("AccountSid", *params.AccountSid) -} -if params != nil && params.EndDate != nil { - data.Set("EndDate", fmt.Sprint(*params.EndDate)) -} -if params != nil && params.StartDate != nil { - data.Set("StartDate", fmt.Sprint(*params.StartDate)) -} + path := "/2010-04-01/Accounts/{AccountSid}/Calls/Feedback/Summary/{Sid}.json" + if params != nil && params.PathAccountSid != nil { + path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) + } else { + path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) + } + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) + data := url.Values{} + headers := make(map[string]interface{}) + if params != nil && params.AccountSid != nil { + data.Set("AccountSid", *params.AccountSid) + } + if params != nil && params.EndDate != nil { + data.Set("EndDate", fmt.Sprint(*params.EndDate)) + } + if params != nil && params.StartDate != nil { + data.Set("StartDate", fmt.Sprint(*params.StartDate)) + } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } + resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - defer resp.Body.Close() + defer resp.Body.Close() - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } - return ps, err + return ps, err } diff --git a/examples/go/go-client/helper/rest/api/v2010/api_service.go b/examples/go/go-client/helper/rest/api/v2010/api_service.go index a9f72042f..ec27f348d 100644 --- a/examples/go/go-client/helper/rest/api/v2010/api_service.go +++ b/examples/go/go-client/helper/rest/api/v2010/api_service.go @@ -15,7 +15,7 @@ package openapi import ( - twilio "github.com/twilio/twilio-go/client" + twilio "github.com/twilio/twilio-go/client" ) type ApiService struct { @@ -24,12 +24,12 @@ type ApiService struct { } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { - return &ApiService { + return &ApiService{ requestHandler: requestHandler, baseURL: "https://api.twilio.com", } } func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { - return NewApiService(twilio.NewRequestHandler(client)) + return NewApiService(twilio.NewRequestHandler(client)) } diff --git a/examples/go/go-client/helper/rest/api/v2010/model_list_account_response.go b/examples/go/go-client/helper/rest/api/v2010/model_list_account_response.go index f98d70007..40053642d 100644 --- a/examples/go/go-client/helper/rest/api/v2010/model_list_account_response.go +++ b/examples/go/go-client/helper/rest/api/v2010/model_list_account_response.go @@ -13,21 +13,16 @@ */ package openapi -import ( - "encoding/json" - "github.com/twilio/twilio-go/client" -) + // ListAccountResponse struct for ListAccountResponse type ListAccountResponse struct { - End int `json:"end,omitempty"` - FirstPageUri string `json:"first_page_uri,omitempty"` - NextPageUri string `json:"next_page_uri,omitempty"` - Page int `json:"page,omitempty"` - PageSize int `json:"page_size,omitempty"` - PreviousPageUri string `json:"previous_page_uri,omitempty"` - Accounts []TestResponseObject `json:"accounts,omitempty"` - Start int `json:"start,omitempty"` - Uri string `json:"uri,omitempty"` + End int `json:"end,omitempty"` + FirstPageUri string `json:"first_page_uri,omitempty"` + NextPageUri string `json:"next_page_uri,omitempty"` + Page int `json:"page,omitempty"` + PageSize int `json:"page_size,omitempty"` + PreviousPageUri string `json:"previous_page_uri,omitempty"` + Accounts []TestResponseObject `json:"accounts,omitempty"` + Start int `json:"start,omitempty"` + Uri string `json:"uri,omitempty"` } - - diff --git a/examples/go/go-client/helper/rest/api/v2010/model_test_response_object.go b/examples/go/go-client/helper/rest/api/v2010/model_test_response_object.go index 849ad2583..ab294fc6c 100644 --- a/examples/go/go-client/helper/rest/api/v2010/model_test_response_object.go +++ b/examples/go/go-client/helper/rest/api/v2010/model_test_response_object.go @@ -13,52 +13,55 @@ */ package openapi + import ( "encoding/json" + "github.com/twilio/twilio-go/client" ) + // TestResponseObject struct for TestResponseObject type TestResponseObject struct { - AccountSid *string `json:"account_sid,omitempty"` - Sid *string `json:"sid,omitempty"` - TestString *string `json:"test_string,omitempty"` - TestInteger *int `json:"test_integer,omitempty"` - TestObject *TestResponseObjectTestObject `json:"test_object,omitempty"` - TestDateTime *string `json:"test_date_time,omitempty"` - TestNumber *float32 `json:"test_number,omitempty"` - From *string `json:"from,omitempty"` - PriceUnit *string `json:"price_unit,omitempty"` - TestNumberFloat *float32 `json:"test_number_float,omitempty"` - TestNumberDecimal *float64 `json:"test_number_decimal,omitempty"` - TestEnum *string `json:"test_enum,omitempty"` - // A2P Messaging Profile Bundle BundleSid - A2pProfileBundleSid *string `json:"a2p_profile_bundle_sid,omitempty"` - TestArrayOfIntegers []int `json:"test_array_of_integers,omitempty"` - TestArrayOfArrayOfIntegers [][]int `json:"test_array_of_array_of_integers,omitempty"` - TestArrayOfObjects *[]TestResponseObjectTestArrayOfObjects `json:"test_array_of_objects,omitempty"` - // Permissions authorized to the app + AccountSid *string `json:"account_sid,omitempty"` + Sid *string `json:"sid,omitempty"` + TestString *string `json:"test_string,omitempty"` + TestInteger *int `json:"test_integer,omitempty"` + TestObject *TestResponseObjectTestObject `json:"test_object,omitempty"` + TestDateTime *string `json:"test_date_time,omitempty"` + TestNumber *float32 `json:"test_number,omitempty"` + From *string `json:"from,omitempty"` + PriceUnit *string `json:"price_unit,omitempty"` + TestNumberFloat *float32 `json:"test_number_float,omitempty"` + TestNumberDecimal *float64 `json:"test_number_decimal,omitempty"` + TestEnum *string `json:"test_enum,omitempty"` + // A2P Messaging Profile Bundle BundleSid + A2pProfileBundleSid *string `json:"a2p_profile_bundle_sid,omitempty"` + TestArrayOfIntegers []int `json:"test_array_of_integers,omitempty"` + TestArrayOfArrayOfIntegers [][]int `json:"test_array_of_array_of_integers,omitempty"` + TestArrayOfObjects *[]TestResponseObjectTestArrayOfObjects `json:"test_array_of_objects,omitempty"` + // Permissions authorized to the app TestArrayOfEnum *[]string `json:"test_array_of_enum,omitempty"` } func (response *TestResponseObject) UnmarshalJSON(bytes []byte) (err error) { raw := struct { - AccountSid *string `json:"account_sid"` - Sid *string `json:"sid"` - TestString *string `json:"test_string"` - TestInteger *int `json:"test_integer"` - TestObject *TestResponseObjectTestObject `json:"test_object"` - TestDateTime *string `json:"test_date_time"` - TestNumber *interface{} `json:"test_number"` - From *string `json:"from"` - PriceUnit *string `json:"price_unit"` - TestNumberFloat *interface{} `json:"test_number_float"` - TestNumberDecimal *float64 `json:"test_number_decimal"` - TestEnum *string `json:"test_enum"` - A2pProfileBundleSid *string `json:"a2p_profile_bundle_sid"` - TestArrayOfIntegers []int `json:"test_array_of_integers"` - TestArrayOfArrayOfIntegers [][]int `json:"test_array_of_array_of_integers"` - TestArrayOfObjects *[]TestResponseObjectTestArrayOfObjects `json:"test_array_of_objects"` - TestArrayOfEnum *[]string `json:"test_array_of_enum"` + AccountSid *string `json:"account_sid"` + Sid *string `json:"sid"` + TestString *string `json:"test_string"` + TestInteger *int `json:"test_integer"` + TestObject *TestResponseObjectTestObject `json:"test_object"` + TestDateTime *string `json:"test_date_time"` + TestNumber *interface{} `json:"test_number"` + From *string `json:"from"` + PriceUnit *string `json:"price_unit"` + TestNumberFloat *interface{} `json:"test_number_float"` + TestNumberDecimal *float64 `json:"test_number_decimal"` + TestEnum *string `json:"test_enum"` + A2pProfileBundleSid *string `json:"a2p_profile_bundle_sid"` + TestArrayOfIntegers []int `json:"test_array_of_integers"` + TestArrayOfArrayOfIntegers [][]int `json:"test_array_of_array_of_integers"` + TestArrayOfObjects *[]TestResponseObjectTestArrayOfObjects `json:"test_array_of_objects"` + TestArrayOfEnum *[]string `json:"test_array_of_enum"` }{} if err = json.Unmarshal(bytes, &raw); err != nil { @@ -66,21 +69,21 @@ func (response *TestResponseObject) UnmarshalJSON(bytes []byte) (err error) { } *response = TestResponseObject{ - AccountSid: raw.AccountSid, - Sid: raw.Sid, - TestString: raw.TestString, - TestInteger: raw.TestInteger, - TestObject: raw.TestObject, - TestDateTime: raw.TestDateTime, - From: raw.From, - PriceUnit: raw.PriceUnit, - TestNumberDecimal: raw.TestNumberDecimal, - TestEnum: raw.TestEnum, - A2pProfileBundleSid: raw.A2pProfileBundleSid, - TestArrayOfIntegers: raw.TestArrayOfIntegers, + AccountSid: raw.AccountSid, + Sid: raw.Sid, + TestString: raw.TestString, + TestInteger: raw.TestInteger, + TestObject: raw.TestObject, + TestDateTime: raw.TestDateTime, + From: raw.From, + PriceUnit: raw.PriceUnit, + TestNumberDecimal: raw.TestNumberDecimal, + TestEnum: raw.TestEnum, + A2pProfileBundleSid: raw.A2pProfileBundleSid, + TestArrayOfIntegers: raw.TestArrayOfIntegers, TestArrayOfArrayOfIntegers: raw.TestArrayOfArrayOfIntegers, - TestArrayOfObjects: raw.TestArrayOfObjects, - TestArrayOfEnum: raw.TestArrayOfEnum, + TestArrayOfObjects: raw.TestArrayOfObjects, + TestArrayOfEnum: raw.TestArrayOfEnum, } responseTestNumber, err := client.UnmarshalFloat32(raw.TestNumber) @@ -97,4 +100,3 @@ func (response *TestResponseObject) UnmarshalJSON(bytes []byte) (err error) { return } - diff --git a/examples/go/go-client/helper/rest/api/v2010/model_test_response_object_test_array_of_objects.go b/examples/go/go-client/helper/rest/api/v2010/model_test_response_object_test_array_of_objects.go index caa54fc4e..dd4cf95b1 100644 --- a/examples/go/go-client/helper/rest/api/v2010/model_test_response_object_test_array_of_objects.go +++ b/examples/go/go-client/helper/rest/api/v2010/model_test_response_object_test_array_of_objects.go @@ -13,20 +13,23 @@ */ package openapi + import ( "encoding/json" + "github.com/twilio/twilio-go/client" ) + // TestResponseObjectTestArrayOfObjects struct for TestResponseObjectTestArrayOfObjects type TestResponseObjectTestArrayOfObjects struct { - Count float32 `json:"count,omitempty"` - Description string `json:"description,omitempty"` + Count float32 `json:"count,omitempty"` + Description string `json:"description,omitempty"` } func (response *TestResponseObjectTestArrayOfObjects) UnmarshalJSON(bytes []byte) (err error) { raw := struct { - Count interface{} `json:"count"` - Description string `json:"description"` + Count interface{} `json:"count"` + Description string `json:"description"` }{} if err = json.Unmarshal(bytes, &raw); err != nil { @@ -45,4 +48,3 @@ func (response *TestResponseObjectTestArrayOfObjects) UnmarshalJSON(bytes []byte return } - diff --git a/examples/go/go-client/helper/rest/api/v2010/model_test_response_object_test_object.go b/examples/go/go-client/helper/rest/api/v2010/model_test_response_object_test_object.go index acfe3e54b..d14eb45d9 100644 --- a/examples/go/go-client/helper/rest/api/v2010/model_test_response_object_test_object.go +++ b/examples/go/go-client/helper/rest/api/v2010/model_test_response_object_test_object.go @@ -13,16 +13,11 @@ */ package openapi -import ( - "encoding/json" - "github.com/twilio/twilio-go/client" -) + // TestResponseObjectTestObject struct for TestResponseObjectTestObject type TestResponseObjectTestObject struct { - Fax bool `json:"fax,omitempty"` - Mms bool `json:"mms,omitempty"` - Sms bool `json:"sms,omitempty"` + Fax bool `json:"fax,omitempty"` + Mms bool `json:"mms,omitempty"` + Sms bool `json:"sms,omitempty"` Voice bool `json:"voice,omitempty"` } - - diff --git a/examples/go/go-client/helper/rest/flex/v1/api_service.go b/examples/go/go-client/helper/rest/flex/v1/api_service.go index 3e378b57d..82f8c08f2 100644 --- a/examples/go/go-client/helper/rest/flex/v1/api_service.go +++ b/examples/go/go-client/helper/rest/flex/v1/api_service.go @@ -15,7 +15,7 @@ package openapi import ( - twilio "github.com/twilio/twilio-go/client" + twilio "github.com/twilio/twilio-go/client" ) type ApiService struct { @@ -24,12 +24,12 @@ type ApiService struct { } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { - return &ApiService { + return &ApiService{ requestHandler: requestHandler, baseURL: "https://flex-api.twilio.com", } } func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { - return NewApiService(twilio.NewRequestHandler(client)) + return NewApiService(twilio.NewRequestHandler(client)) } diff --git a/examples/go/go-client/helper/rest/flex/v1/credentials_aws.go b/examples/go/go-client/helper/rest/flex/v1/credentials_aws.go index b02ea6851..686eb5450 100644 --- a/examples/go/go-client/helper/rest/flex/v1/credentials_aws.go +++ b/examples/go/go-client/helper/rest/flex/v1/credentials_aws.go @@ -18,317 +18,309 @@ import ( "encoding/json" "fmt" "net/url" + "strings" + "time" - "github.com/twilio/twilio-go/client" + "github.com/twilio/twilio-go/client" ) - // Optional parameters for the method 'CreateCredentialAws' type CreateCredentialAwsParams struct { - // - TestString *string `json:"TestString,omitempty"` - // - TestBoolean *bool `json:"TestBoolean,omitempty"` - // - TestInteger *int `json:"TestInteger,omitempty"` - // - TestNumber *float32 `json:"TestNumber,omitempty"` - // - TestNumberFloat *float32 `json:"TestNumberFloat,omitempty"` - // - TestNumberDouble *float64 `json:"TestNumberDouble,omitempty"` - // - TestNumberInt32 *float32 `json:"TestNumberInt32,omitempty"` - // - TestNumberInt64 *int64 `json:"TestNumberInt64,omitempty"` - // - TestObject *map[string]interface{} `json:"TestObject,omitempty"` - // - TestDateTime *time.Time `json:"TestDateTime,omitempty"` - // - TestDate *string `json:"TestDate,omitempty"` - // - TestEnum *string `json:"TestEnum,omitempty"` - // - TestObjectArray *[]map[string]interface{} `json:"TestObjectArray,omitempty"` - // - TestAnyType *interface{} `json:"TestAnyType,omitempty"` - // - TestAnyArray *[]interface{} `json:"TestAnyArray,omitempty"` - // A comma-separated list of the permissions you will request from the users of this ConnectApp. Can include: `get-all` and `post-all`. - Permissions *[]string `json:"Permissions,omitempty"` - // - SomeA2PThing *string `json:"SomeA2PThing,omitempty"` -} - -func (params *CreateCredentialAwsParams) SetTestString(TestString string) (*CreateCredentialAwsParams){ - params.TestString = &TestString - return params -} -func (params *CreateCredentialAwsParams) SetTestBoolean(TestBoolean bool) (*CreateCredentialAwsParams){ - params.TestBoolean = &TestBoolean - return params -} -func (params *CreateCredentialAwsParams) SetTestInteger(TestInteger int) (*CreateCredentialAwsParams){ - params.TestInteger = &TestInteger - return params -} -func (params *CreateCredentialAwsParams) SetTestNumber(TestNumber float32) (*CreateCredentialAwsParams){ - params.TestNumber = &TestNumber - return params -} -func (params *CreateCredentialAwsParams) SetTestNumberFloat(TestNumberFloat float32) (*CreateCredentialAwsParams){ - params.TestNumberFloat = &TestNumberFloat - return params -} -func (params *CreateCredentialAwsParams) SetTestNumberDouble(TestNumberDouble float64) (*CreateCredentialAwsParams){ - params.TestNumberDouble = &TestNumberDouble - return params -} -func (params *CreateCredentialAwsParams) SetTestNumberInt32(TestNumberInt32 float32) (*CreateCredentialAwsParams){ - params.TestNumberInt32 = &TestNumberInt32 - return params -} -func (params *CreateCredentialAwsParams) SetTestNumberInt64(TestNumberInt64 int64) (*CreateCredentialAwsParams){ - params.TestNumberInt64 = &TestNumberInt64 - return params -} -func (params *CreateCredentialAwsParams) SetTestObject(TestObject map[string]interface{}) (*CreateCredentialAwsParams){ - params.TestObject = &TestObject - return params -} -func (params *CreateCredentialAwsParams) SetTestDateTime(TestDateTime time.Time) (*CreateCredentialAwsParams){ - params.TestDateTime = &TestDateTime - return params -} -func (params *CreateCredentialAwsParams) SetTestDate(TestDate string) (*CreateCredentialAwsParams){ - params.TestDate = &TestDate - return params -} -func (params *CreateCredentialAwsParams) SetTestEnum(TestEnum string) (*CreateCredentialAwsParams){ - params.TestEnum = &TestEnum - return params -} -func (params *CreateCredentialAwsParams) SetTestObjectArray(TestObjectArray []map[string]interface{}) (*CreateCredentialAwsParams){ - params.TestObjectArray = &TestObjectArray - return params -} -func (params *CreateCredentialAwsParams) SetTestAnyType(TestAnyType interface{}) (*CreateCredentialAwsParams){ - params.TestAnyType = &TestAnyType - return params -} -func (params *CreateCredentialAwsParams) SetTestAnyArray(TestAnyArray []interface{}) (*CreateCredentialAwsParams){ - params.TestAnyArray = &TestAnyArray - return params -} -func (params *CreateCredentialAwsParams) SetPermissions(Permissions []string) (*CreateCredentialAwsParams){ - params.Permissions = &Permissions - return params -} -func (params *CreateCredentialAwsParams) SetSomeA2PThing(SomeA2PThing string) (*CreateCredentialAwsParams){ - params.SomeA2PThing = &SomeA2PThing - return params + // + TestString *string `json:"TestString,omitempty"` + // + TestBoolean *bool `json:"TestBoolean,omitempty"` + // + TestInteger *int `json:"TestInteger,omitempty"` + // + TestNumber *float32 `json:"TestNumber,omitempty"` + // + TestNumberFloat *float32 `json:"TestNumberFloat,omitempty"` + // + TestNumberDouble *float64 `json:"TestNumberDouble,omitempty"` + // + TestNumberInt32 *float32 `json:"TestNumberInt32,omitempty"` + // + TestNumberInt64 *int64 `json:"TestNumberInt64,omitempty"` + // + TestObject *map[string]interface{} `json:"TestObject,omitempty"` + // + TestDateTime *time.Time `json:"TestDateTime,omitempty"` + // + TestDate *string `json:"TestDate,omitempty"` + // + TestEnum *string `json:"TestEnum,omitempty"` + // + TestObjectArray *[]map[string]interface{} `json:"TestObjectArray,omitempty"` + // + TestAnyType *interface{} `json:"TestAnyType,omitempty"` + // + TestAnyArray *[]interface{} `json:"TestAnyArray,omitempty"` + // A comma-separated list of the permissions you will request from the users of this ConnectApp. Can include: `get-all` and `post-all`. + Permissions *[]string `json:"Permissions,omitempty"` + // + SomeA2PThing *string `json:"SomeA2PThing,omitempty"` +} + +func (params *CreateCredentialAwsParams) SetTestString(TestString string) *CreateCredentialAwsParams { + params.TestString = &TestString + return params +} +func (params *CreateCredentialAwsParams) SetTestBoolean(TestBoolean bool) *CreateCredentialAwsParams { + params.TestBoolean = &TestBoolean + return params +} +func (params *CreateCredentialAwsParams) SetTestInteger(TestInteger int) *CreateCredentialAwsParams { + params.TestInteger = &TestInteger + return params +} +func (params *CreateCredentialAwsParams) SetTestNumber(TestNumber float32) *CreateCredentialAwsParams { + params.TestNumber = &TestNumber + return params +} +func (params *CreateCredentialAwsParams) SetTestNumberFloat(TestNumberFloat float32) *CreateCredentialAwsParams { + params.TestNumberFloat = &TestNumberFloat + return params +} +func (params *CreateCredentialAwsParams) SetTestNumberDouble(TestNumberDouble float64) *CreateCredentialAwsParams { + params.TestNumberDouble = &TestNumberDouble + return params +} +func (params *CreateCredentialAwsParams) SetTestNumberInt32(TestNumberInt32 float32) *CreateCredentialAwsParams { + params.TestNumberInt32 = &TestNumberInt32 + return params +} +func (params *CreateCredentialAwsParams) SetTestNumberInt64(TestNumberInt64 int64) *CreateCredentialAwsParams { + params.TestNumberInt64 = &TestNumberInt64 + return params +} +func (params *CreateCredentialAwsParams) SetTestObject(TestObject map[string]interface{}) *CreateCredentialAwsParams { + params.TestObject = &TestObject + return params +} +func (params *CreateCredentialAwsParams) SetTestDateTime(TestDateTime time.Time) *CreateCredentialAwsParams { + params.TestDateTime = &TestDateTime + return params +} +func (params *CreateCredentialAwsParams) SetTestDate(TestDate string) *CreateCredentialAwsParams { + params.TestDate = &TestDate + return params +} +func (params *CreateCredentialAwsParams) SetTestEnum(TestEnum string) *CreateCredentialAwsParams { + params.TestEnum = &TestEnum + return params +} +func (params *CreateCredentialAwsParams) SetTestObjectArray(TestObjectArray []map[string]interface{}) *CreateCredentialAwsParams { + params.TestObjectArray = &TestObjectArray + return params +} +func (params *CreateCredentialAwsParams) SetTestAnyType(TestAnyType interface{}) *CreateCredentialAwsParams { + params.TestAnyType = &TestAnyType + return params +} +func (params *CreateCredentialAwsParams) SetTestAnyArray(TestAnyArray []interface{}) *CreateCredentialAwsParams { + params.TestAnyArray = &TestAnyArray + return params +} +func (params *CreateCredentialAwsParams) SetPermissions(Permissions []string) *CreateCredentialAwsParams { + params.Permissions = &Permissions + return params +} +func (params *CreateCredentialAwsParams) SetSomeA2PThing(SomeA2PThing string) *CreateCredentialAwsParams { + params.SomeA2PThing = &SomeA2PThing + return params } func (c *ApiService) CreateCredentialAws(params *CreateCredentialAwsParams) (*TestResponseObject, error) { - path := "/v1/Credentials/AWS" - -data := url.Values{} -headers := make(map[string]interface{}) - -if params != nil && params.TestString != nil { - data.Set("TestString", *params.TestString) -} -if params != nil && params.TestBoolean != nil { - data.Set("TestBoolean", fmt.Sprint(*params.TestBoolean)) -} -if params != nil && params.TestInteger != nil { - data.Set("TestInteger", fmt.Sprint(*params.TestInteger)) -} -if params != nil && params.TestNumber != nil { - data.Set("TestNumber", fmt.Sprint(*params.TestNumber)) -} -if params != nil && params.TestNumberFloat != nil { - data.Set("TestNumberFloat", fmt.Sprint(*params.TestNumberFloat)) -} -if params != nil && params.TestNumberDouble != nil { - data.Set("TestNumberDouble", fmt.Sprint(*params.TestNumberDouble)) -} -if params != nil && params.TestNumberInt32 != nil { - data.Set("TestNumberInt32", fmt.Sprint(*params.TestNumberInt32)) -} -if params != nil && params.TestNumberInt64 != nil { - data.Set("TestNumberInt64", fmt.Sprint(*params.TestNumberInt64)) -} -if params != nil && params.TestObject != nil { - v, err := json.Marshal(params.TestObject) + path := "/v1/Credentials/AWS" - if err != nil { - return nil, err - } + data := url.Values{} + headers := make(map[string]interface{}) - data.Set("TestObject", string(v)) -} -if params != nil && params.TestDateTime != nil { - data.Set("TestDateTime", fmt.Sprint((*params.TestDateTime).Format(time.RFC3339))) -} -if params != nil && params.TestDate != nil { - data.Set("TestDate", fmt.Sprint(*params.TestDate)) -} -if params != nil && params.TestEnum != nil { - data.Set("TestEnum", *params.TestEnum) -} -if params != nil && params.TestObjectArray != nil { - for _, item := range *params.TestObjectArray { - v, err := json.Marshal(item) + if params != nil && params.TestString != nil { + data.Set("TestString", *params.TestString) + } + if params != nil && params.TestBoolean != nil { + data.Set("TestBoolean", fmt.Sprint(*params.TestBoolean)) + } + if params != nil && params.TestInteger != nil { + data.Set("TestInteger", fmt.Sprint(*params.TestInteger)) + } + if params != nil && params.TestNumber != nil { + data.Set("TestNumber", fmt.Sprint(*params.TestNumber)) + } + if params != nil && params.TestNumberFloat != nil { + data.Set("TestNumberFloat", fmt.Sprint(*params.TestNumberFloat)) + } + if params != nil && params.TestNumberDouble != nil { + data.Set("TestNumberDouble", fmt.Sprint(*params.TestNumberDouble)) + } + if params != nil && params.TestNumberInt32 != nil { + data.Set("TestNumberInt32", fmt.Sprint(*params.TestNumberInt32)) + } + if params != nil && params.TestNumberInt64 != nil { + data.Set("TestNumberInt64", fmt.Sprint(*params.TestNumberInt64)) + } + if params != nil && params.TestObject != nil { + v, err := json.Marshal(params.TestObject) - if err != nil { - return nil, err - } + if err != nil { + return nil, err + } - data.Add("TestObjectArray", string(v)) - } -} -if params != nil && params.TestAnyType != nil { - v, err := json.Marshal(params.TestAnyType) + data.Set("TestObject", string(v)) + } + if params != nil && params.TestDateTime != nil { + data.Set("TestDateTime", fmt.Sprint((*params.TestDateTime).Format(time.RFC3339))) + } + if params != nil && params.TestDate != nil { + data.Set("TestDate", fmt.Sprint(*params.TestDate)) + } + if params != nil && params.TestEnum != nil { + data.Set("TestEnum", *params.TestEnum) + } + if params != nil && params.TestObjectArray != nil { + for _, item := range *params.TestObjectArray { + v, err := json.Marshal(item) - if err != nil { - return nil, err - } + if err != nil { + return nil, err + } - data.Set("TestAnyType", string(v)) -} -if params != nil && params.TestAnyArray != nil { - for _, item := range *params.TestAnyArray { - v, err := json.Marshal(item) + data.Add("TestObjectArray", string(v)) + } + } + if params != nil && params.TestAnyType != nil { + v, err := json.Marshal(params.TestAnyType) - if err != nil { - return nil, err - } + if err != nil { + return nil, err + } - data.Add("TestAnyArray", string(v)) - } -} -if params != nil && params.Permissions != nil { - for _, item := range *params.Permissions { - data.Add("Permissions", item) - } -} -if params != nil && params.SomeA2PThing != nil { - data.Set("SomeA2PThing", *params.SomeA2PThing) -} + data.Set("TestAnyType", string(v)) + } + if params != nil && params.TestAnyArray != nil { + for _, item := range *params.TestAnyArray { + v, err := json.Marshal(item) + if err != nil { + return nil, err + } + data.Add("TestAnyArray", string(v)) + } + } + if params != nil && params.Permissions != nil { + for _, item := range *params.Permissions { + data.Add("Permissions", item) + } + } + if params != nil && params.SomeA2PThing != nil { + data.Set("SomeA2PThing", *params.SomeA2PThing) + } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } + resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - defer resp.Body.Close() + defer resp.Body.Close() - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } - return ps, err + return ps, err } -func (c *ApiService) DeleteCredentialAws(Sid string, ) (error) { - path := "/v1/Credentials/AWS/{Sid}" - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) - -data := url.Values{} -headers := make(map[string]interface{}) - +func (c *ApiService) DeleteCredentialAws(Sid string) error { + path := "/v1/Credentials/AWS/{Sid}" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) + data := url.Values{} + headers := make(map[string]interface{}) + resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + if err != nil { + return err + } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) - if err != nil { - return err - } - - defer resp.Body.Close() + defer resp.Body.Close() - return nil + return nil } -func (c *ApiService) FetchCredentialAws(Sid string, ) (*TestResponseObject, error) { - path := "/v1/Credentials/AWS/{Sid}" - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) - -data := url.Values{} -headers := make(map[string]interface{}) - - +func (c *ApiService) FetchCredentialAws(Sid string) (*TestResponseObject, error) { + path := "/v1/Credentials/AWS/{Sid}" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) + data := url.Values{} + headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } + resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - defer resp.Body.Close() + defer resp.Body.Close() - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } - return ps, err + return ps, err } // Optional parameters for the method 'ListCredentialAws' type ListCredentialAwsParams struct { - // - PageSize *int `json:"PageSize,omitempty"` - // Max number of records to return. - Limit *int `json:"limit,omitempty"` + // + PageSize *int `json:"PageSize,omitempty"` + // Max number of records to return. + Limit *int `json:"limit,omitempty"` } -func (params *ListCredentialAwsParams) SetPageSize(PageSize int) (*ListCredentialAwsParams){ - params.PageSize = &PageSize - return params +func (params *ListCredentialAwsParams) SetPageSize(PageSize int) *ListCredentialAwsParams { + params.PageSize = &PageSize + return params } -func (params *ListCredentialAwsParams) SetLimit(Limit int) (*ListCredentialAwsParams){ - params.Limit = &Limit - return params +func (params *ListCredentialAwsParams) SetLimit(Limit int) *ListCredentialAwsParams { + params.Limit = &Limit + return params } // Retrieve a single page of CredentialAws records from the API. Request is executed immediately. func (c *ApiService) PageCredentialAws(params *ListCredentialAwsParams, pageToken, pageNumber string) (*ListCredentialAwsResponse, error) { - path := "/v1/Credentials/AWS" + path := "/v1/Credentials/AWS" - -data := url.Values{} -headers := make(map[string]interface{}) + data := url.Values{} + headers := make(map[string]interface{}) -if params != nil && params.PageSize != nil { - data.Set("PageSize", fmt.Sprint(*params.PageSize)) -} + if params != nil && params.PageSize != nil { + data.Set("PageSize", fmt.Sprint(*params.PageSize)) + } - if pageToken != "" { - data.Set("PageToken", pageToken) - } - if pageNumber != "" { - data.Set("Page", pageNumber) - } + if pageToken != "" { + data.Set("PageToken", pageToken) + } + if pageNumber != "" { + data.Set("Page", pageNumber) + } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } + resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - defer resp.Body.Close() + defer resp.Body.Close() - ps := &ListCredentialAwsResponse{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + ps := &ListCredentialAwsResponse{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } - return ps, err + return ps, err } // Lists CredentialAws records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. @@ -369,7 +361,6 @@ func (c *ApiService) StreamCredentialAws(params *ListCredentialAwsParams) (chan return recordChannel, errorChannel } - func (c *ApiService) streamCredentialAws(response *ListCredentialAwsResponse, params *ListCredentialAwsParams, recordChannel chan TestResponseObject, errorChannel chan error) { curRecord := 1 @@ -401,68 +392,65 @@ func (c *ApiService) streamCredentialAws(response *ListCredentialAwsResponse, pa } func (c *ApiService) getNextListCredentialAwsResponse(nextPageUrl string) (interface{}, error) { - if nextPageUrl == "" { - return nil, nil - } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) - if err != nil { - return nil, err - } + if nextPageUrl == "" { + return nil, nil + } + resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + if err != nil { + return nil, err + } - defer resp.Body.Close() + defer resp.Body.Close() - ps := &ListCredentialAwsResponse{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } - return ps, nil + ps := &ListCredentialAwsResponse{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } + return ps, nil } - // Optional parameters for the method 'UpdateCredentialAws' type UpdateCredentialAwsParams struct { - // - TestString *string `json:"TestString,omitempty"` - // - TestBoolean *bool `json:"TestBoolean,omitempty"` + // + TestString *string `json:"TestString,omitempty"` + // + TestBoolean *bool `json:"TestBoolean,omitempty"` } -func (params *UpdateCredentialAwsParams) SetTestString(TestString string) (*UpdateCredentialAwsParams){ - params.TestString = &TestString - return params +func (params *UpdateCredentialAwsParams) SetTestString(TestString string) *UpdateCredentialAwsParams { + params.TestString = &TestString + return params } -func (params *UpdateCredentialAwsParams) SetTestBoolean(TestBoolean bool) (*UpdateCredentialAwsParams){ - params.TestBoolean = &TestBoolean - return params +func (params *UpdateCredentialAwsParams) SetTestBoolean(TestBoolean bool) *UpdateCredentialAwsParams { + params.TestBoolean = &TestBoolean + return params } func (c *ApiService) UpdateCredentialAws(Sid string, params *UpdateCredentialAwsParams) (*TestResponseObject, error) { - path := "/v1/Credentials/AWS/{Sid}" - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) - -data := url.Values{} -headers := make(map[string]interface{}) - -if params != nil && params.TestString != nil { - data.Set("TestString", *params.TestString) -} -if params != nil && params.TestBoolean != nil { - data.Set("TestBoolean", fmt.Sprint(*params.TestBoolean)) -} + path := "/v1/Credentials/AWS/{Sid}" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) + data := url.Values{} + headers := make(map[string]interface{}) + if params != nil && params.TestString != nil { + data.Set("TestString", *params.TestString) + } + if params != nil && params.TestBoolean != nil { + data.Set("TestBoolean", fmt.Sprint(*params.TestBoolean)) + } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } + resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - defer resp.Body.Close() + defer resp.Body.Close() - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } - return ps, err + return ps, err } diff --git a/examples/go/go-client/helper/rest/flex/v1/credentials_aws_history.go b/examples/go/go-client/helper/rest/flex/v1/credentials_aws_history.go index 24150a592..edf4465ac 100644 --- a/examples/go/go-client/helper/rest/flex/v1/credentials_aws_history.go +++ b/examples/go/go-client/helper/rest/flex/v1/credentials_aws_history.go @@ -16,54 +16,49 @@ package openapi import ( "encoding/json" - "fmt" "net/url" - - "github.com/twilio/twilio-go/client" + "strings" ) - // Optional parameters for the method 'FetchCredentialHistory' type FetchCredentialHistoryParams struct { - // - AddOnsData *map[string]interface{} `json:"AddOnsData,omitempty"` + // + AddOnsData *map[string]interface{} `json:"AddOnsData,omitempty"` } -func (params *FetchCredentialHistoryParams) SetAddOnsData(AddOnsData map[string]interface{}) (*FetchCredentialHistoryParams){ - params.AddOnsData = &AddOnsData - return params +func (params *FetchCredentialHistoryParams) SetAddOnsData(AddOnsData map[string]interface{}) *FetchCredentialHistoryParams { + params.AddOnsData = &AddOnsData + return params } func (c *ApiService) FetchCredentialHistory(Sid string, params *FetchCredentialHistoryParams) (*TestResponseObject, error) { - path := "/v1/Credentials/AWS/{Sid}/History" - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) - -data := url.Values{} -headers := make(map[string]interface{}) + path := "/v1/Credentials/AWS/{Sid}/History" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) -if params != nil && params.AddOnsData != nil { - v, err := json.Marshal(params.AddOnsData) + data := url.Values{} + headers := make(map[string]interface{}) - if err != nil { - return nil, err - } - - data.Set("AddOnsData", string(v)) -} + if params != nil && params.AddOnsData != nil { + v, err := json.Marshal(params.AddOnsData) + if err != nil { + return nil, err + } + data.Set("AddOnsData", string(v)) + } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } + resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - defer resp.Body.Close() + defer resp.Body.Close() - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } - return ps, err + return ps, err } diff --git a/examples/go/go-client/helper/rest/flex/v1/model_list_credential_aws_response.go b/examples/go/go-client/helper/rest/flex/v1/model_list_credential_aws_response.go index e5fbfb70e..940a75deb 100644 --- a/examples/go/go-client/helper/rest/flex/v1/model_list_credential_aws_response.go +++ b/examples/go/go-client/helper/rest/flex/v1/model_list_credential_aws_response.go @@ -13,14 +13,9 @@ */ package openapi -import ( - "encoding/json" - "github.com/twilio/twilio-go/client" -) + // ListCredentialAwsResponse struct for ListCredentialAwsResponse type ListCredentialAwsResponse struct { - Credentials []TestResponseObject `json:"credentials,omitempty"` - Meta ListCredentialAwsResponseMeta `json:"meta,omitempty"` + Credentials []TestResponseObject `json:"credentials,omitempty"` + Meta ListCredentialAwsResponseMeta `json:"meta,omitempty"` } - - diff --git a/examples/go/go-client/helper/rest/flex/v1/model_list_credential_aws_response_meta.go b/examples/go/go-client/helper/rest/flex/v1/model_list_credential_aws_response_meta.go index 269dd867a..9c879a767 100644 --- a/examples/go/go-client/helper/rest/flex/v1/model_list_credential_aws_response_meta.go +++ b/examples/go/go-client/helper/rest/flex/v1/model_list_credential_aws_response_meta.go @@ -13,19 +13,14 @@ */ package openapi -import ( - "encoding/json" - "github.com/twilio/twilio-go/client" -) + // ListCredentialAwsResponseMeta struct for ListCredentialAwsResponseMeta type ListCredentialAwsResponseMeta struct { - FirstPageUrl string `json:"first_page_url,omitempty"` - Key string `json:"key,omitempty"` - NextPageUrl string `json:"next_page_url,omitempty"` - Page int `json:"page,omitempty"` - PageSize int `json:"page_size,omitempty"` + FirstPageUrl string `json:"first_page_url,omitempty"` + Key string `json:"key,omitempty"` + NextPageUrl string `json:"next_page_url,omitempty"` + Page int `json:"page,omitempty"` + PageSize int `json:"page_size,omitempty"` PreviousPageUrl string `json:"previous_page_url,omitempty"` - Url string `json:"url,omitempty"` + Url string `json:"url,omitempty"` } - - diff --git a/examples/go/go-client/helper/rest/flex/v1/model_test_response_object.go b/examples/go/go-client/helper/rest/flex/v1/model_test_response_object.go index 176141030..413f14ab1 100644 --- a/examples/go/go-client/helper/rest/flex/v1/model_test_response_object.go +++ b/examples/go/go-client/helper/rest/flex/v1/model_test_response_object.go @@ -13,16 +13,11 @@ */ package openapi -import ( - "encoding/json" - "github.com/twilio/twilio-go/client" -) + // TestResponseObject struct for TestResponseObject type TestResponseObject struct { - AccountSid *string `json:"account_sid,omitempty"` - Sid *string `json:"sid,omitempty"` - TestString *string `json:"test_string,omitempty"` - TestInteger *int `json:"test_integer,omitempty"` + AccountSid *string `json:"account_sid,omitempty"` + Sid *string `json:"sid,omitempty"` + TestString *string `json:"test_string,omitempty"` + TestInteger *int `json:"test_integer,omitempty"` } - - diff --git a/examples/go/go-client/helper/rest/flex/v1/model_update_call_200_response.go b/examples/go/go-client/helper/rest/flex/v1/model_update_call_200_response.go index de150d3cf..f0548e961 100644 --- a/examples/go/go-client/helper/rest/flex/v1/model_update_call_200_response.go +++ b/examples/go/go-client/helper/rest/flex/v1/model_update_call_200_response.go @@ -13,14 +13,9 @@ */ package openapi -import ( - "encoding/json" - "github.com/twilio/twilio-go/client" -) + // UpdateCall200Response struct for UpdateCall200Response type UpdateCall200Response struct { - // Non-string path parameter in the response. + // Non-string path parameter in the response. Sid *int `json:"sid,omitempty"` } - - diff --git a/examples/go/go-client/helper/rest/flex/v1/voice.go b/examples/go/go-client/helper/rest/flex/v1/voice.go index 4eaa30794..88f989e29 100644 --- a/examples/go/go-client/helper/rest/flex/v1/voice.go +++ b/examples/go/go-client/helper/rest/flex/v1/voice.go @@ -16,34 +16,28 @@ package openapi import ( "encoding/json" - "fmt" "net/url" - - "github.com/twilio/twilio-go/client" + "strings" ) +func (c *ApiService) UpdateCall(Sid string) (*UpdateCall200Response, error) { + path := "/v1/Voice/{Sid}" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) -func (c *ApiService) UpdateCall(Sid string, ) (*UpdateCall200Response, error) { - path := "/v1/Voice/{Sid}" - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) - -data := url.Values{} -headers := make(map[string]interface{}) - - - + data := url.Values{} + headers := make(map[string]interface{}) - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) - if err != nil { - return nil, err - } + resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - defer resp.Body.Close() + defer resp.Body.Close() - ps := &UpdateCall200Response{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + ps := &UpdateCall200Response{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } - return ps, err + return ps, err } diff --git a/examples/go/go-client/terraform/resources/api/v2010/api_default.go b/examples/go/go-client/terraform/resources/api/v2010/api_default.go index 776cdfce3..2072bce32 100644 --- a/examples/go/go-client/terraform/resources/api/v2010/api_default.go +++ b/examples/go/go-client/terraform/resources/api/v2010/api_default.go @@ -12,232 +12,232 @@ * Do not edit the class manually. */ - package openapi import ( - "context" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "go-client/terraform/client" - . "github.com/twilio/terraform-provider-twilio/core" - . "go-client/helper/rest/api/v2010" + "context" + "fmt" + . "go-client/helper/rest/api/v2010" + "go-client/terraform/client" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + . "github.com/twilio/terraform-provider-twilio/core" ) func ResourceAccounts() *schema.Resource { - return &schema.Resource{ - CreateContext: createAccounts, - ReadContext: readAccounts, - UpdateContext: updateAccounts, - DeleteContext: deleteAccounts, - Schema: map[string]*schema.Schema{ - "x_twilio_webhook_enabled": AsString(SchemaForceNewOptional), - "recording_status_callback": AsString(SchemaForceNewOptional), - "recording_status_callback_event": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), - "twiml": AsString(SchemaForceNewOptional), - "sid": AsString(SchemaComputed), - "status": AsString(SchemaComputedOptional), - "pause_behavior": AsString(SchemaComputedOptional), - }, - Importer: &schema.ResourceImporter{ - StateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { - err := parseAccountsImportId(d.Id(), d) - if err != nil { - return nil, err - } - - return []*schema.ResourceData{d}, nil - }, - }, - } + return &schema.Resource{ + CreateContext: createAccounts, + ReadContext: readAccounts, + UpdateContext: updateAccounts, + DeleteContext: deleteAccounts, + Schema: map[string]*schema.Schema{ + "x_twilio_webhook_enabled": AsString(SchemaForceNewOptional), + "recording_status_callback": AsString(SchemaForceNewOptional), + "recording_status_callback_event": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), + "twiml": AsString(SchemaForceNewOptional), + "sid": AsString(SchemaComputed), + "status": AsString(SchemaComputedOptional), + "pause_behavior": AsString(SchemaComputedOptional), + }, + Importer: &schema.ResourceImporter{ + StateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { + err := parseAccountsImportId(d.Id(), d) + if err != nil { + return nil, err + } + + return []*schema.ResourceData{d}, nil + }, + }, + } } func createAccounts(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - params := CreateAccountParams{} - if err := UnmarshalSchema(¶ms, d); err != nil { - return diag.FromErr(err) - } - - - r, err := m.(*client.Config).Client.Api.CreateAccount(¶ms) - if err != nil { - return diag.FromErr(err) - } - - idParts := []string{ } - idParts = append(idParts, (*r.Sid)) - d.SetId(strings.Join(idParts, "/")) - d.Set("sid", *r.Sid) - - return updateAccounts(ctx, d, m) + params := CreateAccountParams{} + if err := UnmarshalSchema(¶ms, d); err != nil { + return diag.FromErr(err) + } + + r, err := m.(*client.Config).Client.Api.CreateAccount(¶ms) + if err != nil { + return diag.FromErr(err) + } + + idParts := []string{} + idParts = append(idParts, (*r.Sid)) + d.SetId(strings.Join(idParts, "/")) + d.Set("sid", *r.Sid) + + return updateAccounts(ctx, d, m) } func deleteAccounts(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - sid := d.Get("sid").(string) + sid := d.Get("sid").(string) - err := m.(*client.Config).Client.Api.DeleteAccount(sid) - if err != nil { - return diag.FromErr(err) - } + err := m.(*client.Config).Client.Api.DeleteAccount(sid) + if err != nil { + return diag.FromErr(err) + } - d.SetId("") + d.SetId("") - return nil + return nil } func readAccounts(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - sid := d.Get("sid").(string) + sid := d.Get("sid").(string) - r, err := m.(*client.Config).Client.Api.FetchAccount(sid) - if err != nil { - return diag.FromErr(err) - } + r, err := m.(*client.Config).Client.Api.FetchAccount(sid) + if err != nil { + return diag.FromErr(err) + } - err = MarshalSchema(d, r) - if err != nil { - return diag.FromErr(err) - } + err = MarshalSchema(d, r) + if err != nil { + return diag.FromErr(err) + } - return nil + return nil } func parseAccountsImportId(importId string, d *schema.ResourceData) error { - importParts := strings.Split(importId, "/") - errStr := "invalid import ID (%q), expected sid" + importParts := strings.Split(importId, "/") + errStr := "invalid import ID (%q), expected sid" - if len(importParts) != 1 { - return fmt.Errorf(errStr, importId) - } + if len(importParts) != 1 { + return fmt.Errorf(errStr, importId) + } - d.Set("sid", importParts[0]) + d.Set("sid", importParts[0]) - return nil + return nil } func updateAccounts(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - params := UpdateAccountParams{} - if err := UnmarshalSchema(¶ms, d); err != nil { - return diag.FromErr(err) - } + params := UpdateAccountParams{} + if err := UnmarshalSchema(¶ms, d); err != nil { + return diag.FromErr(err) + } - sid := d.Get("sid").(string) + sid := d.Get("sid").(string) - r, err := m.(*client.Config).Client.Api.UpdateAccount(sid, ¶ms) - if err != nil { - return diag.FromErr(err) - } + r, err := m.(*client.Config).Client.Api.UpdateAccount(sid, ¶ms) + if err != nil { + return diag.FromErr(err) + } - err = MarshalSchema(d, r) - if err != nil { - return diag.FromErr(err) - } + err = MarshalSchema(d, r) + if err != nil { + return diag.FromErr(err) + } - return nil + return nil } func ResourceAccountsCalls() *schema.Resource { - return &schema.Resource{ - CreateContext: createAccountsCalls, - ReadContext: readAccountsCalls, - DeleteContext: deleteAccountsCalls, - Schema: map[string]*schema.Schema{ - "required_string_property": AsString(SchemaForceNewRequired), - "test_method": AsString(SchemaForceNewRequired), - "path_account_sid": AsString(SchemaForceNewOptional), - "test_array_of_strings": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), - "test_array_of_uri": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), - "test_integer": AsInt(SchemaComputed), - }, - Importer: &schema.ResourceImporter{ - StateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { - err := parseAccountsCallsImportId(d.Id(), d) - if err != nil { - return nil, err - } - - return []*schema.ResourceData{d}, nil - }, - }, - } + return &schema.Resource{ + CreateContext: createAccountsCalls, + ReadContext: readAccountsCalls, + DeleteContext: deleteAccountsCalls, + Schema: map[string]*schema.Schema{ + "required_string_property": AsString(SchemaForceNewRequired), + "test_method": AsString(SchemaForceNewRequired), + "path_account_sid": AsString(SchemaForceNewOptional), + "test_array_of_strings": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), + "test_array_of_uri": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), + "test_integer": AsInt(SchemaComputed), + }, + Importer: &schema.ResourceImporter{ + StateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { + err := parseAccountsCallsImportId(d.Id(), d) + if err != nil { + return nil, err + } + + return []*schema.ResourceData{d}, nil + }, + }, + } } func createAccountsCalls(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - params := CreateCallParams{} - if err := UnmarshalSchema(¶ms, d); err != nil { - return diag.FromErr(err) - } - - - r, err := m.(*client.Config).Client.Api.CreateCall(¶ms) - if err != nil { - return diag.FromErr(err) - } - - idParts := []string{ } - idParts = append(idParts, IntToString(*r.TestInteger)) - d.SetId(strings.Join(idParts, "/")) - - err = MarshalSchema(d, r) - if err != nil { - return diag.FromErr(err) - } - - return nil + params := CreateCallParams{} + if err := UnmarshalSchema(¶ms, d); err != nil { + return diag.FromErr(err) + } + + r, err := m.(*client.Config).Client.Api.CreateCall(¶ms) + if err != nil { + return diag.FromErr(err) + } + + idParts := []string{} + idParts = append(idParts, IntToString(*r.TestInteger)) + d.SetId(strings.Join(idParts, "/")) + + err = MarshalSchema(d, r) + if err != nil { + return diag.FromErr(err) + } + + return nil } func deleteAccountsCalls(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - params := DeleteCallParams{} - if err := UnmarshalSchema(¶ms, d); err != nil { - return diag.FromErr(err) - } + params := DeleteCallParams{} + if err := UnmarshalSchema(¶ms, d); err != nil { + return diag.FromErr(err) + } - testInteger := d.Get("test_integer").(int) + testInteger := d.Get("test_integer").(int) - err := m.(*client.Config).Client.Api.DeleteCall(testInteger, ¶ms) - if err != nil { - return diag.FromErr(err) - } + err := m.(*client.Config).Client.Api.DeleteCall(testInteger, ¶ms) + if err != nil { + return diag.FromErr(err) + } - d.SetId("") + d.SetId("") - return nil + return nil } func readAccountsCalls(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - params := FetchCallParams{} - if err := UnmarshalSchema(¶ms, d); err != nil { - return diag.FromErr(err) - } + params := FetchCallParams{} + if err := UnmarshalSchema(¶ms, d); err != nil { + return diag.FromErr(err) + } - testInteger := d.Get("test_integer").(int) + testInteger := d.Get("test_integer").(int) - r, err := m.(*client.Config).Client.Api.FetchCall(testInteger, ¶ms) - if err != nil { - return diag.FromErr(err) - } + r, err := m.(*client.Config).Client.Api.FetchCall(testInteger, ¶ms) + if err != nil { + return diag.FromErr(err) + } - err = MarshalSchema(d, r) - if err != nil { - return diag.FromErr(err) - } + err = MarshalSchema(d, r) + if err != nil { + return diag.FromErr(err) + } - return nil + return nil } func parseAccountsCallsImportId(importId string, d *schema.ResourceData) error { - importParts := strings.Split(importId, "/") - errStr := "invalid import ID (%q), expected test_integer" + importParts := strings.Split(importId, "/") + errStr := "invalid import ID (%q), expected test_integer" - if len(importParts) != 1 { - return fmt.Errorf(errStr, importId) - } + if len(importParts) != 1 { + return fmt.Errorf(errStr, importId) + } - testInteger, err := StringToInt(importParts[0]) - if err != nil { - return nil - } - d.Set("test_integer", testInteger) + testInteger, err := StringToInt(importParts[0]) + if err != nil { + return nil + } + d.Set("test_integer", testInteger) - return nil + return nil } diff --git a/examples/go/go-client/terraform/resources/flex/v1/api_default.go b/examples/go/go-client/terraform/resources/flex/v1/api_default.go index 1ff69811b..420852747 100644 --- a/examples/go/go-client/terraform/resources/flex/v1/api_default.go +++ b/examples/go/go-client/terraform/resources/flex/v1/api_default.go @@ -12,142 +12,142 @@ * Do not edit the class manually. */ - package openapi import ( - "context" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "go-client/terraform/client" - . "github.com/twilio/terraform-provider-twilio/core" - . "go-client/helper/rest/flex/v1" + "context" + "fmt" + . "go-client/helper/rest/flex/v1" + "go-client/terraform/client" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + . "github.com/twilio/terraform-provider-twilio/core" ) func ResourceCredentialsAWS() *schema.Resource { - return &schema.Resource{ - CreateContext: createCredentialsAWS, - ReadContext: readCredentialsAWS, - UpdateContext: updateCredentialsAWS, - DeleteContext: deleteCredentialsAWS, - Schema: map[string]*schema.Schema{ - "test_string": AsString(SchemaRequired), - "test_boolean": AsBool(SchemaComputedOptional), - "test_integer": AsInt(SchemaForceNewOptional), - "test_number": AsFloat(SchemaForceNewOptional), - "test_number_float": AsFloat(SchemaForceNewOptional), - "test_number_double": AsString(SchemaForceNewOptional), - "test_number_int32": AsFloat(SchemaForceNewOptional), - "test_number_int64": AsString(SchemaForceNewOptional), - "test_object": AsString(SchemaForceNewOptional), - "test_date_time": AsString(SchemaForceNewOptional), - "test_date": AsString(SchemaForceNewOptional), - "test_enum": AsString(SchemaForceNewOptional), - "test_object_array": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), - "test_any_type": AsString(SchemaForceNewOptional), - "test_any_array": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), - "permissions": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), - "some_a2p_thing": AsString(SchemaForceNewOptional), - "sid": AsString(SchemaComputed), - }, - Importer: &schema.ResourceImporter{ - StateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { - err := parseCredentialsAWSImportId(d.Id(), d) - if err != nil { - return nil, err - } - - return []*schema.ResourceData{d}, nil - }, - }, - } + return &schema.Resource{ + CreateContext: createCredentialsAWS, + ReadContext: readCredentialsAWS, + UpdateContext: updateCredentialsAWS, + DeleteContext: deleteCredentialsAWS, + Schema: map[string]*schema.Schema{ + "test_string": AsString(SchemaRequired), + "test_boolean": AsBool(SchemaComputedOptional), + "test_integer": AsInt(SchemaForceNewOptional), + "test_number": AsFloat(SchemaForceNewOptional), + "test_number_float": AsFloat(SchemaForceNewOptional), + "test_number_double": AsString(SchemaForceNewOptional), + "test_number_int32": AsFloat(SchemaForceNewOptional), + "test_number_int64": AsString(SchemaForceNewOptional), + "test_object": AsString(SchemaForceNewOptional), + "test_date_time": AsString(SchemaForceNewOptional), + "test_date": AsString(SchemaForceNewOptional), + "test_enum": AsString(SchemaForceNewOptional), + "test_object_array": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), + "test_any_type": AsString(SchemaForceNewOptional), + "test_any_array": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), + "permissions": AsList(AsString(SchemaForceNewOptional), SchemaForceNewOptional), + "some_a2p_thing": AsString(SchemaForceNewOptional), + "sid": AsString(SchemaComputed), + }, + Importer: &schema.ResourceImporter{ + StateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { + err := parseCredentialsAWSImportId(d.Id(), d) + if err != nil { + return nil, err + } + + return []*schema.ResourceData{d}, nil + }, + }, + } } func createCredentialsAWS(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - params := CreateCredentialAwsParams{} - if err := UnmarshalSchema(¶ms, d); err != nil { - return diag.FromErr(err) - } - - - r, err := m.(*client.Config).Client.FlexV1.CreateCredentialAws(¶ms) - if err != nil { - return diag.FromErr(err) - } - - idParts := []string{ } - idParts = append(idParts, (*r.Sid)) - d.SetId(strings.Join(idParts, "/")) - - err = MarshalSchema(d, r) - if err != nil { - return diag.FromErr(err) - } - - return nil + params := CreateCredentialAwsParams{} + if err := UnmarshalSchema(¶ms, d); err != nil { + return diag.FromErr(err) + } + + r, err := m.(*client.Config).Client.FlexV1.CreateCredentialAws(¶ms) + if err != nil { + return diag.FromErr(err) + } + + idParts := []string{} + idParts = append(idParts, (*r.Sid)) + d.SetId(strings.Join(idParts, "/")) + + err = MarshalSchema(d, r) + if err != nil { + return diag.FromErr(err) + } + + return nil } func deleteCredentialsAWS(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - sid := d.Get("sid").(string) + sid := d.Get("sid").(string) - err := m.(*client.Config).Client.FlexV1.DeleteCredentialAws(sid) - if err != nil { - return diag.FromErr(err) - } + err := m.(*client.Config).Client.FlexV1.DeleteCredentialAws(sid) + if err != nil { + return diag.FromErr(err) + } - d.SetId("") + d.SetId("") - return nil + return nil } func readCredentialsAWS(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - sid := d.Get("sid").(string) + sid := d.Get("sid").(string) - r, err := m.(*client.Config).Client.FlexV1.FetchCredentialAws(sid) - if err != nil { - return diag.FromErr(err) - } + r, err := m.(*client.Config).Client.FlexV1.FetchCredentialAws(sid) + if err != nil { + return diag.FromErr(err) + } - err = MarshalSchema(d, r) - if err != nil { - return diag.FromErr(err) - } + err = MarshalSchema(d, r) + if err != nil { + return diag.FromErr(err) + } - return nil + return nil } func parseCredentialsAWSImportId(importId string, d *schema.ResourceData) error { - importParts := strings.Split(importId, "/") - errStr := "invalid import ID (%q), expected sid" + importParts := strings.Split(importId, "/") + errStr := "invalid import ID (%q), expected sid" - if len(importParts) != 1 { - return fmt.Errorf(errStr, importId) - } + if len(importParts) != 1 { + return fmt.Errorf(errStr, importId) + } - d.Set("sid", importParts[0]) + d.Set("sid", importParts[0]) - return nil + return nil } func updateCredentialsAWS(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - params := UpdateCredentialAwsParams{} - if err := UnmarshalSchema(¶ms, d); err != nil { - return diag.FromErr(err) - } + params := UpdateCredentialAwsParams{} + if err := UnmarshalSchema(¶ms, d); err != nil { + return diag.FromErr(err) + } - sid := d.Get("sid").(string) + sid := d.Get("sid").(string) - r, err := m.(*client.Config).Client.FlexV1.UpdateCredentialAws(sid, ¶ms) - if err != nil { - return diag.FromErr(err) - } + r, err := m.(*client.Config).Client.FlexV1.UpdateCredentialAws(sid, ¶ms) + if err != nil { + return diag.FromErr(err) + } - err = MarshalSchema(d, r) - if err != nil { - return diag.FromErr(err) - } + err = MarshalSchema(d, r) + if err != nil { + return diag.FromErr(err) + } - return nil + return nil } - diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java index b0462ac6c..1c2fffd4c 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.UUID; import lombok.ToString; @@ -107,7 +108,7 @@ public Account create(final TwilioRestClient client){ } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } @@ -133,7 +134,6 @@ private void addPostParams(final Request request) { private void addHeaderParams(final Request request) { if (xTwilioWebhookEnabled != null) { request.addHeaderParam("X-Twilio-Webhook-Enabled", xTwilioWebhookEnabled.toString()); - } } } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountDeleter.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountDeleter.java index aaf61ee2d..34f31e320 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountDeleter.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountDeleter.java @@ -72,7 +72,7 @@ public boolean delete(final TwilioRestClient client) { } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java index 83c84d91b..cbc132f4d 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java @@ -73,7 +73,7 @@ public Account fetch(final TwilioRestClient client) { } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountReader.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountReader.java index e6b022a91..bb07c3a94 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountReader.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountReader.java @@ -102,7 +102,7 @@ private Page pageForRequest(final TwilioRestClient client, final Reques } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java index df837ab2a..d44109c53 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java @@ -88,7 +88,7 @@ public Account update(final TwilioRestClient client){ } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java index 1db83a29d..c789abbe4 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.UUID; import lombok.ToString; @@ -117,7 +118,7 @@ public Call create(final TwilioRestClient client){ } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java index 1f5b3edee..d2e0439c2 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java @@ -76,7 +76,7 @@ public boolean delete(final TwilioRestClient client) { } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java index 676bdd4ad..17148c079 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java @@ -77,7 +77,7 @@ public Call fetch(final TwilioRestClient client) { } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackCallSummaryUpdater.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackCallSummaryUpdater.java index aed7060cd..f716e898d 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackCallSummaryUpdater.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackCallSummaryUpdater.java @@ -100,7 +100,7 @@ public FeedbackCallSummary update(final TwilioRestClient client){ } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/CallUpdater.java b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/CallUpdater.java index 24711f887..7abd1ef7e 100644 --- a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/CallUpdater.java +++ b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/CallUpdater.java @@ -70,7 +70,7 @@ public Call update(final TwilioRestClient client){ } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsDeleter.java b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsDeleter.java index 53a1a5e67..d7ca8d111 100644 --- a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsDeleter.java +++ b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsDeleter.java @@ -69,7 +69,7 @@ public boolean delete(final TwilioRestClient client) { } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsFetcher.java b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsFetcher.java index 01af8dffe..249e7416e 100644 --- a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsFetcher.java +++ b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsFetcher.java @@ -70,7 +70,7 @@ public Aws fetch(final TwilioRestClient client) { } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsReader.java b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsReader.java index 79819197e..a17a7fedd 100644 --- a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsReader.java +++ b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsReader.java @@ -82,7 +82,7 @@ private Page pageForRequest(final TwilioRestClient client, final Request re } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsUpdater.java b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsUpdater.java index 277c9f1ef..24915f694 100644 --- a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsUpdater.java +++ b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsUpdater.java @@ -82,7 +82,7 @@ public Aws update(final TwilioRestClient client){ } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/NewCredentialsCreator.java b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/NewCredentialsCreator.java index 16c7a7bbc..ce96017a8 100644 --- a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/NewCredentialsCreator.java +++ b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/NewCredentialsCreator.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.UUID; import lombok.ToString; @@ -188,7 +189,7 @@ public NewCredentials create(final TwilioRestClient client){ } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/aws/HistoryFetcher.java b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/aws/HistoryFetcher.java index faa0e074e..c47040c06 100644 --- a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/aws/HistoryFetcher.java +++ b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/aws/HistoryFetcher.java @@ -76,7 +76,7 @@ public History fetch(final TwilioRestClient client) { } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/versionless/deployedDevices/FleetCreator.java b/examples/java/src/main/java/com/twilio/rest/versionless/deployedDevices/FleetCreator.java index c5a678a96..75f4badeb 100644 --- a/examples/java/src/main/java/com/twilio/rest/versionless/deployedDevices/FleetCreator.java +++ b/examples/java/src/main/java/com/twilio/rest/versionless/deployedDevices/FleetCreator.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.UUID; import lombok.ToString; @@ -80,7 +81,7 @@ public Fleet create(final TwilioRestClient client){ } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/versionless/deployedDevices/FleetFetcher.java b/examples/java/src/main/java/com/twilio/rest/versionless/deployedDevices/FleetFetcher.java index 820aba961..57d04612c 100644 --- a/examples/java/src/main/java/com/twilio/rest/versionless/deployedDevices/FleetFetcher.java +++ b/examples/java/src/main/java/com/twilio/rest/versionless/deployedDevices/FleetFetcher.java @@ -70,7 +70,7 @@ public Fleet fetch(final TwilioRestClient client) { } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/java/src/main/java/com/twilio/rest/versionless/understand/AssistantReader.java b/examples/java/src/main/java/com/twilio/rest/versionless/understand/AssistantReader.java index 13a9bf5a0..933b78cb1 100644 --- a/examples/java/src/main/java/com/twilio/rest/versionless/understand/AssistantReader.java +++ b/examples/java/src/main/java/com/twilio/rest/versionless/understand/AssistantReader.java @@ -82,7 +82,7 @@ private Page pageForRequest(final TwilioRestClient client, final Requ } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/examples/python/Dockerfile b/examples/python/Dockerfile index 8651a4bec..4bf78ea8d 100644 --- a/examples/python/Dockerfile +++ b/examples/python/Dockerfile @@ -1,4 +1,4 @@ -FROM python:latest +FROM python:3.11 ENV PYTHONBUFFERED 1 diff --git a/src/main/java/com/twilio/oai/TwilioGoGenerator.java b/src/main/java/com/twilio/oai/TwilioGoGenerator.java index cfbb2e806..1e7a60ad3 100644 --- a/src/main/java/com/twilio/oai/TwilioGoGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioGoGenerator.java @@ -121,6 +121,7 @@ public OperationsMap postProcessOperationsWithModels(final OperationsMap objs, L for (final CodegenOperation co : opList) { Utility.populateCrudOperations(co); + Utility.resolveContentType(co); if (co.nickname.startsWith("List")) { // make sure the format matches the other methods @@ -167,6 +168,9 @@ public void postProcessParameter(final CodegenParameter parameter) { // Parameters (and their items) need to be marshalled to a string for inclusion in the request payload when // they are either free-form objects (type: object) or any type objects (type is absent). + if(parameter.isBodyParam){ + parameter.vendorExtensions.put("x-is-body-param",true); + } if (parameter.isFreeFormObject || parameter.isAnyType) { parameter.vendorExtensions.put("x-marshal", true); } diff --git a/src/main/java/com/twilio/oai/TwilioNodeGenerator.java b/src/main/java/com/twilio/oai/TwilioNodeGenerator.java index 2db7f20e1..06db00467 100644 --- a/src/main/java/com/twilio/oai/TwilioNodeGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioNodeGenerator.java @@ -7,10 +7,8 @@ import com.twilio.oai.resolver.IConventionMapper; import com.twilio.oai.resolver.LanguageConventionResolver; import com.twilio.oai.resolver.LanguagePropertyResolver; -import com.twilio.oai.resolver.common.CodegenModelResolver; -import com.twilio.oai.resolver.java.JavaParameterResolver; -import com.twilio.oai.resolver.java.JavaPropertyResolver; import com.twilio.oai.resolver.node.NodeCaseResolver; +import com.twilio.oai.resolver.node.NodeCodegenModelResolver; import com.twilio.oai.resolver.node.NodeParameterResolver; import com.twilio.oai.resource.IResourceTree; import com.twilio.oai.resource.ResourceMap; @@ -102,7 +100,7 @@ public OperationsMap postProcessOperationsWithModels(final OperationsMap objs, L private ApiResources generateResources(final List opList) { final IConventionMapper conventionMapper = new LanguageConventionResolver(CONFIG_NODE_JSON_PATH); - final CodegenModelResolver codegenModelResolver = new CodegenModelResolver(conventionMapper, + final NodeCodegenModelResolver nodeCodegenModelResolver = new NodeCodegenModelResolver(conventionMapper, modelFormatMap, List.of(EnumConstants.NodeDataTypes.values())); @@ -111,8 +109,10 @@ private ApiResources generateResources(final List opList) { nodeApiResourceBuilder.updateApiPath() .updateTemplate() - .updateOperations(new NodeParameterResolver(conventionMapper, codegenModelResolver)) - .updateResponseModel(new LanguagePropertyResolver(conventionMapper), codegenModelResolver); + .updateOperations(new NodeParameterResolver(conventionMapper, nodeCodegenModelResolver)); + + nodeApiResourceBuilder.updateResponseModel(new LanguagePropertyResolver(conventionMapper), nodeCodegenModelResolver); + return nodeApiResourceBuilder.build(); } diff --git a/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java index cf51cc0ee..c0c0a6228 100644 --- a/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java @@ -3,6 +3,7 @@ import com.twilio.oai.DirectoryStructureService; import com.twilio.oai.PathUtils; import com.twilio.oai.StringHelper; +import com.twilio.oai.common.ApplicationConstants; import com.twilio.oai.common.Utility; import com.twilio.oai.resolver.Resolver; import com.twilio.oai.resource.Resource; @@ -20,7 +21,7 @@ public abstract class ApiResourceBuilder implements IApiResourceBuilder { public static final String META_LIST_PARAMETER_KEY = "x-list-parameters"; public static final String META_CONTEXT_PARAMETER_KEY = "x-context-parameters"; - public static final String NESTED_CONTENT_TYPE = "application/json"; + public static final String CONTENT_TYPE_JSON = "application/json"; protected final IApiActionTemplate template; @Getter @@ -338,7 +339,7 @@ protected void categorizeOperations() { protected boolean updateNestedContent(CodegenOperation co) { if(!hasNestedRequestBody) { if (co.bodyParam != null && co.bodyParam.getContent() != null) { - hasNestedRequestBody = co.bodyParam.getContent().containsKey(NESTED_CONTENT_TYPE); + hasNestedRequestBody = co.bodyParam.getContent().containsKey(CONTENT_TYPE_JSON); } } return hasNestedRequestBody; diff --git a/src/main/java/com/twilio/oai/api/FluentApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/FluentApiResourceBuilder.java index b83d1958f..492a0cb70 100644 --- a/src/main/java/com/twilio/oai/api/FluentApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/FluentApiResourceBuilder.java @@ -191,7 +191,7 @@ protected void resolveParam(final Resolver codegenParameterIRe }); } - private void updateDataType(final String baseType, + protected void updateDataType(final String baseType, final String dataType, final BiConsumer consumer) { consumer.accept(baseType, getDataTypeName(dataType)); diff --git a/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java index a639fb45c..e8176da4e 100644 --- a/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java @@ -118,6 +118,7 @@ public ApiResourceBuilder updateOperations(Resolver codegenPar .map(item -> codegenParameterIResolver.resolve(item, this)) .map(item -> conventionResolver.resolveEnumParameter(item, resourceName)) .collect(Collectors.toList()); + processDataTypesForParams(co.headerParams); co.optionalParams = co.optionalParams .stream() .map(item -> codegenParameterIResolver.resolve(item, this)) @@ -349,7 +350,7 @@ private void processDataTypesForParams(List finalQueryParamLis @Override protected Map mapOperation(CodegenOperation co) { Map operationMap = super.mapOperation(co); - if (hasNestedRequestBody) { + if (co.bodyParam !=null && co.bodyParam.getContent() != null && co.bodyParam.getContent().containsKey(CONTENT_TYPE_JSON)) { operationMap.put(SIGNATURE_LIST, generateSignatureListJson(co)); modelParameters = generateSignatureListBody(co); } else { diff --git a/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java index d5aacdca7..5ce709388 100644 --- a/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java @@ -2,17 +2,22 @@ import com.twilio.oai.DirectoryStructureService; import com.twilio.oai.common.ApplicationConstants; -import com.twilio.oai.common.EnumConstants; import com.twilio.oai.common.Utility; import com.twilio.oai.resolver.Resolver; +import com.twilio.oai.resolver.node.NodeCodegenModelResolver; import com.twilio.oai.template.IApiActionTemplate; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.CodegenParameter; +import org.openapitools.codegen.CodegenProperty; + +import static com.twilio.oai.common.ApplicationConstants.STRING; public class NodeApiResourceBuilder extends FluentApiResourceBuilder { public NodeApiResourceBuilder(final IApiActionTemplate template, @@ -63,6 +68,63 @@ public ApiResourceBuilder updateOperations(final Resolver code return this; } + public ApiResourceBuilder updateResponseModel(Resolver codegenPropertyResolver, NodeCodegenModelResolver codegenModelResolver) { + final String resourceName = getApiName(); + + final List allResponseModels = codegenOperationList + .stream() + .flatMap(co -> co.responses + .stream() + .map(response -> response.dataType) + .filter(Objects::nonNull) + .flatMap(modelName -> getModel(modelName, co).stream()) + .findFirst() + .stream()) + .collect(Collectors.toList()); + + allResponseModels.stream().findFirst().ifPresent(firstModel -> { + responseModel = firstModel; + + allResponseModels.forEach(model -> { + codegenModelResolver.resolveResponseModel(model, this); + + model.setName(resourceName); + model.getVars().forEach(variable -> { + codegenPropertyResolver.resolve(variable, this); + + instancePathParams + .stream() + .filter(param -> param.paramName.equals(variable.name)) + .filter(param -> param.dataType.equals(STRING)) + .filter(param -> !param.dataType.equals(variable.dataType)) + .forEach(param -> param.vendorExtensions.put("x-stringify", true)); + }); + + if (model != responseModel) { + // Merge any vars from the model that aren't part of the response model. + model.getVars().forEach(variable -> { + if (responseModel.getVars().stream().noneMatch(v -> v.getName().equals(variable.getName()))) { + responseModel.getVars().add(variable); + } + }); + } + }); + + responseModel.getVars().forEach(variable -> { + addModel(modelTree, variable.complexType, variable.dataType); + + super.updateDataType(variable.complexType, variable.dataType, (dataTypeWithEnum, dataType) -> { + variable.datatypeWithEnum = dataTypeWithEnum; + variable.baseType = dataType; + }); + }); + }); + + modelTree.values().forEach(model -> model.setName(getModelName(model.getClassname()))); + + return this; + } + @Override public ApiResourceBuilder updateModel(Resolver codegenModelResolver) { super.updateModel(codegenModelResolver); @@ -79,7 +141,7 @@ protected String getDataTypeName(final String dataType) { return removeEnumName(dataType); } - private String removeEnumName(final String dataType) { + public String removeEnumName(final String dataType) { if (dataType != null && dataType.contains(ApplicationConstants.ENUM)) { return getApiName() + Utility.removeEnumName(dataType); } diff --git a/src/main/java/com/twilio/oai/common/Utility.java b/src/main/java/com/twilio/oai/common/Utility.java index da0d35c58..acdb18c6b 100644 --- a/src/main/java/com/twilio/oai/common/Utility.java +++ b/src/main/java/com/twilio/oai/common/Utility.java @@ -5,6 +5,7 @@ import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -130,4 +131,13 @@ public Optional getModelByClassname(final List model public Optional getModelByName(final List models, final String modelname) { return models.stream().filter(model -> model.name.equals(modelname)).findFirst(); } + + public static void resolveContentType(CodegenOperation co) { + if(co.bodyParam != null) { + LinkedHashMap conType = co.bodyParam.getContent(); + if (conType != null && conType.containsKey("application/json")) { + co.vendorExtensions.put("x-is-json-type", true); + } + } + } } diff --git a/src/main/java/com/twilio/oai/resolver/common/CodegenModelContainerDataTypeResolver.java b/src/main/java/com/twilio/oai/resolver/common/CodegenModelContainerDataTypeResolver.java index 07b756a9d..7d72cfea5 100644 --- a/src/main/java/com/twilio/oai/resolver/common/CodegenModelContainerDataTypeResolver.java +++ b/src/main/java/com/twilio/oai/resolver/common/CodegenModelContainerDataTypeResolver.java @@ -6,7 +6,6 @@ import com.twilio.oai.resolver.Resolver; import lombok.RequiredArgsConstructor; -import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenProperty; import java.util.List; @@ -27,18 +26,6 @@ public CodegenProperty resolve(CodegenProperty codegenProperty, ApiResourceBuild return codegenProperty; } - public CodegenProperty resolve(CodegenProperty codegenProperty, ApiResourceBuilder apiResourceBuilder, CodegenModelResolver codegenModelResolver) { - Stack containerTypes = new Stack<>(); - codegenProperty.dataType = unwrapContainerType(codegenProperty,containerTypes); - CodegenModel nestedModel = codegenModelResolver.resolveNestedModel(codegenProperty, apiResourceBuilder); - if (nestedModel == null) { - codegenModelDataTypeResolver.resolve(codegenProperty, apiResourceBuilder); - } - rewrapContainerType(codegenProperty,containerTypes); - - return codegenProperty; - } - /** * Unwraps the container type(s) from the underlying property datatype and adds the container type(s) to the given * containerTypes stack. Returns the underlying property datatype (i.e. "List" -> "IceServer"). @@ -46,7 +33,7 @@ public CodegenProperty resolve(CodegenProperty codegenProperty, ApiResourceBuild * @param containerTypes * @return */ - private String unwrapContainerType(CodegenProperty codegenProperty,Stack containerTypes) { + protected String unwrapContainerType(CodegenProperty codegenProperty,Stack containerTypes) { String codegenPropertyDataType = ""; codegenPropertyDataType = codegenProperty.dataType; @@ -78,7 +65,7 @@ private String unwrapContainerType(CodegenProperty codegenProperty,Stack * @param codegenProperty * @param containerTypes */ - private static void rewrapContainerType(CodegenProperty codegenProperty,Stack containerTypes) { + protected static void rewrapContainerType(CodegenProperty codegenProperty,Stack containerTypes) { String currentContainerType = ""; while(!containerTypes.empty()) { currentContainerType = containerTypes.pop(); diff --git a/src/main/java/com/twilio/oai/resolver/common/CodegenModelResolver.java b/src/main/java/com/twilio/oai/resolver/common/CodegenModelResolver.java index ca5f88e7b..0036f200d 100644 --- a/src/main/java/com/twilio/oai/resolver/common/CodegenModelResolver.java +++ b/src/main/java/com/twilio/oai/resolver/common/CodegenModelResolver.java @@ -1,6 +1,5 @@ package com.twilio.oai.resolver.common; -import com.twilio.oai.CodegenUtils; import com.twilio.oai.api.ApiResourceBuilder; import com.twilio.oai.common.LanguageDataType; import com.twilio.oai.resolver.Resolver; @@ -8,8 +7,6 @@ import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenProperty; -import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -36,35 +33,13 @@ public CodegenModel resolve(CodegenModel model, ApiResourceBuilder apiResourceBu } for (CodegenProperty property : model.vars) { - CodegenModel nestedModel = resolveNestedModel(property, apiResourceBuilder); - if(nestedModel != null) { - return nestedModel; - } if (property.isContainer) { - codegenModelContainerDataTypeResolver.resolve(property, apiResourceBuilder, this); + codegenModelContainerDataTypeResolver.resolve(property, apiResourceBuilder); } else { codegenModelDataTypeResolver.resolve(property, apiResourceBuilder); } - property.getVendorExtensions().computeIfPresent("x-import", (key, value) -> { - if( model.vendorExtensions.containsKey(key)) { - ((HashMap) model.vendorExtensions.get(key)).putAll((Map) value); - } - else { - model.vendorExtensions.put(key, value); - } - return value; - }); } + return model; } - public CodegenModel resolveNestedModel(CodegenProperty property, ApiResourceBuilder apiResourceBuilder) { - CodegenModel derivedCodegenModel = apiResourceBuilder.getModel(property.dataType); - if(derivedCodegenModel != null && !CodegenUtils.isPropertySchemaEnum(property) && - !codegenModelDataTypeResolver.modelFormatMap.containsKey(property.dataType)) { - this.resolve(derivedCodegenModel, apiResourceBuilder); - CodegenUtils.mergeVendorExtensionProperty(property.vendorExtensions,(LinkedHashMap) derivedCodegenModel.getVendorExtensions().get("x-import"), "x-import"); - return derivedCodegenModel; - } - return null; - } } diff --git a/src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelContainerDataTypeResolver.java b/src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelContainerDataTypeResolver.java new file mode 100644 index 000000000..81c0cbd95 --- /dev/null +++ b/src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelContainerDataTypeResolver.java @@ -0,0 +1,35 @@ +package com.twilio.oai.resolver.node; + +import com.twilio.oai.api.ApiResourceBuilder; +import com.twilio.oai.common.LanguageDataType; + +import com.twilio.oai.resolver.common.CodegenModelContainerDataTypeResolver; +import org.openapitools.codegen.CodegenModel; +import org.openapitools.codegen.CodegenProperty; + +import java.util.List; +import java.util.Stack; + +public class NodeCodegenModelContainerDataTypeResolver extends CodegenModelContainerDataTypeResolver { + private final NodeCodegenModelDataTypeResolver codegenModelDataTypeResolver; + private final List languageDataTypes; + + public NodeCodegenModelContainerDataTypeResolver(NodeCodegenModelDataTypeResolver codegenModelDataTypeResolver, List languageDataTypes) { + super(codegenModelDataTypeResolver, languageDataTypes); + this.codegenModelDataTypeResolver = codegenModelDataTypeResolver; + this.languageDataTypes = languageDataTypes; + } + + public CodegenProperty resolve(CodegenProperty codegenProperty, ApiResourceBuilder apiResourceBuilder, NodeCodegenModelResolver codegenModelResolver) { + Stack containerTypes = new Stack<>(); + codegenProperty.dataType = unwrapContainerType(codegenProperty,containerTypes); + CodegenModel nestedModel = codegenModelResolver.resolveNestedModel(codegenProperty, apiResourceBuilder); + if (nestedModel == null) { + codegenModelDataTypeResolver.resolve(codegenProperty, apiResourceBuilder); + } + rewrapContainerType(codegenProperty,containerTypes); + + return codegenProperty; + } + +} diff --git a/src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelDataTypeResolver.java b/src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelDataTypeResolver.java new file mode 100644 index 000000000..88661cd6a --- /dev/null +++ b/src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelDataTypeResolver.java @@ -0,0 +1,77 @@ +package com.twilio.oai.resolver.node; + +import com.twilio.oai.CodegenUtils; +import com.twilio.oai.api.ApiResourceBuilder; +import com.twilio.oai.common.ApplicationConstants; +import com.twilio.oai.common.Utility; +import com.twilio.oai.resolver.IConventionMapper; +import com.twilio.oai.resolver.common.CodegenModelDataTypeResolver; + +import java.util.Map; +import java.util.function.BiConsumer; + +import com.twilio.oai.resolver.common.CodegenModelResolver; +import org.openapitools.codegen.CodegenModel; +import org.openapitools.codegen.CodegenProperty; + +// Overriding default behavior and handling the enum +public class NodeCodegenModelDataTypeResolver extends CodegenModelDataTypeResolver { + + protected Map modelFormatMap; + private CodegenModelResolver codegenModelResolver; + + public NodeCodegenModelDataTypeResolver(IConventionMapper mapper, Map modelFormatMap) { + super(mapper, modelFormatMap); + this.modelFormatMap = modelFormatMap; + } + + public void setCodegenModel(CodegenModelResolver codegenModelResolver) { + this.codegenModelResolver = codegenModelResolver; + } + + @Override + public CodegenProperty resolve(CodegenProperty property, ApiResourceBuilder apiResourceBuilder) { + property = super.resolve(property, apiResourceBuilder); + CodegenModel codegenModel = apiResourceBuilder.getModel(property.dataType); + if (codegenModel != null && !CodegenUtils.isPropertySchemaEnum(property) && !modelFormatMap.containsKey(property.dataType)) { + // this is recursion as codegenModelResolver will again call NodeCodegenModelDataTypeResolver + codegenModelResolver.resolve(codegenModel, apiResourceBuilder); + apiResourceBuilder.addNestedModel(codegenModel); + } else { + super.resolve(property, apiResourceBuilder); + resolveProperty(property, apiResourceBuilder); + } + return property; + } + + public void resolveResponseModel(CodegenProperty property, ApiResourceBuilder apiResourceBuilder) { + super.resolve(property, apiResourceBuilder); + } + + protected void resolveProperty(CodegenProperty property, ApiResourceBuilder apiResourceBuilder) { + updateDataType(property.baseType, property.dataType, apiResourceBuilder, (dataTypeWithEnum, dataType) -> { + property.datatypeWithEnum = dataTypeWithEnum; + property.dataType = dataType; + }); + } + + private void updateDataType(final String baseType, + final String dataType, + ApiResourceBuilder apiResourceBuilder, + final BiConsumer consumer) { + consumer.accept(baseType, removeEnumName(dataType, apiResourceBuilder)); + + if (baseType != null && dataType != null) { + final String datatypeWithEnum = removeEnumName(baseType, apiResourceBuilder); + consumer.accept(datatypeWithEnum, dataType.replaceFirst(baseType, datatypeWithEnum)); + } + } + + private String removeEnumName(final String dataType, ApiResourceBuilder apiResourceBuilder) { + if (dataType != null && dataType.contains(ApplicationConstants.ENUM)) { + return apiResourceBuilder.getApiName() + Utility.removeEnumName(dataType); + } + + return dataType; + } +} diff --git a/src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelResolver.java b/src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelResolver.java new file mode 100644 index 000000000..33dd37ec7 --- /dev/null +++ b/src/main/java/com/twilio/oai/resolver/node/NodeCodegenModelResolver.java @@ -0,0 +1,89 @@ +package com.twilio.oai.resolver.node; + +import com.twilio.oai.CodegenUtils; +import com.twilio.oai.api.ApiResourceBuilder; +import com.twilio.oai.common.LanguageDataType; +import com.twilio.oai.resolver.IConventionMapper; +import com.twilio.oai.resolver.common.CodegenModelResolver; +import org.openapitools.codegen.CodegenModel; +import org.openapitools.codegen.CodegenProperty; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class NodeCodegenModelResolver extends CodegenModelResolver { + private final NodeCodegenModelDataTypeResolver codegenModelDataTypeResolver; + private final NodeCodegenModelContainerDataTypeResolver codegenModelContainerDataTypeResolver; + private static final String X_IMPORT = "x-import"; + + public NodeCodegenModelResolver(IConventionMapper mapper, Map modelFormatMap, + List languageDataTypes) { + this(languageDataTypes, new NodeCodegenModelDataTypeResolver(mapper, modelFormatMap)); + } + + public NodeCodegenModelResolver(List languageDataTypes, + NodeCodegenModelDataTypeResolver codegenModelDataTypeResolver) { + super(languageDataTypes, codegenModelDataTypeResolver); + this.codegenModelDataTypeResolver = codegenModelDataTypeResolver; + this.codegenModelContainerDataTypeResolver = new NodeCodegenModelContainerDataTypeResolver(codegenModelDataTypeResolver, + languageDataTypes); + this.codegenModelDataTypeResolver.setCodegenModel(this); + } + + @Override + public CodegenModel resolve(CodegenModel model, ApiResourceBuilder apiResourceBuilder) { + if (model == null) { + return null; + } + + for (CodegenProperty property : model.vars) { + CodegenModel nestedModel = resolveNestedModel(property, apiResourceBuilder); + if(nestedModel != null) { + return nestedModel; + } + if (property.isContainer) { + codegenModelContainerDataTypeResolver.resolve(property, apiResourceBuilder, this); + } else { + codegenModelDataTypeResolver.resolve(property, apiResourceBuilder); + } + property.getVendorExtensions().computeIfPresent(X_IMPORT, (key, value) -> { + if(model.vendorExtensions.containsKey(key)) { + ((HashMap) model.vendorExtensions.get(key)).putAll((Map) value); + } + else { + model.vendorExtensions.put(key, value); + } + return value; + }); + } + return model; + } + + public void resolveResponseModel(CodegenModel model, ApiResourceBuilder apiResourceBuilder) { + if (model == null) { + return; + } + + for (CodegenProperty property : model.vars) { + if (property.isContainer) { + codegenModelContainerDataTypeResolver.resolve(property, apiResourceBuilder); + } else { + codegenModelDataTypeResolver.resolveResponseModel(property, apiResourceBuilder); + } + } + + } + + public CodegenModel resolveNestedModel(CodegenProperty property, ApiResourceBuilder apiResourceBuilder) { + CodegenModel derivedCodegenModel = apiResourceBuilder.getModel(property.dataType); + if(derivedCodegenModel != null && !CodegenUtils.isPropertySchemaEnum(property) && + !codegenModelDataTypeResolver.modelFormatMap.containsKey(property.dataType)) { + this.resolve(derivedCodegenModel, apiResourceBuilder); + CodegenUtils.mergeVendorExtensionProperty(property.vendorExtensions,(LinkedHashMap) derivedCodegenModel.getVendorExtensions().get(X_IMPORT), X_IMPORT); + return derivedCodegenModel; + } + return null; + } +} diff --git a/src/main/resources/twilio-go/partial_serialization.mustache b/src/main/resources/twilio-go/partial_serialization.mustache index 03df71997..f3055b8ba 100644 --- a/src/main/resources/twilio-go/partial_serialization.mustache +++ b/src/main/resources/twilio-go/partial_serialization.mustache @@ -11,48 +11,112 @@ if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"{{paramName}}"+"}", {{^isString}}fmt.Sprint({{/isString}}{{paramName}}{{^isString}}){{/isString}}, -1) {{/pathParams}} -data := url.Values{} -headers := make(map[string]interface{}) + data := url.Values{} +{{^vendorExtensions.x-is-json-type}} + headers := make(map[string]interface{}) + +{{/vendorExtensions.x-is-json-type}} +{{#vendorExtensions.x-is-json-type}} + headers := map[string]interface{}{ + "Content-Type": "application/json", + } {{#hasOptionalParams}} {{#optionalParams}} +{{#vendorExtensions.x-is-body-param}} + if params != nil && params.{{paramName}} != nil { + v, err := json.Marshal(*params.{{paramName}}) + if err != nil { + return nil, err + } + urlEncodedData := url.QueryEscape(string(v)) + data.Set("{{baseName}}", urlEncodedData) + } +{{/vendorExtensions.x-is-body-param}} +{{^vendorExtensions.x-is-body-param}} {{^vendorExtensions.x-is-account-sid}} {{^isHeaderParam}} {{^vendorExtensions.x-custom}} -if params != nil && params.{{paramName}} != nil { + if params != nil && params.{{paramName}} != nil { {{#isArray}} - for _, item := range *params.{{paramName}} { + for _, item := range *params.{{paramName}} { {{#items.vendorExtensions.x-marshal}} - v, err := json.Marshal(item) + v, err := json.Marshal(item) - if err != nil { + if err != nil { return nil, err - } + } - data.Add("{{{baseName}}}", string(v)) + data.Add("{{{baseName}}}", string(v)) {{/items.vendorExtensions.x-marshal}} {{^items.vendorExtensions.x-marshal}} - data.Add("{{{baseName}}}", item) + data.Add("{{{baseName}}}", item) {{/items.vendorExtensions.x-marshal}} - } + } {{/isArray}} {{^isArray}} {{#vendorExtensions.x-marshal}} - v, err := json.Marshal(params.{{paramName}}) + v, err := json.Marshal(params.{{paramName}}) - if err != nil { + if err != nil { return nil, err + } + + data.Set("{{{baseName}}}", string(v)) +{{/vendorExtensions.x-marshal}} +{{^vendorExtensions.x-marshal}} + data.Set("{{{baseName}}}", {{^isString}}fmt.Sprint({{/isString}}{{#isDateTime}}({{/isDateTime}}*params.{{paramName}}{{^isString}}{{#isDateTime}}).Format(time.RFC3339){{/isDateTime}}){{/isString}}) +{{/vendorExtensions.x-marshal}} +{{/isArray}} + } +{{/vendorExtensions.x-custom}} +{{/isHeaderParam}} +{{/vendorExtensions.x-is-account-sid}} +{{/vendorExtensions.x-is-body-param}} +{{/optionalParams}} +{{/hasOptionalParams}} +{{/vendorExtensions.x-is-json-type}} +{{^vendorExtensions.x-is-json-type}} +{{#hasOptionalParams}} +{{#optionalParams}} +{{^vendorExtensions.x-is-account-sid}} +{{^isHeaderParam}} +{{^vendorExtensions.x-custom}} + if params != nil && params.{{paramName}} != nil { +{{#isArray}} + for _, item := range *params.{{paramName}} { +{{#items.vendorExtensions.x-marshal}} + v, err := json.Marshal(item) + + if err != nil { + return nil, err + } + + data.Add("{{{baseName}}}", string(v)) +{{/items.vendorExtensions.x-marshal}} +{{^items.vendorExtensions.x-marshal}} + data.Add("{{{baseName}}}", item) +{{/items.vendorExtensions.x-marshal}} } +{{/isArray}} +{{^isArray}} +{{#vendorExtensions.x-marshal}} + v, err := json.Marshal(params.{{paramName}}) - data.Set("{{{baseName}}}", string(v)) + if err != nil { + return nil, err + } + + data.Set("{{{baseName}}}", string(v)) {{/vendorExtensions.x-marshal}} {{^vendorExtensions.x-marshal}} - data.Set("{{{baseName}}}", {{^isString}}fmt.Sprint({{/isString}}{{#isDateTime}}({{/isDateTime}}*params.{{paramName}}{{^isString}}{{#isDateTime}}).Format(time.RFC3339){{/isDateTime}}){{/isString}}) + data.Set("{{{baseName}}}", {{^isString}}fmt.Sprint({{/isString}}{{#isDateTime}}({{/isDateTime}}*params.{{paramName}}{{^isString}}{{#isDateTime}}).Format(time.RFC3339){{/isDateTime}}){{/isString}}) {{/vendorExtensions.x-marshal}} {{/isArray}} -} + } {{/vendorExtensions.x-custom}} {{/isHeaderParam}} {{/vendorExtensions.x-is-account-sid}} {{/optionalParams}} {{/hasOptionalParams}} +{{/vendorExtensions.x-is-json-type}} diff --git a/src/main/resources/twilio-java/creator.mustache b/src/main/resources/twilio-java/creator.mustache index 80b01dc21..3496435db 100644 --- a/src/main/resources/twilio-java/creator.mustache +++ b/src/main/resources/twilio-java/creator.mustache @@ -35,6 +35,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.UUID; {{/fullJavaUtil}} import lombok.ToString; @@ -104,7 +105,7 @@ public class {{apiName}}Creator extends Creator<{{apiName}}>{ } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/src/main/resources/twilio-java/deleter.mustache b/src/main/resources/twilio-java/deleter.mustache index 4292ad91f..8a1de7999 100644 --- a/src/main/resources/twilio-java/deleter.mustache +++ b/src/main/resources/twilio-java/deleter.mustache @@ -92,7 +92,7 @@ public class {{apiName}}Deleter extends Deleter<{{apiName}}> { } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/src/main/resources/twilio-java/fetcher.mustache b/src/main/resources/twilio-java/fetcher.mustache index 463711373..0a19e9386 100644 --- a/src/main/resources/twilio-java/fetcher.mustache +++ b/src/main/resources/twilio-java/fetcher.mustache @@ -93,7 +93,7 @@ public class {{apiName}}Fetcher extends Fetcher<{{apiName}}> { } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/src/main/resources/twilio-java/models.mustache b/src/main/resources/twilio-java/models.mustache index b1d489b31..701f91430 100644 --- a/src/main/resources/twilio-java/models.mustache +++ b/src/main/resources/twilio-java/models.mustache @@ -4,7 +4,7 @@ static public class {{classname}} { {{#vars}} @JsonInclude(JsonInclude.Include.NON_EMPTY) - @JsonProperty("{{#lambda.lowercase}}{{{nameInSnakeCase}}}{{/lambda.lowercase}}") + @JsonProperty("{{{baseName}}}") @Getter @Setter private {{{dataType}}} {{name}}; {{#vendorExtensions.x-serialize}} public String get{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}() { diff --git a/src/main/resources/twilio-java/reader.mustache b/src/main/resources/twilio-java/reader.mustache index 28a6e15db..ffafb0ec0 100644 --- a/src/main/resources/twilio-java/reader.mustache +++ b/src/main/resources/twilio-java/reader.mustache @@ -113,7 +113,7 @@ public class {{apiName}}Reader extends Reader<{{apiName}}> { } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/src/main/resources/twilio-java/updater.mustache b/src/main/resources/twilio-java/updater.mustache index f12f22b96..41a83244a 100644 --- a/src/main/resources/twilio-java/updater.mustache +++ b/src/main/resources/twilio-java/updater.mustache @@ -94,7 +94,7 @@ public class {{apiName}}Updater extends Updater<{{apiName}}>{ } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException("Server Error, no content", response.getStatusCode()); } throw new ApiException(restException); } diff --git a/src/main/resources/twilio-node/model.mustache b/src/main/resources/twilio-node/model.mustache index b4e7e2353..d3ba41889 100644 --- a/src/main/resources/twilio-node/model.mustache +++ b/src/main/resources/twilio-node/model.mustache @@ -19,6 +19,6 @@ export class {{name}} {{#parent}}extends {{{parent}}} {{/parent}}{ {{/isEnum}} {{#isEnum}} -export type {{classname}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}|{{/-last}}{{/enumVars}}{{/allowableValues}}; +export type {{name}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}|{{/-last}}{{/enumVars}}{{/allowableValues}}; {{/isEnum}} {{/models}} diff --git a/src/main/resources/twilio-node/operation.mustache b/src/main/resources/twilio-node/operation.mustache index fd65224e0..0398a05c0 100644 --- a/src/main/resources/twilio-node/operation.mustache +++ b/src/main/resources/twilio-node/operation.mustache @@ -26,6 +26,7 @@ {{#queryParams}}{{>requestParam}}{{/queryParams}} {{#formParams}}{{>requestParam}}{{/formParams}} + {{#bodyParam}}data = params{{/bodyParam}} {{#vendorExtensions.x-is-read-operation}} if (params.pageNumber !== undefined) data["Page"] = params.pageNumber; if (params.pageToken !== undefined) data["PageToken"] = params.pageToken; diff --git a/src/test/java/com/twilio/oai/TwilioGeneratorTest.java b/src/test/java/com/twilio/oai/TwilioGeneratorTest.java index 02bd4bfe3..dc9bcd094 100644 --- a/src/test/java/com/twilio/oai/TwilioGeneratorTest.java +++ b/src/test/java/com/twilio/oai/TwilioGeneratorTest.java @@ -28,7 +28,14 @@ public class TwilioGeneratorTest { @Parameterized.Parameters public static Collection generators() { - return Arrays.asList(Generator.TWILIO_JAVA); + return Arrays.asList(Generator.TWILIO_CSHARP, + Generator.TWILIO_GO, + Generator.TWILIO_JAVA, + Generator.TWILIO_NODE, + Generator.TWILIO_PHP, + Generator.TWILIO_PYTHON, + Generator.TWILIO_RUBY, + Generator.TWILIO_TERRAFORM); } private final Generator generator; @@ -40,8 +47,8 @@ public static void setUp() { @Test public void launchGenerator() { - // final String pathname = "/Users/kgoswami/Projects/github/twilio-oai/spec/yaml/twilio_messaging_bulk_v1.yaml"; - final String pathname = "examples/twilio_messaging_bulk_v1.yaml"; + final String pathname = "examples/spec/twilio_api_v2010.yaml"; +// final String pathname = "examples/twilio_messaging_bulk_v1.yaml"; File filesList[] ; File directoryPath = new File(pathname); if (directoryPath.isDirectory()) {