From 654c95357803b34e66e0e4938acc05fd751b2af4 Mon Sep 17 00:00:00 2001 From: sbansla Date: Thu, 24 Aug 2023 18:06:48 +0530 Subject: [PATCH 01/12] datatype resolved for nested models and created models for request body with builder pattern --- .../com/twilio/oai/TwilioCsharpGenerator.java | 3 +- .../twilio/oai/api/ApiResourceBuilder.java | 7 ++++ .../oai/api/CsharpApiResourceBuilder.java | 2 - .../java/com/twilio/oai/resolver/README.md | 38 +++++++++++++++++++ .../common/CodegenParameterResolver.java | 22 ++++++++--- .../CsharpCodegenModelDataTypeResolver.java | 26 ++++++++++--- .../resources/twilio-csharp/Resource.mustache | 1 + .../resources/twilio-csharp/models.mustache | 30 +++++++++++++++ 8 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/twilio/oai/resolver/README.md create mode 100644 src/main/resources/twilio-csharp/models.mustache diff --git a/src/main/java/com/twilio/oai/TwilioCsharpGenerator.java b/src/main/java/com/twilio/oai/TwilioCsharpGenerator.java index 551ce99ee..6cc3b7d14 100644 --- a/src/main/java/com/twilio/oai/TwilioCsharpGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioCsharpGenerator.java @@ -74,11 +74,12 @@ private CsharpApiResources processCodegenOperations(List opLis // Model Resolver CsharpCodegenModelDataTypeResolver csharpCodegenModelDataTypeResolver = new CsharpCodegenModelDataTypeResolver(conventionMapper, modelFormatMap); CodegenModelResolver codegenModelResolver = new CodegenModelResolver(languageDataType, csharpCodegenModelDataTypeResolver); + csharpCodegenModelDataTypeResolver.setCodegenModel(codegenModelResolver); // Parameter Resolver CsharpSerializer csharpSerializer = new CsharpSerializer(conventionMapper); CsharpCodegenParameterDataTypeResolver csharpCodegenParameterDataTypeResolver = new CsharpCodegenParameterDataTypeResolver(conventionMapper, csharpSerializer); - CodegenParameterResolver codegenParameterResolver = new CodegenParameterResolver(languageDataType, csharpCodegenParameterDataTypeResolver); + CodegenParameterResolver codegenParameterResolver = new CodegenParameterResolver(languageDataType, csharpCodegenParameterDataTypeResolver, codegenModelResolver); return new CsharpApiResourceBuilder(apiActionTemplate, opList, this.allModels) diff --git a/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java index 6a14d9589..cf51cc0ee 100644 --- a/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java @@ -187,6 +187,13 @@ public CodegenModel getModel(String modelName ) { } public void addNestedModel(final CodegenModel codegenModel) { + // TODO: Temporary fix, planning to use hashmap, set is inserting duplicate values. + Iterator iterator = nestedModels.iterator(); + while (iterator.hasNext()) { + if (iterator.next().name.equals(codegenModel.name)) { + return; + } + } nestedModels.add(codegenModel); } diff --git a/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java index 584410ae2..5c792b650 100644 --- a/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/CsharpApiResourceBuilder.java @@ -6,7 +6,6 @@ import com.twilio.oai.common.EnumConstants; import com.twilio.oai.common.Utility; import com.twilio.oai.resolver.Resolver; -import com.twilio.oai.resolver.csharp.CsharpSerializer; import com.twilio.oai.resolver.csharp.OperationStore; import com.twilio.oai.template.CsharpApiActionTemplate; import com.twilio.oai.template.IApiActionTemplate; @@ -15,7 +14,6 @@ import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.CodegenParameter; import org.openapitools.codegen.CodegenProperty; -import org.openapitools.codegen.CodegenResponse; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/com/twilio/oai/resolver/README.md b/src/main/java/com/twilio/oai/resolver/README.md new file mode 100644 index 000000000..7ba70d9d2 --- /dev/null +++ b/src/main/java/com/twilio/oai/resolver/README.md @@ -0,0 +1,38 @@ +This section explains the relationship between a parameter, property, model +1. Request type: urlencoded +application/x-www-form-urlencoded: + schema: + type: object + title: CreateMessageRequest + properties: + To: + StatusCallback: + ApplicationSid: + MaxPrice: + +2: Request type: json +application/json: + schema: + type: object + title: CreateMessageRequest + properties: + To: + StatusCallback: + ApplicationSid: + MaxPrice: + +1. Parameter +In case of Request type is urlencoded, then each item inside request body is considered as codegenparameter(To, +StatusCallback, ApplicationSid,MaxPrice). +In case of Request type is json, then there will be only one codegenparameter(CreateMessageRequest) +Each property will be present as codegenproperty(To, StatusCallback, ApplicationSid,MaxPrice). +A parameter can have multiple properties. +A parameter can be a model if it is referenced in component section. + +2. Property +A parameter can have multiple properties. A property can be a model if it is referenced in component section. + +3. Model +Any object defined inside component schema is a model. Now a model can have multiple properties. +Parameter can be a model +Property can be a model diff --git a/src/main/java/com/twilio/oai/resolver/common/CodegenParameterResolver.java b/src/main/java/com/twilio/oai/resolver/common/CodegenParameterResolver.java index 86de9d10b..81aea1ab5 100644 --- a/src/main/java/com/twilio/oai/resolver/common/CodegenParameterResolver.java +++ b/src/main/java/com/twilio/oai/resolver/common/CodegenParameterResolver.java @@ -4,6 +4,7 @@ import com.twilio.oai.common.LanguageDataType; import com.twilio.oai.resolver.Resolver; import com.twilio.oai.resolver.IConventionMapper; +import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenParameter; import java.util.List; @@ -12,28 +13,37 @@ public class CodegenParameterResolver extends Resolver { private final CodegenParameterDataTypeResolver codegenParameterDataTypeResolver; private final CodegenParameterContainerDataTypeResolver codegenParameterContainerDataTypeResolver; + private final CodegenModelResolver codegenModelResolver; public CodegenParameterResolver(IConventionMapper mapper, List languageDataTypes) { - this(languageDataTypes, new CodegenParameterDataTypeResolver(mapper)); + this(languageDataTypes, new CodegenParameterDataTypeResolver(mapper), null); } public CodegenParameterResolver(List languageDataTypes, - CodegenParameterDataTypeResolver codegenParameterDataTypeResolver) { + CodegenParameterDataTypeResolver codegenParameterDataTypeResolver, + CodegenModelResolver codegenModelResolver) { this.codegenParameterDataTypeResolver = codegenParameterDataTypeResolver; codegenParameterContainerDataTypeResolver = new CodegenParameterContainerDataTypeResolver(codegenParameterDataTypeResolver, languageDataTypes); + this.codegenModelResolver = codegenModelResolver; } public CodegenParameter resolve(CodegenParameter parameter, ApiResourceBuilder apiResourceBuilder) { if (parameter == null) { return null; } - - if (parameter.isContainer) { - codegenParameterContainerDataTypeResolver.resolve(parameter, apiResourceBuilder); + + CodegenModel codegenModel = apiResourceBuilder.getModel(parameter.dataType); + if (codegenModel != null && codegenModelResolver != null) { // Request Body is json + codegenModelResolver.resolve(codegenModel, apiResourceBuilder); + apiResourceBuilder.addNestedModel(codegenModel); } else { - codegenParameterDataTypeResolver.resolve(parameter, apiResourceBuilder); + if (parameter.isContainer) { + codegenParameterContainerDataTypeResolver.resolve(parameter, apiResourceBuilder); + } else { + codegenParameterDataTypeResolver.resolve(parameter, apiResourceBuilder); + } } return parameter; diff --git a/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java b/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java index d8825bea3..ab7aba68f 100644 --- a/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java +++ b/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java @@ -10,23 +10,37 @@ import java.util.Map; import java.util.Optional; +import com.twilio.oai.resolver.common.CodegenModelResolver; +import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenProperty; // Overriding default behavior and adding "x-jsonConverter" to enum public class CsharpCodegenModelDataTypeResolver extends CodegenModelDataTypeResolver { + + private CodegenModelResolver codegenModelResolver; public CsharpCodegenModelDataTypeResolver(IConventionMapper mapper, Map modelFormatMap) { super(mapper, modelFormatMap); } + public void setCodegenModel(CodegenModelResolver codegenModelResolver) { + this.codegenModelResolver = codegenModelResolver; + } + @Override public CodegenProperty resolve(CodegenProperty property, ApiResourceBuilder apiResourceBuilder) { - super.resolve(property, apiResourceBuilder); - resolveEnum(property); - mapper.deserialize() - .getString(property.dataFormat) - .ifPresent(dataType -> property.vendorExtensions.put("x-jsonConverter", dataType)); - + CodegenModel codegenModel = apiResourceBuilder.getModel(property.dataType); + if (codegenModel != null) { + // this is recursion as codegenModelResolver will again call CsharpCodegenModelDataTypeResolver + codegenModelResolver.resolve(codegenModel, apiResourceBuilder); + apiResourceBuilder.addNestedModel(codegenModel); + } else { + super.resolve(property, apiResourceBuilder); + resolveEnum(property); + mapper.deserialize() + .getString(property.dataFormat) + .ifPresent(dataType -> property.vendorExtensions.put("x-jsonConverter", dataType)); + } return property; } diff --git a/src/main/resources/twilio-csharp/Resource.mustache b/src/main/resources/twilio-csharp/Resource.mustache index a0beab4ae..cdb8078a8 100644 --- a/src/main/resources/twilio-csharp/Resource.mustache +++ b/src/main/resources/twilio-csharp/Resource.mustache @@ -8,6 +8,7 @@ namespace Twilio.Rest.{{domainPackage}}.{{apiVersionClass}}{{namespaceSubPart}} { public class {{apiName}}{{resourceConstant}} : {{resourceConstant}} { + {{>models}} {{>resource/Enum}} {{#apiOperations}} {{#vendorExtensions.x-is-create-operation}} diff --git a/src/main/resources/twilio-csharp/models.mustache b/src/main/resources/twilio-csharp/models.mustache new file mode 100644 index 000000000..f4ad17a32 --- /dev/null +++ b/src/main/resources/twilio-csharp/models.mustache @@ -0,0 +1,30 @@ + + {{#resources.nestedModels}} + + public static class {{classname}} + { + {{#vars}} + @JsonProperty("{{#lambda.lowercase}}{{{nameInSnakeCase}}}{{/lambda.lowercase}}") + private {{{dataType}}} {{name}} {get; set;} + {{/vars}} + public {{classname}}() { } + {{#vendorExtensions.constructors}} + private {{{dataType}}} {{name}} {get; set;} + private {{classname}}() {} + {{/vendorExtensions.constructors}} + public class Builder + { + private {{classname}} _{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}} = new {{classname}}; + public Builder() + { + } + {{#vars}} + public Builder With{{name}}({{{dataType}}} {{#lambda.camelcase}}{{name}}{{/lambda.camelcase}}) + { + _{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}.{{name}}= {{#lambda.camelcase}}{{name}}{{/lambda.camelcase}}; + return this; + } + {{/vars}} + } + } + {{/resources.nestedModels}} \ No newline at end of file From 53ff3c4dbf3ce528e38b113fc45bd00ab311a61a Mon Sep 17 00:00:00 2001 From: sbansla Date: Mon, 28 Aug 2023 09:46:03 +0530 Subject: [PATCH 02/12] enum resolver added --- .../java/com/twilio/oai/CodegenUtils.java | 25 ++++++++++++++++++- .../twilio/oai/JsonRequestBodyResolver.java | 4 +-- .../com/twilio/oai/TwilioJavaGenerator.java | 8 +++--- .../common/CodegenParameterResolver.java | 3 ++- .../CsharpCodegenModelDataTypeResolver.java | 3 ++- .../resolver/java/JavaConventionResolver.java | 2 +- 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/twilio/oai/CodegenUtils.java b/src/main/java/com/twilio/oai/CodegenUtils.java index 638926763..fdb5b4e65 100644 --- a/src/main/java/com/twilio/oai/CodegenUtils.java +++ b/src/main/java/com/twilio/oai/CodegenUtils.java @@ -7,7 +7,7 @@ public class CodegenUtils { public static boolean isPropertySchemaEnum(CodegenProperty codegenProperty) { if(codegenProperty.isEnum) { - return false; + return true; } boolean enumValues = codegenProperty.allowableValues != null && codegenProperty.allowableValues.containsKey(TwilioJavaGenerator.VALUES); @@ -17,6 +17,29 @@ public static boolean isPropertySchemaEnum(CodegenProperty codegenProperty) { } public static boolean isParameterSchemaEnum(CodegenParameter codegenParameter) { + if(codegenParameter.isEnum) { + return true; + } + boolean enumValues = codegenParameter.allowableValues != null && + codegenParameter.allowableValues.containsKey(TwilioJavaGenerator.VALUES); + boolean listEnumValues = codegenParameter.items != null && (codegenParameter.items.allowableValues != null + && codegenParameter.items.allowableValues.containsKey(TwilioJavaGenerator.VALUES)); + return enumValues || listEnumValues; + } + + // TODO: Refactor java code. + public static boolean isPropertySchemaEnumJava(CodegenProperty codegenProperty) { + if(codegenProperty.isEnum) { + return false; + } + boolean enumValues = codegenProperty.allowableValues != null && + codegenProperty.allowableValues.containsKey(TwilioJavaGenerator.VALUES); + boolean listEnumValues = codegenProperty.items != null && (codegenProperty.items.allowableValues != null + && codegenProperty.items.allowableValues.containsKey(TwilioJavaGenerator.VALUES)); + return enumValues || listEnumValues; + } + + public static boolean isParameterSchemaEnumJava(CodegenParameter codegenParameter) { if(codegenParameter.isEnum) { return false; } diff --git a/src/main/java/com/twilio/oai/JsonRequestBodyResolver.java b/src/main/java/com/twilio/oai/JsonRequestBodyResolver.java index cc9c2c199..fbbf91d5a 100644 --- a/src/main/java/com/twilio/oai/JsonRequestBodyResolver.java +++ b/src/main/java/com/twilio/oai/JsonRequestBodyResolver.java @@ -41,7 +41,7 @@ public void resolve(final CodegenParameter codegenParameter, final Resolver) property.items.allowableValues.get(VALUES); - } else if (CodegenUtils.isPropertySchemaEnum(property)) { + } else if (CodegenUtils.isPropertySchemaEnumJava(property)) { property.vendorExtensions.put(REF_ENUM_EXTENSION_NAME, true); property.dataType = Utility.removeEnumName(property.dataType); property.complexType = property.dataType; diff --git a/src/main/java/com/twilio/oai/resolver/common/CodegenParameterResolver.java b/src/main/java/com/twilio/oai/resolver/common/CodegenParameterResolver.java index 81aea1ab5..3930017e5 100644 --- a/src/main/java/com/twilio/oai/resolver/common/CodegenParameterResolver.java +++ b/src/main/java/com/twilio/oai/resolver/common/CodegenParameterResolver.java @@ -1,5 +1,6 @@ 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; @@ -35,7 +36,7 @@ public CodegenParameter resolve(CodegenParameter parameter, ApiResourceBuilder a } CodegenModel codegenModel = apiResourceBuilder.getModel(parameter.dataType); - if (codegenModel != null && codegenModelResolver != null) { // Request Body is json + if (codegenModel != null && codegenModelResolver != null && !CodegenUtils.isParameterSchemaEnum(parameter)) { // Request Body is json codegenModelResolver.resolve(codegenModel, apiResourceBuilder); apiResourceBuilder.addNestedModel(codegenModel); } else { diff --git a/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java b/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java index ab7aba68f..f402d95cc 100644 --- a/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java +++ b/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java @@ -1,5 +1,6 @@ package com.twilio.oai.resolver.csharp; +import com.twilio.oai.CodegenUtils; import com.twilio.oai.StringHelper; import com.twilio.oai.api.ApiResourceBuilder; import com.twilio.oai.common.ApplicationConstants; @@ -30,7 +31,7 @@ public void setCodegenModel(CodegenModelResolver codegenModelResolver) { @Override public CodegenProperty resolve(CodegenProperty property, ApiResourceBuilder apiResourceBuilder) { CodegenModel codegenModel = apiResourceBuilder.getModel(property.dataType); - if (codegenModel != null) { + if (codegenModel != null && !CodegenUtils.isPropertySchemaEnum(property)) { // this is recursion as codegenModelResolver will again call CsharpCodegenModelDataTypeResolver codegenModelResolver.resolve(codegenModel, apiResourceBuilder); apiResourceBuilder.addNestedModel(codegenModel); diff --git a/src/main/java/com/twilio/oai/resolver/java/JavaConventionResolver.java b/src/main/java/com/twilio/oai/resolver/java/JavaConventionResolver.java index c2b1482a4..f2c75c720 100644 --- a/src/main/java/com/twilio/oai/resolver/java/JavaConventionResolver.java +++ b/src/main/java/com/twilio/oai/resolver/java/JavaConventionResolver.java @@ -60,7 +60,7 @@ public CodegenParameter resolveEnumParameter(CodegenParameter parameter, String } public CodegenProperty resolveEnumProperty(CodegenProperty property, String resourceName) { - if(CodegenUtils.isPropertySchemaEnum(property)) { + if(CodegenUtils.isPropertySchemaEnumJava(property)) { // complexType contains the class name, dataType contains the data type for enum which prefixes class name. // name contains variable name // This is new gen enums From 3f32d28bd8350048818db3b583e37c494490e4f5 Mon Sep 17 00:00:00 2001 From: sbansla Date: Mon, 28 Aug 2023 13:02:22 +0530 Subject: [PATCH 03/12] ignoring predefined model classes --- .../oai/resolver/common/CodegenModelDataTypeResolver.java | 2 +- .../oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java | 2 +- src/main/resources/twilio-csharp/models.mustache | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/twilio/oai/resolver/common/CodegenModelDataTypeResolver.java b/src/main/java/com/twilio/oai/resolver/common/CodegenModelDataTypeResolver.java index 81d18be4e..afa8337fe 100644 --- a/src/main/java/com/twilio/oai/resolver/common/CodegenModelDataTypeResolver.java +++ b/src/main/java/com/twilio/oai/resolver/common/CodegenModelDataTypeResolver.java @@ -15,7 +15,7 @@ public class CodegenModelDataTypeResolver extends Resolver { protected final IConventionMapper mapper; private final CodegenModelComplexResolver codegenModelComplexResolver; - private final Map modelFormatMap; + protected final Map modelFormatMap; public CodegenModelDataTypeResolver(final IConventionMapper mapper, final Map modelFormatMap) { this.mapper = mapper; diff --git a/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java b/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java index f402d95cc..31561a2ff 100644 --- a/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java +++ b/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java @@ -31,7 +31,7 @@ public void setCodegenModel(CodegenModelResolver codegenModelResolver) { @Override public CodegenProperty resolve(CodegenProperty property, ApiResourceBuilder apiResourceBuilder) { CodegenModel codegenModel = apiResourceBuilder.getModel(property.dataType); - if (codegenModel != null && !CodegenUtils.isPropertySchemaEnum(property)) { + if (codegenModel != null && !CodegenUtils.isPropertySchemaEnum(property) && !modelFormatMap.containsKey(property.dataType)) { // this is recursion as codegenModelResolver will again call CsharpCodegenModelDataTypeResolver codegenModelResolver.resolve(codegenModel, apiResourceBuilder); apiResourceBuilder.addNestedModel(codegenModel); diff --git a/src/main/resources/twilio-csharp/models.mustache b/src/main/resources/twilio-csharp/models.mustache index f4ad17a32..34470df49 100644 --- a/src/main/resources/twilio-csharp/models.mustache +++ b/src/main/resources/twilio-csharp/models.mustache @@ -1,6 +1,5 @@ {{#resources.nestedModels}} - public static class {{classname}} { {{#vars}} From 807b219a50456f8276c207389107efb32f4bc270 Mon Sep 17 00:00:00 2001 From: sbansla Date: Mon, 28 Aug 2023 13:21:13 +0530 Subject: [PATCH 04/12] updating csharp generated code --- .../Rest/Api/V2010/Account/Call/FeedbackCallSummaryResource.cs | 2 ++ .../csharp/src/Twilio/Rest/Api/V2010/Account/CallResource.cs | 2 ++ examples/csharp/src/Twilio/Rest/Api/V2010/AccountResource.cs | 2 ++ examples/csharp/src/Twilio/Rest/FlexApi/V1/CallResource.cs | 2 ++ .../Twilio/Rest/FlexApi/V1/Credential/Aws/HistoryResource.cs | 2 ++ .../csharp/src/Twilio/Rest/FlexApi/V1/Credential/AwsResource.cs | 2 ++ .../Twilio/Rest/FlexApi/V1/Credential/NewCredentialsResource.cs | 2 ++ .../Twilio/Rest/Versionless/DeployedDevices/FleetResource.cs | 2 ++ .../src/Twilio/Rest/Versionless/Understand/AssistantResource.cs | 2 ++ 9 files changed, 18 insertions(+) diff --git a/examples/csharp/src/Twilio/Rest/Api/V2010/Account/Call/FeedbackCallSummaryResource.cs b/examples/csharp/src/Twilio/Rest/Api/V2010/Account/Call/FeedbackCallSummaryResource.cs index 9d2bc3fbd..9558e3ca5 100644 --- a/examples/csharp/src/Twilio/Rest/Api/V2010/Account/Call/FeedbackCallSummaryResource.cs +++ b/examples/csharp/src/Twilio/Rest/Api/V2010/Account/Call/FeedbackCallSummaryResource.cs @@ -29,6 +29,8 @@ namespace Twilio.Rest.Api.V2010.Account.Call public class FeedbackCallSummaryResource : Resource { + + [JsonConverter(typeof(StringEnumConverter))] public sealed class StatusEnum : StringEnum { diff --git a/examples/csharp/src/Twilio/Rest/Api/V2010/Account/CallResource.cs b/examples/csharp/src/Twilio/Rest/Api/V2010/Account/CallResource.cs index fbe5efefe..c87c7a561 100644 --- a/examples/csharp/src/Twilio/Rest/Api/V2010/Account/CallResource.cs +++ b/examples/csharp/src/Twilio/Rest/Api/V2010/Account/CallResource.cs @@ -29,6 +29,8 @@ namespace Twilio.Rest.Api.V2010.Account public class CallResource : Resource { + + [JsonConverter(typeof(StringEnumConverter))] public sealed class StatusEnum : StringEnum { diff --git a/examples/csharp/src/Twilio/Rest/Api/V2010/AccountResource.cs b/examples/csharp/src/Twilio/Rest/Api/V2010/AccountResource.cs index 73ad5d851..e3d8793e4 100644 --- a/examples/csharp/src/Twilio/Rest/Api/V2010/AccountResource.cs +++ b/examples/csharp/src/Twilio/Rest/Api/V2010/AccountResource.cs @@ -29,6 +29,8 @@ namespace Twilio.Rest.Api.V2010 public class AccountResource : Resource { + + [JsonConverter(typeof(StringEnumConverter))] public sealed class StatusEnum : StringEnum { diff --git a/examples/csharp/src/Twilio/Rest/FlexApi/V1/CallResource.cs b/examples/csharp/src/Twilio/Rest/FlexApi/V1/CallResource.cs index 200a13089..a079d1da7 100644 --- a/examples/csharp/src/Twilio/Rest/FlexApi/V1/CallResource.cs +++ b/examples/csharp/src/Twilio/Rest/FlexApi/V1/CallResource.cs @@ -30,6 +30,8 @@ public class CallResource : Resource { + + private static Request BuildUpdateRequest(UpdateCallOptions options, ITwilioRestClient client) { diff --git a/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/Aws/HistoryResource.cs b/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/Aws/HistoryResource.cs index 8b35ac4ca..4664e97b1 100644 --- a/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/Aws/HistoryResource.cs +++ b/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/Aws/HistoryResource.cs @@ -30,6 +30,8 @@ public class HistoryResource : Resource { + + private static Request BuildFetchRequest(FetchHistoryOptions options, ITwilioRestClient client) { diff --git a/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/AwsResource.cs b/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/AwsResource.cs index b689f25d2..36cf66453 100644 --- a/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/AwsResource.cs +++ b/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/AwsResource.cs @@ -30,6 +30,8 @@ public class AwsResource : Resource { + + /// delete /// Delete Aws parameters diff --git a/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/NewCredentialsResource.cs b/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/NewCredentialsResource.cs index 21a25d51d..440c6f89e 100644 --- a/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/NewCredentialsResource.cs +++ b/examples/csharp/src/Twilio/Rest/FlexApi/V1/Credential/NewCredentialsResource.cs @@ -29,6 +29,8 @@ namespace Twilio.Rest.FlexApi.V1.Credential public class NewCredentialsResource : Resource { + + public sealed class StatusEnum : StringEnum { private StatusEnum(string value) : base(value) {} diff --git a/examples/csharp/src/Twilio/Rest/Versionless/DeployedDevices/FleetResource.cs b/examples/csharp/src/Twilio/Rest/Versionless/DeployedDevices/FleetResource.cs index ab67f11e3..75b22d135 100644 --- a/examples/csharp/src/Twilio/Rest/Versionless/DeployedDevices/FleetResource.cs +++ b/examples/csharp/src/Twilio/Rest/Versionless/DeployedDevices/FleetResource.cs @@ -30,6 +30,8 @@ public class FleetResource : Resource { + + private static Request BuildCreateRequest(CreateFleetOptions options, ITwilioRestClient client) { diff --git a/examples/csharp/src/Twilio/Rest/Versionless/Understand/AssistantResource.cs b/examples/csharp/src/Twilio/Rest/Versionless/Understand/AssistantResource.cs index fd5dd760f..03080e6df 100644 --- a/examples/csharp/src/Twilio/Rest/Versionless/Understand/AssistantResource.cs +++ b/examples/csharp/src/Twilio/Rest/Versionless/Understand/AssistantResource.cs @@ -30,6 +30,8 @@ public class AssistantResource : Resource { + + private static Request BuildReadRequest(ReadAssistantOptions options, ITwilioRestClient client) { From 56dccc31c01a8d90887d42c6393c3e2bd6004d14 Mon Sep 17 00:00:00 2001 From: sbansla Date: Thu, 31 Aug 2023 12:00:54 +0530 Subject: [PATCH 05/12] added custome serialization support --- examples/spec/twilio_messaging_bulk_v1.yaml | 231 ++++++++++++++++++ .../resources/twilio-csharp/models.mustache | 3 + 2 files changed, 234 insertions(+) create mode 100644 examples/spec/twilio_messaging_bulk_v1.yaml diff --git a/examples/spec/twilio_messaging_bulk_v1.yaml b/examples/spec/twilio_messaging_bulk_v1.yaml new file mode 100644 index 000000000..b1d505f41 --- /dev/null +++ b/examples/spec/twilio_messaging_bulk_v1.yaml @@ -0,0 +1,231 @@ +openapi: 3.0.3 +info: + title: Bulk Messaging API + description: This is the public Twilio REST API for 1:Many Message creation. + termsOfService: https://www.twilio.com/legal/tos + version: 1.0.0-alpha.1 + contact: + name: Twilio Support + url: https://support.twilio.com + email: support@twilio.com + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +servers: +- url: https://preview.messaging.twilio.com +paths: + /v1/Messages: + post: + description: Send messages to multiple recipients + operationId: CreateMessages + requestBody: + required: true + content: + application/json: + schema: + type: object + title: CreateMessagesRequest + properties: + Messages: + type: array + items: + $ref: '#/components/schemas/messaging.v1.Message' + From: + type: string + format: phone-number + description: A Twilio phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) + format, an [alphanumeric sender ID](https://www.twilio.com/docs/sms/send-messages#use-an-alphanumeric-sender-id), + or a [Channel Endpoint address](https://www.twilio.com/docs/sms/channels#channel-addresses) + that is enabled for the type of message you want to send. Phone + numbers or [short codes](https://www.twilio.com/docs/sms/api/short-code) + purchased from Twilio also work here. You cannot, for example, + spoof messages from a private cell phone number. If you are using + `messaging_service_sid`, this parameter must be empty. + MessagingServiceSid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^MG[0-9a-fA-F]{32}$ + description: The SID of the [Messaging Service](https://www.twilio.com/docs/sms/services#send-a-message-with-copilot) + you want to associate with the Message. Set this parameter to + use the [Messaging Service Settings and Copilot Features](https://www.twilio.com/console/sms/services) + you have configured and leave the `from` parameter empty. When + only this parameter is set, Twilio will use your enabled Copilot + Features to select the `from` phone number for delivery. + phone_number_prices: + type: array + items: + type: object + format: phone-number-price + properties: + base_price: + type: number + current_price: + type: number + number_type: + type: string + nullable: true + description: The list of [PhoneNumberPrice](https://www.twilio.com/docs/phone-numbers/pricing#phone-number-price) + records. + StatusCallbackMethod2: + type: string + format: http-method + enum: + - HEAD + - GET + - POST + - PATCH + - PUT + - DELETE + description: 'The HTTP method we should use when requesting the + `status_callback` URL. Can be: `GET` or `POST` and the default + is `POST`. If an `application_sid` parameter is present, this + parameter is ignored.' + ScheduleType2: + type: string + $ref: '#/components/schemas/message_enum_schedule_type' + description: 'For Messaging Services only: Include this parameter + with a value of `fixed` in conjuction with the `send_time` parameter + in order to [schedule a Message](https://www.twilio.com/docs/messaging/features/message-scheduling).' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/messaging.v1.CreateMessagesResult' + '400': + description: Bad request + content: + application/json: + schema: + $ref: '#/components/schemas/messaging.v1.Error' + security: + - accountSid_authToken: [] +components: + schemas: + messaging.v1.Message: + type: object + properties: + To: + type: string + format: phone-number + description: The destination phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) + format for SMS/MMS or [Channel user address](https://www.twilio.com/docs/sms/channels#channel-addresses) + for other 3rd-party channels. + Body: + type: string + description: The text of the message you want to send. Can be up to 1,600 + characters in length. Overrides the request-level body and content template + if provided. + ContentVariables: + type: object + additionalProperties: + type: string + description: Key-value pairs of variable names to substitution values. Refer + to the [Twilio Content API Resources](https://www.twilio.com/docs/content-api/content-api-resources#send-a-message-with-preconfigured-content) + for more details. + + test_object: + nullable: true + format: phone-number-capabilities + properties: + fax: + type: boolean + mms: + type: boolean + sms: + type: boolean + voice: + type: boolean + type: object + StatusCallbackMethod: + type: string + format: http-method + enum: + - HEAD + - GET + - POST + - PATCH + - PUT + - DELETE + description: 'The HTTP method we should use when requesting the + `status_callback` URL. Can be: `GET` or `POST` and the default + is `POST`. If an `application_sid` parameter is present, this + parameter is ignored.' + ScheduleType: + type: string + $ref: '#/components/schemas/message_enum_schedule_type' + description: 'For Messaging Services only: Include this parameter + with a value of `fixed` in conjuction with the `send_time` parameter + in order to [schedule a Message](https://www.twilio.com/docs/messaging/features/message-scheduling).' + messaging.v1.MessageReceipt: + type: object + properties: + to: + type: string + nullable: true + description: The recipient phone number + sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^(SM|MM)[0-9a-fA-F]{32}$ + nullable: true + description: The unique string that identifies the resource + messaging.v1.FailedMessageReceipt: + type: object + properties: + to: + type: string + description: The recipient phone number + error_message: + type: string + description: The description of the error_code + error_code: + type: integer + description: The error code associated with the message creation attempt + messaging.v1.CreateMessagesResult: + properties: + total_message_count: + type: integer + description: The number of Messages processed in the request, equal to the + sum of success_count and error_count. + success_count: + type: integer + description: The number of Messages successfully created. + error_count: + type: integer + description: The number of Messages unsuccessfully processed in the request. + message_receipts: + type: array + items: + $ref: '#/components/schemas/messaging.v1.MessageReceipt' + failed_message_receipts: + type: array + items: + $ref: '#/components/schemas/messaging.v1.FailedMessageReceipt' + messaging.v1.Error: + type: object + properties: + message: + type: string + description: The error message details + code: + type: integer + description: The Twilio error code + status: + type: integer + description: The HTTP status code + more_info: + type: string + description: More information on the error + message_enum_schedule_type: + type: string + enum: + - fixed + - variable + securitySchemes: + accountSid_authToken: + type: http + scheme: basic diff --git a/src/main/resources/twilio-csharp/models.mustache b/src/main/resources/twilio-csharp/models.mustache index 34470df49..33d5c82f2 100644 --- a/src/main/resources/twilio-csharp/models.mustache +++ b/src/main/resources/twilio-csharp/models.mustache @@ -3,6 +3,9 @@ public static class {{classname}} { {{#vars}} + {{#vendorExtensions.x-jsonConverter}} + [JsonConverter(typeof({{vendorExtensions.x-jsonConverter}}))] + {{/vendorExtensions.x-jsonConverter}} @JsonProperty("{{#lambda.lowercase}}{{{nameInSnakeCase}}}{{/lambda.lowercase}}") private {{{dataType}}} {{name}} {get; set;} {{/vars}} From b5c6de1f6048197d5a6c8d6c922aa69c4bb1bf3b Mon Sep 17 00:00:00 2001 From: sbansla Date: Thu, 31 Aug 2023 12:04:24 +0530 Subject: [PATCH 06/12] changed directory of json spec file --- examples/{spec => }/twilio_messaging_bulk_v1.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{spec => }/twilio_messaging_bulk_v1.yaml (100%) diff --git a/examples/spec/twilio_messaging_bulk_v1.yaml b/examples/twilio_messaging_bulk_v1.yaml similarity index 100% rename from examples/spec/twilio_messaging_bulk_v1.yaml rename to examples/twilio_messaging_bulk_v1.yaml From d275c6ed56549295b09059062b6548f6d508b8d9 Mon Sep 17 00:00:00 2001 From: kridai Date: Mon, 11 Sep 2023 06:48:35 +0530 Subject: [PATCH 07/12] chore: node json support' --- .../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 +- examples/twilio_messaging_v1.yml | 10 +- examples/twilio_proxy_v1.yml | 2700 +++++++++++++++++ .../com/twilio/oai/TwilioJavaGenerator.java | 2 +- .../com/twilio/oai/TwilioNodeGenerator.java | 14 +- .../oai/api/JavaApiResourceBuilder.java | 2 +- .../oai/api/NodeApiResourceBuilder.java | 22 + .../resolver/node/NodePropertyResolver.java | 81 + src/main/resources/config/toggles.json | 3 +- .../com/twilio/oai/TwilioGeneratorTest.java | 12 +- 27 files changed, 3948 insertions(+), 1070 deletions(-) create mode 100644 examples/twilio_proxy_v1.yml create mode 100644 src/main/java/com/twilio/oai/resolver/node/NodePropertyResolver.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 1e60583c7..c1c30d2dd 100644 --- a/examples/go/go-client/helper/rest/api/v2010/accounts.go +++ b/examples/go/go-client/helper/rest/api/v2010/accounts.go @@ -18,201 +18,208 @@ 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" + 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.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.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) +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{}) - data := url.Values{} - headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) - if err != nil { - return err - } - defer resp.Body.Close() - return nil + resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + if err != nil { + return err + } + + defer resp.Body.Close() + + return nil } -func (c *ApiService) FetchAccount(Sid string) (*TestResponseObject, error) { - path := "/2010-04-01/Accounts/{Sid}.json" - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) +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{}) +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 + 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 } // 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. @@ -253,6 +260,7 @@ 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 @@ -284,65 +292,68 @@ 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) + path := "/2010-04-01/Accounts/{Sid}.json" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) - data := url.Values{} - headers := make(map[string]interface{}) +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) - } +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 - } - defer resp.Body.Close() - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); 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() + + 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 f6e2259e0..cc4c87699 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,154 +18,164 @@ import ( "encoding/json" "fmt" "net/url" - "strings" + + "github.com/twilio/twilio-go/client" ) + // 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"` + // + PathAccountSid *string `json:"PathAccountSid,omitempty"` +} + +func (params *DeleteCallParams) SetPathAccountSid(PathAccountSid string) (*DeleteCallParams){ + params.PathAccountSid = &PathAccountSid + return params } -func (params *DeleteCallParams) SetPathAccountSid(PathAccountSid string) *DeleteCallParams { - params.PathAccountSid = &PathAccountSid - return params +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{}) -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 - } - defer resp.Body.Close() + resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + if err != nil { + return err + } - return nil + defer resp.Body.Close() + + 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 2af1473db..f95684b1b 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,71 +18,75 @@ import ( "encoding/json" "fmt" "net/url" - "strings" + + "github.com/twilio/twilio-go/client" ) + // 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) + 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)) +} - 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 ec27f348d..a9f72042f 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 40053642d..f98d70007 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,16 +13,21 @@ */ 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 ab294fc6c..849ad2583 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,55 +13,52 @@ */ 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 { @@ -69,21 +66,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) @@ -100,3 +97,4 @@ 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 dd4cf95b1..caa54fc4e 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,23 +13,20 @@ */ 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 { @@ -48,3 +45,4 @@ 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 d14eb45d9..acfe3e54b 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,11 +13,16 @@ */ 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 82f8c08f2..3e378b57d 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 686eb5450..b02ea6851 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,309 +18,317 @@ 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" + path := "/v1/Credentials/AWS" + +data := url.Values{} +headers := make(map[string]interface{}) - 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) - 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.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) - 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.Add("TestObjectArray", string(v)) + } +} +if params != nil && params.TestAnyType != nil { + v, err := json.Marshal(params.TestAnyType) - 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.Set("TestAnyType", string(v)) +} +if params != nil && params.TestAnyArray != nil { + for _, item := range *params.TestAnyArray { + v, err := json.Marshal(item) - 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 + } - 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.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 - } - defer resp.Body.Close() + resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { - return nil, err - } + defer resp.Body.Close() - return ps, err + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } + + return ps, err } -func (c *ApiService) DeleteCredentialAws(Sid string) error { - path := "/v1/Credentials/AWS/{Sid}" - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) +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{}) +data := url.Values{} +headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) - if err != nil { - return err - } - defer resp.Body.Close() - return nil + + resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + if err != nil { + return err + } + + defer resp.Body.Close() + + return nil } -func (c *ApiService) FetchCredentialAws(Sid string) (*TestResponseObject, error) { - path := "/v1/Credentials/AWS/{Sid}" - path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) +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{}) +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 + 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 } // 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. @@ -361,6 +369,7 @@ 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 @@ -392,65 +401,68 @@ 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) + path := "/v1/Credentials/AWS/{Sid}" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) - data := url.Values{} - headers := make(map[string]interface{}) +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.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 - } - defer resp.Body.Close() - ps := &TestResponseObject{} - if err := json.NewDecoder(resp.Body).Decode(ps); 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() + + 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 edf4465ac..24150a592 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,49 +16,54 @@ package openapi import ( "encoding/json" + "fmt" "net/url" - "strings" + + "github.com/twilio/twilio-go/client" ) + // 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) + path := "/v1/Credentials/AWS/{Sid}/History" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) + +data := url.Values{} +headers := make(map[string]interface{}) - data := url.Values{} - headers := make(map[string]interface{}) +if params != nil && params.AddOnsData != nil { + v, err := json.Marshal(params.AddOnsData) - if params != nil && params.AddOnsData != nil { - v, err := json.Marshal(params.AddOnsData) + if err != nil { + return nil, err + } + + data.Set("AddOnsData", string(v)) +} - 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 940a75deb..e5fbfb70e 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,9 +13,14 @@ */ 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 9c879a767..269dd867a 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,14 +13,19 @@ */ 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 413f14ab1..176141030 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,11 +13,16 @@ */ 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 f0548e961..de150d3cf 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,9 +13,14 @@ */ 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 88f989e29..4eaa30794 100644 --- a/examples/go/go-client/helper/rest/flex/v1/voice.go +++ b/examples/go/go-client/helper/rest/flex/v1/voice.go @@ -16,28 +16,34 @@ package openapi import ( "encoding/json" + "fmt" "net/url" - "strings" + + "github.com/twilio/twilio-go/client" ) -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{}) +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{}) + + + - 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 2072bce32..776cdfce3 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" - "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" + "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" ) 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 420852747..1ff69811b 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" - "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" + "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" ) 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/twilio_messaging_v1.yml b/examples/twilio_messaging_v1.yml index 266932d60..15ec71f2e 100644 --- a/examples/twilio_messaging_v1.yml +++ b/examples/twilio_messaging_v1.yml @@ -46,7 +46,7 @@ paths: examples: example: $ref: '#/components/examples/NumberPoolResponse.example' - '5XX': + '500': description: Unexpected error. externalDocs: description: Learn more about user operations provided by this API. @@ -81,7 +81,7 @@ paths: $ref: '#/components/schemas/NumberPoolResponse' '404': description: A Number Pool with the specified ID was not found. - '5XX': + '500': description: Unexpected error. externalDocs: description: Learn more about user operations provided by this API. @@ -113,7 +113,7 @@ paths: $ref: '#/components/schemas/NumberPoolResponse' '404': description: A Number Pool with the specified ID was not found. - '5XX': + '500': description: Unexpected error. externalDocs: description: Learn more about user operations provided by this API. @@ -149,7 +149,7 @@ paths: $ref: '#/components/schemas/NumberPoolResponse' '404': description: A Number Pool with the specified ID was not found. - '5XX': + '500': description: Unexpected error. externalDocs: description: Learn more about user operations provided by this API. @@ -178,7 +178,7 @@ paths: $ref: '#/components/schemas/NumberPoolResponse' '404': description: A Number Pool with the specified ID was not found. - '5XX': + '500': description: Unexpected error. externalDocs: description: Learn more about user operations provided by this API. diff --git a/examples/twilio_proxy_v1.yml b/examples/twilio_proxy_v1.yml new file mode 100644 index 000000000..7d25cd445 --- /dev/null +++ b/examples/twilio_proxy_v1.yml @@ -0,0 +1,2700 @@ +components: + schemas: + proxy.v1.service.session.interaction: + type: object + properties: + sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KI[0-9a-fA-F]{32}$ + nullable: true + description: The unique string that we created to identify the Interaction + resource. + session_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + resource. + service_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + resource. + account_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^AC[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) + that created the Interaction resource. + data: + type: string + nullable: true + description: 'A JSON string that includes the message body of message interactions + (e.g. `{"body": "hello"}`) or the call duration (when available) of a + call (e.g. `{"duration": "5"}`).' + type: + type: string + $ref: '#/components/schemas/interaction_enum_type' + nullable: true + description: 'The Type of the Interaction. Can be: `message`, `voice` or + `unknown`.' + inbound_participant_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KP[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the inbound [Participant](https://www.twilio.com/docs/proxy/api/participant) + resource. + inbound_resource_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^[a-zA-Z]{2}[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the inbound resource; either the [Call](https://www.twilio.com/docs/voice/api/call-resource) + or [Message](https://www.twilio.com/docs/sms/api/message. + inbound_resource_status: + type: string + $ref: '#/components/schemas/interaction_enum_resource_status' + nullable: true + description: The inbound resource status of the Interaction. Will always + be `delivered` for messages and `in-progress` for calls. + inbound_resource_type: + type: string + nullable: true + description: The inbound resource type. Can be [Call](https://www.twilio.com/docs/voice/api/call-resource) + or [Message](https://www.twilio.com/docs/sms/api/message-resource). + inbound_resource_url: + type: string + format: uri + nullable: true + description: The URL of the Twilio inbound resource + outbound_participant_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KP[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the outbound [Participant](https://www.twilio.com/docs/proxy/api/participant)). + outbound_resource_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^[a-zA-Z]{2}[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the outbound resource; either the [Call](https://www.twilio.com/docs/voice/api/call-resource) + or [Message](https://www.twilio.com/docs/sms/api/message-resource). + outbound_resource_status: + type: string + $ref: '#/components/schemas/interaction_enum_resource_status' + nullable: true + description: 'The outbound resource status of the Interaction. Can be: `accepted`, + `canceled`, `deleted`, `delivered`, `delivery-unknown`, `failed`, `partially-delivered`, + `queued`, `read`, `received`, `receiving`, `scheduled`, `sending`, `sent`, + `undelivered`, or `unknown` for messages. Can be `initiated` or `completed` + or `unknown` for calls.' + outbound_resource_type: + type: string + nullable: true + description: 'The outbound resource type. Can be: [Call](https://www.twilio.com/docs/voice/api/call-resource) + or [Message](https://www.twilio.com/docs/sms/api/message-resource).' + outbound_resource_url: + type: string + format: uri + nullable: true + description: The URL of the Twilio outbound resource. + date_created: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the Interaction was created. + date_updated: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was last updated. + url: + type: string + format: uri + nullable: true + description: The absolute URL of the Interaction resource. + interaction_enum_type: + type: string + enum: + - message + - voice + - unknown + interaction_enum_resource_status: + type: string + enum: + - accepted + - answered + - busy + - canceled + - completed + - deleted + - delivered + - delivery-unknown + - failed + - in-progress + - initiated + - no-answer + - queued + - received + - receiving + - ringing + - scheduled + - sending + - sent + - undelivered + - unknown + proxy.v1.service.session.participant.message_interaction: + type: object + properties: + sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KI[0-9a-fA-F]{32}$ + nullable: true + description: The unique string that we created to identify the MessageInteraction + resource. + session_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + resource. + service_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + resource. + account_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^AC[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) + that created the MessageInteraction resource. + data: + type: string + nullable: true + description: 'A JSON string that includes the message body sent to the participant. + (e.g. `{"body": "hello"}`)' + type: + type: string + $ref: '#/components/schemas/message_interaction_enum_type' + nullable: true + description: The Type of Message Interaction. This value is always `message`. + participant_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KP[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the [Participant](https://www.twilio.com/docs/proxy/api/participant) + resource. + inbound_participant_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KP[0-9a-fA-F]{32}$ + nullable: true + description: Always empty for created Message Interactions. + inbound_resource_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^[a-zA-Z]{2}[0-9a-fA-F]{32}$ + nullable: true + description: Always empty for created Message Interactions. + inbound_resource_status: + type: string + $ref: '#/components/schemas/message_interaction_enum_resource_status' + nullable: true + description: Always empty for created Message Interactions. + inbound_resource_type: + type: string + nullable: true + description: Always empty for created Message Interactions. + inbound_resource_url: + type: string + format: uri + nullable: true + description: Always empty for created Message Interactions. + outbound_participant_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KP[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the outbound [Participant](https://www.twilio.com/docs/proxy/api/participant) + resource. + outbound_resource_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^[a-zA-Z]{2}[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the outbound [Message](https://www.twilio.com/docs/sms/api/message-resource) + resource. + outbound_resource_status: + type: string + $ref: '#/components/schemas/message_interaction_enum_resource_status' + nullable: true + description: 'The outbound message resource status. Can be: `accepted`, + `deleted`, `delivered`, `delivery-unknown`, `failed`, `queued`, `received`, + `receiving`, `scheduled`, `sending`, `sent`, `undelivered`, or `unknown`.' + outbound_resource_type: + type: string + nullable: true + description: The outbound resource type. This value is always `Message`. + outbound_resource_url: + type: string + format: uri + nullable: true + description: The URL of the Twilio message resource. + date_created: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was created. + date_updated: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was last updated. + url: + type: string + format: uri + nullable: true + description: The absolute URL of the MessageInteraction resource. + message_interaction_enum_type: + type: string + enum: + - message + - voice + - unknown + message_interaction_enum_resource_status: + type: string + enum: + - accepted + - answered + - busy + - canceled + - completed + - deleted + - delivered + - delivery-unknown + - failed + - in-progress + - initiated + - no-answer + - queued + - received + - receiving + - ringing + - scheduled + - sending + - sent + - undelivered + - unknown + proxy.v1.service.session.participant: + type: object + properties: + sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KP[0-9a-fA-F]{32}$ + nullable: true + description: The unique string that we created to identify the Participant + resource. + session_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + resource. + service_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the resource's parent [Service](https://www.twilio.com/docs/proxy/api/service) + resource. + account_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^AC[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) + that created the Participant resource. + friendly_name: + type: string + nullable: true + description: The string that you assigned to describe the participant. This + value must be 255 characters or fewer. Supports UTF-8 characters. **This + value should not have PII.** + identifier: + type: string + nullable: true + description: The phone number or channel identifier of the Participant. + This value must be 191 characters or fewer. Supports UTF-8 characters. + proxy_identifier: + type: string + nullable: true + description: The phone number or short code (masked number) of the participant's + partner. The participant will call or message the partner participant + at this number. + proxy_identifier_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^PN[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the Proxy Identifier assigned to the Participant. + date_deleted: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + when the Participant was removed from the session. + date_created: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was created. + date_updated: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was last updated. + url: + type: string + format: uri + nullable: true + description: The absolute URL of the Participant resource. + links: + type: object + format: uri-map + nullable: true + description: The URLs to resources related the participant. + proxy.v1.service.phone_number: + type: object + properties: + sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^PN[0-9a-fA-F]{32}$ + nullable: true + description: The unique string that we created to identify the PhoneNumber + resource. + account_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^AC[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) + that created the PhoneNumber resource. + service_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the PhoneNumber resource's parent [Service](https://www.twilio.com/docs/proxy/api/service) + resource. + date_created: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was created. + date_updated: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was last updated. + phone_number: + type: string + format: phone-number + nullable: true + description: The phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) + format, which consists of a + followed by the country code and subscriber + number. + friendly_name: + type: string + nullable: true + description: The string that you assigned to describe the resource. + iso_country: + type: string + nullable: true + description: The ISO Country Code for the phone number. + capabilities: + type: object + format: phone-number-capabilities + properties: + mms: + type: boolean + sms: + type: boolean + voice: + type: boolean + fax: + type: boolean + nullable: true + description: The capabilities of the phone number. + url: + type: string + format: uri + nullable: true + description: The absolute URL of the PhoneNumber resource. + is_reserved: + type: boolean + nullable: true + description: Whether the phone number should be reserved and not be assigned + to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) + for more information. + in_use: + type: integer + nullable: true + description: The number of open session assigned to the number. See the + [How many Phone Numbers do I need?](https://www.twilio.com/docs/proxy/phone-numbers-needed) + guide for more information. + proxy.v1.service: + type: object + properties: + sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + nullable: true + description: The unique string that we created to identify the Service resource. + unique_name: + type: string + nullable: true + description: An application-defined string that uniquely identifies the + resource. This value must be 191 characters or fewer in length and be + unique. Supports UTF-8 characters. **This value should not have PII.** + account_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^AC[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) + that created the Service resource. + chat_instance_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^IS[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the Chat Service Instance managed by Proxy Service. + The Chat Service enables Proxy to forward SMS and channel messages to + this chat instance. This is a one-to-one relationship. + callback_url: + type: string + format: uri + nullable: true + description: The URL we call when the interaction status changes. + default_ttl: + type: integer + nullable: true + description: The default `ttl` value for Sessions created in the Service. + The TTL (time to live) is measured in seconds after the Session's last + create or last Interaction. The default value of `0` indicates an unlimited + Session length. You can override a Session's default TTL value by setting + its `ttl` value. + number_selection_behavior: + type: string + $ref: '#/components/schemas/service_enum_number_selection_behavior' + nullable: true + description: 'The preference for Proxy Number selection in the Service instance. + Can be: `prefer-sticky` or `avoid-sticky`. `prefer-sticky` means that + we will try and select the same Proxy Number for a given participant if + they have previous [Sessions](https://www.twilio.com/docs/proxy/api/session), + but we will not fail if that Proxy Number cannot be used. `avoid-sticky` + means that we will try to use different Proxy Numbers as long as that + is possible within a given pool rather than try and use a previously assigned + number.' + geo_match_level: + type: string + $ref: '#/components/schemas/service_enum_geo_match_level' + nullable: true + description: 'Where a proxy number must be located relative to the participant + identifier. Can be: `country`, `area-code`, or `extended-area-code`. The + default value is `country` and more specific areas than `country` are + only available in North America.' + intercept_callback_url: + type: string + format: uri + nullable: true + description: The URL we call on each interaction. If we receive a 403 status, + we block the interaction; otherwise the interaction continues. + out_of_session_callback_url: + type: string + format: uri + nullable: true + description: The URL we call when an inbound call or SMS action occurs on + a closed or non-existent Session. If your server (or a Twilio [function](https://www.twilio.com/functions)) + responds with valid [TwiML](https://www.twilio.com/docs/voice/twiml), + we will process it. This means it is possible, for example, to play a + message for a call, send an automated text message response, or redirect + a call to another Phone Number. See [Out-of-Session Callback Response + Guide](https://www.twilio.com/docs/proxy/out-session-callback-response-guide) + for more information. + date_created: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was created. + date_updated: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was last updated. + url: + type: string + format: uri + nullable: true + description: The absolute URL of the Service resource. + links: + type: object + format: uri-map + nullable: true + description: The URLs of resources related to the Service. + service_enum_geo_match_level: + type: string + enum: + - area-code + - overlay + - radius + - country + service_enum_number_selection_behavior: + type: string + enum: + - avoid-sticky + - prefer-sticky + proxy.v1.service.session: + type: object + properties: + sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + nullable: true + description: The unique string that we created to identify the Session resource. + service_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the [Service](https://www.twilio.com/docs/proxy/api/service) + the session is associated with. + account_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^AC[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) + that created the Session resource. + date_started: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + when the Session started. + date_ended: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + when the Session ended. + date_last_interaction: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + when the Session last had an interaction. + date_expiry: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + when the Session should expire. If this is value is present, it overrides + the `ttl` value. + unique_name: + type: string + nullable: true + description: An application-defined string that uniquely identifies the + resource. This value must be 191 characters or fewer in length and be + unique. Supports UTF-8 characters. **This value should not have PII.** + status: + type: string + $ref: '#/components/schemas/session_enum_status' + nullable: true + description: 'The status of the Session. Can be: `open`, `in-progress`, + `closed`, `failed`, or `unknown`.' + closed_reason: + type: string + nullable: true + description: The reason the Session ended. + ttl: + type: integer + nullable: true + description: The time, in seconds, when the session will expire. The time + is measured from the last Session create or the Session's last Interaction. + mode: + type: string + $ref: '#/components/schemas/session_enum_mode' + nullable: true + description: 'The Mode of the Session. Can be: `message-only`, `voice-only`, + or `voice-and-message`.' + date_created: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was created. + date_updated: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was last updated. + url: + type: string + format: uri + nullable: true + description: The absolute URL of the Session resource. + links: + type: object + format: uri-map + nullable: true + description: The URLs of resources related to the Session. + session_enum_status: + type: string + enum: + - open + - in-progress + - closed + - failed + - unknown + session_enum_mode: + type: string + enum: + - message-only + - voice-only + - voice-and-message + proxy.v1.service.short_code: + type: object + properties: + sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^SC[0-9a-fA-F]{32}$ + nullable: true + description: The unique string that we created to identify the ShortCode + resource. + account_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^AC[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) + that created the ShortCode resource. + service_sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + nullable: true + description: The SID of the ShortCode resource's parent [Service](https://www.twilio.com/docs/proxy/api/service) + resource. + date_created: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was created. + date_updated: + type: string + format: date-time + nullable: true + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date + and time in GMT when the resource was last updated. + short_code: + type: string + nullable: true + description: The short code's number. + iso_country: + type: string + nullable: true + description: The ISO Country Code for the short code. + capabilities: + type: object + format: phone-number-capabilities + properties: + mms: + type: boolean + sms: + type: boolean + voice: + type: boolean + fax: + type: boolean + nullable: true + description: The capabilities of the short code. + url: + type: string + format: uri + nullable: true + description: The absolute URL of the ShortCode resource. + is_reserved: + type: boolean + nullable: true + description: Whether the short code should be reserved and not be assigned + to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) + for more information. + securitySchemes: + accountSid_authToken: + type: http + scheme: basic +info: + title: Twilio - Proxy + description: This is the public Twilio REST API. + termsOfService: https://www.twilio.com/legal/tos + contact: + name: Twilio Support + url: https://support.twilio.com + email: support@twilio.com + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html + version: 1.48.0 +openapi: 3.0.1 +paths: + /v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions/{Sid}: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - type + - data + pathType: instance + parent: /Services/{ServiceSid}/Sessions/{Sid} + get: + description: Retrieve a list of Interactions for a given [Session](https://www.twilio.com/docs/proxy/api/session). + tags: + - ProxyV1Interaction + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: SessionSid + in: path + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + of the resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the Interaction + resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KI[0-9a-fA-F]{32}$ + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.session.interaction' + description: OK + security: + - accountSid_authToken: [] + operationId: FetchInteraction + x-maturity: + - Beta + delete: + description: Delete a specific Interaction. + tags: + - ProxyV1Interaction + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: SessionSid + in: path + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + of the resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the Interaction + resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KI[0-9a-fA-F]{32}$ + required: true + responses: + '204': + description: The resource was deleted successfully. + security: + - accountSid_authToken: [] + operationId: DeleteInteraction + x-maturity: + - Beta + /v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - type + - data + pathType: list + parent: /Services/{ServiceSid}/Sessions/{Sid} + get: + description: Retrieve a list of all Interactions for a Session. A maximum of + 100 records will be returned per page. + tags: + - ProxyV1Interaction + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + to read the resources from. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: SessionSid + in: path + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + to read the resources from. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + - name: PageSize + in: query + description: How many resources to return in each list page. The default is + 50, and the maximum is 1000. + schema: + type: integer + minimum: 1 + maximum: 1000 + - name: Page + in: query + description: The page index. This value is simply for client state. + schema: + type: integer + minimum: 0 + - name: PageToken + in: query + description: The page token. This is provided by the API. + schema: + type: string + responses: + '200': + content: + application/json: + schema: + type: object + title: ListInteractionResponse + properties: + interactions: + type: array + items: + $ref: '#/components/schemas/proxy.v1.service.session.interaction' + meta: + type: object + properties: + first_page_url: + type: string + format: uri + next_page_url: + type: string + format: uri + nullable: true + page: + type: integer + page_size: + type: integer + previous_page_url: + type: string + format: uri + nullable: true + url: + type: string + format: uri + key: + type: string + description: OK + security: + - accountSid_authToken: [] + operationId: ListInteraction + x-maturity: + - Beta + /v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - type + - data + pathType: list + parent: /Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{Sid} + post: + description: Create a new message Interaction to send directly from your system + to one [Participant](https://www.twilio.com/docs/proxy/api/participant). The + `inbound` properties for the Interaction will always be empty. + tags: + - ProxyV1MessageInteraction + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + resource. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: SessionSid + in: path + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + resource. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + - name: ParticipantSid + in: path + description: The SID of the [Participant](https://www.twilio.com/docs/proxy/api/participant) + resource. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KP[0-9a-fA-F]{32}$ + required: true + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.session.participant.message_interaction' + description: Created + security: + - accountSid_authToken: [] + operationId: CreateMessageInteraction + x-maturity: + - Beta + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + title: CreateMessageInteractionRequest + properties: + Body: + type: string + description: The message to send to the participant + MediaUrl: + type: array + items: + type: string + format: uri + description: Reserved. Not currently supported. + x-twilio: + conditional: + - - body + - media_url + get: + description: '' + tags: + - ProxyV1MessageInteraction + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + to read the resources from. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: SessionSid + in: path + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + to read the resources from. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + - name: ParticipantSid + in: path + description: The SID of the [Participant](https://www.twilio.com/docs/proxy/api/participant) + to read the resources from. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KP[0-9a-fA-F]{32}$ + required: true + - name: PageSize + in: query + description: How many resources to return in each list page. The default is + 50, and the maximum is 1000. + schema: + type: integer + minimum: 1 + maximum: 1000 + - name: Page + in: query + description: The page index. This value is simply for client state. + schema: + type: integer + minimum: 0 + - name: PageToken + in: query + description: The page token. This is provided by the API. + schema: + type: string + responses: + '200': + content: + application/json: + schema: + type: object + title: ListMessageInteractionResponse + properties: + interactions: + type: array + items: + $ref: '#/components/schemas/proxy.v1.service.session.participant.message_interaction' + meta: + type: object + properties: + first_page_url: + type: string + format: uri + next_page_url: + type: string + format: uri + nullable: true + page: + type: integer + page_size: + type: integer + previous_page_url: + type: string + format: uri + nullable: true + url: + type: string + format: uri + key: + type: string + description: OK + security: + - accountSid_authToken: [] + operationId: ListMessageInteraction + x-maturity: + - Beta + /v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions/{Sid}: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - type + - data + pathType: instance + parent: /Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{Sid} + get: + description: '' + tags: + - ProxyV1MessageInteraction + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: SessionSid + in: path + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + of the resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + - name: ParticipantSid + in: path + description: The SID of the [Participant](https://www.twilio.com/docs/proxy/api/participant) + resource. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KP[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the MessageInteraction + resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KI[0-9a-fA-F]{32}$ + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.session.participant.message_interaction' + description: OK + security: + - accountSid_authToken: [] + operationId: FetchMessageInteraction + x-maturity: + - Beta + /v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{Sid}: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - friendly_name + - identifier + - proxy_identifier + pathType: instance + dependentProperties: + message_interaction: '{service_sid: service_sid, session_sid: session_sid, + participant_sid: sid}' + parent: /Services/{ServiceSid}/Sessions/{Sid} + get: + description: Fetch a specific Participant. + tags: + - ProxyV1Participant + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: SessionSid + in: path + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + of the resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the Participant + resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KP[0-9a-fA-F]{32}$ + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.session.participant' + description: OK + security: + - accountSid_authToken: [] + operationId: FetchParticipant + x-maturity: + - Beta + delete: + description: Delete a specific Participant. This is a soft-delete. The participant + remains associated with the session and cannot be re-added. Participants are + only permanently deleted when the [Session](https://www.twilio.com/docs/proxy/api/session) + is deleted. + tags: + - ProxyV1Participant + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: SessionSid + in: path + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + of the resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the Participant + resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KP[0-9a-fA-F]{32}$ + required: true + responses: + '204': + description: The resource was deleted successfully. + security: + - accountSid_authToken: [] + operationId: DeleteParticipant + x-maturity: + - Beta + /v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - friendly_name + - identifier + - proxy_identifier + pathType: list + dependentProperties: + message_interaction: '{service_sid: service_sid, session_sid: session_sid, + participant_sid: sid}' + parent: /Services/{ServiceSid}/Sessions/{Sid} + get: + description: Retrieve a list of all Participants in a Session. + tags: + - ProxyV1Participant + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the resources to read. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: SessionSid + in: path + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + of the resources to read. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + - name: PageSize + in: query + description: How many resources to return in each list page. The default is + 50, and the maximum is 1000. + schema: + type: integer + minimum: 1 + maximum: 1000 + - name: Page + in: query + description: The page index. This value is simply for client state. + schema: + type: integer + minimum: 0 + - name: PageToken + in: query + description: The page token. This is provided by the API. + schema: + type: string + responses: + '200': + content: + application/json: + schema: + type: object + title: ListParticipantResponse + properties: + participants: + type: array + items: + $ref: '#/components/schemas/proxy.v1.service.session.participant' + meta: + type: object + properties: + first_page_url: + type: string + format: uri + next_page_url: + type: string + format: uri + nullable: true + page: + type: integer + page_size: + type: integer + previous_page_url: + type: string + format: uri + nullable: true + url: + type: string + format: uri + key: + type: string + description: OK + security: + - accountSid_authToken: [] + operationId: ListParticipant + x-maturity: + - Beta + post: + description: Add a new Participant to the Session + tags: + - ProxyV1Participant + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + resource. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: SessionSid + in: path + description: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) + resource. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.session.participant' + description: Created + security: + - accountSid_authToken: [] + operationId: CreateParticipant + x-maturity: + - Beta + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + title: CreateParticipantRequest + properties: + Identifier: + type: string + description: The phone number of the Participant. + FriendlyName: + type: string + description: The string that you assigned to describe the participant. + This value must be 255 characters or fewer. **This value should + not have PII.** + ProxyIdentifier: + type: string + description: The proxy phone number to use for the Participant. + If not specified, Proxy will select a number from the pool. + ProxyIdentifierSid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^PN[0-9a-fA-F]{32}$ + description: The SID of the Proxy Identifier to assign to the Participant. + required: + - Identifier + /v1/Services/{ServiceSid}/PhoneNumbers: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - friendly_name + - phone_number + pathType: list + parent: /Services/{Sid} + post: + description: Add a Phone Number to a Service's Proxy Number Pool. + tags: + - ProxyV1PhoneNumber + parameters: + - name: ServiceSid + in: path + description: The SID parent [Service](https://www.twilio.com/docs/proxy/api/service) + resource of the new PhoneNumber resource. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.phone_number' + description: Created + security: + - accountSid_authToken: [] + operationId: CreatePhoneNumber + x-maturity: + - Beta + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + title: CreatePhoneNumberRequest + properties: + Sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^PN[0-9a-fA-F]{32}$ + description: The SID of a Twilio [IncomingPhoneNumber](https://www.twilio.com/docs/phone-numbers/api/incomingphonenumber-resource) + resource that represents the Twilio Number you would like to assign + to your Proxy Service. + PhoneNumber: + type: string + format: phone-number + description: The phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) + format. E.164 phone numbers consist of a + followed by the country + code and subscriber number without punctuation characters. For + example, +14155551234. + IsReserved: + type: boolean + description: Whether the new phone number should be reserved and + not be assigned to a participant using proxy pool logic. See [Reserved + Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) + for more information. + get: + description: Retrieve a list of all Phone Numbers in the Proxy Number Pool for + a Service. A maximum of 100 records will be returned per page. + tags: + - ProxyV1PhoneNumber + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the PhoneNumber resources to read. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: PageSize + in: query + description: How many resources to return in each list page. The default is + 50, and the maximum is 1000. + schema: + type: integer + minimum: 1 + maximum: 1000 + - name: Page + in: query + description: The page index. This value is simply for client state. + schema: + type: integer + minimum: 0 + - name: PageToken + in: query + description: The page token. This is provided by the API. + schema: + type: string + responses: + '200': + content: + application/json: + schema: + type: object + title: ListPhoneNumberResponse + properties: + phone_numbers: + type: array + items: + $ref: '#/components/schemas/proxy.v1.service.phone_number' + meta: + type: object + properties: + first_page_url: + type: string + format: uri + next_page_url: + type: string + format: uri + nullable: true + page: + type: integer + page_size: + type: integer + previous_page_url: + type: string + format: uri + nullable: true + url: + type: string + format: uri + key: + type: string + description: OK + security: + - accountSid_authToken: [] + operationId: ListPhoneNumber + x-maturity: + - Beta + /v1/Services/{ServiceSid}/PhoneNumbers/{Sid}: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - friendly_name + - phone_number + pathType: instance + parent: /Services/{Sid} + delete: + description: Delete a specific Phone Number from a Service. + tags: + - ProxyV1PhoneNumber + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the PhoneNumber resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the PhoneNumber + resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^PN[0-9a-fA-F]{32}$ + required: true + responses: + '204': + description: The resource was deleted successfully. + security: + - accountSid_authToken: [] + operationId: DeletePhoneNumber + x-maturity: + - Beta + get: + description: Fetch a specific Phone Number. + tags: + - ProxyV1PhoneNumber + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the PhoneNumber resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the PhoneNumber + resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^PN[0-9a-fA-F]{32}$ + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.phone_number' + description: OK + security: + - accountSid_authToken: [] + operationId: FetchPhoneNumber + x-maturity: + - Beta + post: + description: Update a specific Proxy Number. + tags: + - ProxyV1PhoneNumber + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the PhoneNumber resource to update. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the PhoneNumber + resource to update. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^PN[0-9a-fA-F]{32}$ + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.phone_number' + description: OK + security: + - accountSid_authToken: [] + operationId: UpdatePhoneNumber + x-maturity: + - Beta + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + title: UpdatePhoneNumberRequest + properties: + IsReserved: + type: boolean + description: Whether the phone number should be reserved and not + be assigned to a participant using proxy pool logic. See [Reserved + Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) + for more information. + /v1/Services/{Sid}: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - unique_name + - date_created + pathType: instance + dependentProperties: + session: '{service_sid: sid}' + phone_number: '{service_sid: sid}' + short_code: '{service_sid: sid}' + get: + description: Fetch a specific Service. + tags: + - ProxyV1Service + parameters: + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the Service + resource to fetch. + schema: + type: string + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service' + description: OK + security: + - accountSid_authToken: [] + operationId: FetchService + x-maturity: + - Beta + delete: + description: Delete a specific Service. + tags: + - ProxyV1Service + parameters: + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the Service + resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + responses: + '204': + description: The resource was deleted successfully. + security: + - accountSid_authToken: [] + operationId: DeleteService + x-maturity: + - Beta + post: + description: Update a specific Service. + tags: + - ProxyV1Service + parameters: + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the Service + resource to update. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service' + description: OK + security: + - accountSid_authToken: [] + operationId: UpdateService + x-maturity: + - Beta + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + title: UpdateServiceRequest + properties: + UniqueName: + type: string + description: An application-defined string that uniquely identifies + the resource. This value must be 191 characters or fewer in length + and be unique. **This value should not have PII.** + DefaultTtl: + type: integer + description: The default `ttl` value to set for Sessions created + in the Service. The TTL (time to live) is measured in seconds + after the Session's last create or last Interaction. The default + value of `0` indicates an unlimited Session length. You can override + a Session's default TTL value by setting its `ttl` value. + CallbackUrl: + type: string + format: uri + description: The URL we should call when the interaction status + changes. + GeoMatchLevel: + type: string + $ref: '#/components/schemas/service_enum_geo_match_level' + description: 'Where a proxy number must be located relative to the + participant identifier. Can be: `country`, `area-code`, or `extended-area-code`. + The default value is `country` and more specific areas than `country` + are only available in North America.' + NumberSelectionBehavior: + type: string + $ref: '#/components/schemas/service_enum_number_selection_behavior' + description: 'The preference for Proxy Number selection in the Service + instance. Can be: `prefer-sticky` or `avoid-sticky` and the default + is `prefer-sticky`. `prefer-sticky` means that we will try and + select the same Proxy Number for a given participant if they have + previous [Sessions](https://www.twilio.com/docs/proxy/api/session), + but we will not fail if that Proxy Number cannot be used. `avoid-sticky` + means that we will try to use different Proxy Numbers as long + as that is possible within a given pool rather than try and use + a previously assigned number.' + InterceptCallbackUrl: + type: string + format: uri + description: The URL we call on each interaction. If we receive + a 403 status, we block the interaction; otherwise the interaction + continues. + OutOfSessionCallbackUrl: + type: string + format: uri + description: The URL we should call when an inbound call or SMS + action occurs on a closed or non-existent Session. If your server + (or a Twilio [function](https://www.twilio.com/functions)) responds + with valid [TwiML](https://www.twilio.com/docs/voice/twiml), we + will process it. This means it is possible, for example, to play + a message for a call, send an automated text message response, + or redirect a call to another Phone Number. See [Out-of-Session + Callback Response Guide](https://www.twilio.com/docs/proxy/out-session-callback-response-guide) + for more information. + ChatInstanceSid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^IS[0-9a-fA-F]{32}$ + description: The SID of the Chat Service Instance managed by Proxy + Service. The Chat Service enables Proxy to forward SMS and channel + messages to this chat instance. This is a one-to-one relationship. + /v1/Services: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - unique_name + - date_created + pathType: list + dependentProperties: + session: '{service_sid: sid}' + phone_number: '{service_sid: sid}' + short_code: '{service_sid: sid}' + get: + description: Retrieve a list of all Services for Twilio Proxy. A maximum of + 100 records will be returned per page. + tags: + - ProxyV1Service + parameters: + - name: PageSize + in: query + description: How many resources to return in each list page. The default is + 50, and the maximum is 1000. + schema: + type: integer + minimum: 1 + maximum: 1000 + - name: Page + in: query + description: The page index. This value is simply for client state. + schema: + type: integer + minimum: 0 + - name: PageToken + in: query + description: The page token. This is provided by the API. + schema: + type: string + responses: + '200': + content: + application/json: + schema: + type: object + title: ListServiceResponse + properties: + services: + type: array + items: + $ref: '#/components/schemas/proxy.v1.service' + meta: + type: object + properties: + first_page_url: + type: string + format: uri + next_page_url: + type: string + format: uri + nullable: true + page: + type: integer + page_size: + type: integer + previous_page_url: + type: string + format: uri + nullable: true + url: + type: string + format: uri + key: + type: string + description: OK + security: + - accountSid_authToken: [] + operationId: ListService + x-maturity: + - Beta + post: + description: Create a new Service for Twilio Proxy + tags: + - ProxyV1Service + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service' + description: Created + security: + - accountSid_authToken: [] + operationId: CreateService + x-maturity: + - Beta + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + title: CreateServiceRequest + properties: + UniqueName: + type: string + description: An application-defined string that uniquely identifies + the resource. This value must be 191 characters or fewer in length + and be unique. **This value should not have PII.** + DefaultTtl: + type: integer + description: The default `ttl` value to set for Sessions created + in the Service. The TTL (time to live) is measured in seconds + after the Session's last create or last Interaction. The default + value of `0` indicates an unlimited Session length. You can override + a Session's default TTL value by setting its `ttl` value. + CallbackUrl: + type: string + format: uri + description: The URL we should call when the interaction status + changes. + GeoMatchLevel: + type: string + $ref: '#/components/schemas/service_enum_geo_match_level' + description: 'Where a proxy number must be located relative to the + participant identifier. Can be: `country`, `area-code`, or `extended-area-code`. + The default value is `country` and more specific areas than `country` + are only available in North America.' + NumberSelectionBehavior: + type: string + $ref: '#/components/schemas/service_enum_number_selection_behavior' + description: 'The preference for Proxy Number selection in the Service + instance. Can be: `prefer-sticky` or `avoid-sticky` and the default + is `prefer-sticky`. `prefer-sticky` means that we will try and + select the same Proxy Number for a given participant if they have + previous [Sessions](https://www.twilio.com/docs/proxy/api/session), + but we will not fail if that Proxy Number cannot be used. `avoid-sticky` + means that we will try to use different Proxy Numbers as long + as that is possible within a given pool rather than try and use + a previously assigned number.' + InterceptCallbackUrl: + type: string + format: uri + description: The URL we call on each interaction. If we receive + a 403 status, we block the interaction; otherwise the interaction + continues. + OutOfSessionCallbackUrl: + type: string + format: uri + description: The URL we should call when an inbound call or SMS + action occurs on a closed or non-existent Session. If your server + (or a Twilio [function](https://www.twilio.com/functions)) responds + with valid [TwiML](https://www.twilio.com/docs/voice/twiml), we + will process it. This means it is possible, for example, to play + a message for a call, send an automated text message response, + or redirect a call to another Phone Number. See [Out-of-Session + Callback Response Guide](https://www.twilio.com/docs/proxy/out-session-callback-response-guide) + for more information. + ChatInstanceSid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^IS[0-9a-fA-F]{32}$ + description: The SID of the Chat Service Instance managed by Proxy + Service. The Chat Service enables Proxy to forward SMS and channel + messages to this chat instance. This is a one-to-one relationship. + required: + - UniqueName + /v1/Services/{ServiceSid}/Sessions/{Sid}: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - unique_name + - date_started + - date_ended + pathType: instance + dependentProperties: + interaction: '{service_sid: service_sid, session_sid: sid}' + participant: '{service_sid: service_sid, session_sid: sid}' + parent: /Services/{Sid} + get: + description: Fetch a specific Session. + tags: + - ProxyV1Session + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the Session + resource to fetch. + schema: + type: string + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.session' + description: OK + security: + - accountSid_authToken: [] + operationId: FetchSession + x-maturity: + - Beta + delete: + description: Delete a specific Session. + tags: + - ProxyV1Session + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the Session + resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + responses: + '204': + description: The resource was deleted successfully. + security: + - accountSid_authToken: [] + operationId: DeleteSession + x-maturity: + - Beta + post: + description: Update a specific Session. + tags: + - ProxyV1Session + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the resource to update. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the Session + resource to update. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KC[0-9a-fA-F]{32}$ + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.session' + description: OK + security: + - accountSid_authToken: [] + operationId: UpdateSession + x-maturity: + - Beta + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + title: UpdateSessionRequest + properties: + DateExpiry: + type: string + format: date-time + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) + date when the Session should expire. If this is value is present, + it overrides the `ttl` value. + Ttl: + type: integer + description: The time, in seconds, when the session will expire. + The time is measured from the last Session create or the Session's + last Interaction. + Status: + type: string + $ref: '#/components/schemas/session_enum_status' + description: 'The new status of the resource. Can be: `in-progress` + to re-open a session or `closed` to close a session.' + /v1/Services/{ServiceSid}/Sessions: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - unique_name + - date_started + - date_ended + pathType: list + dependentProperties: + interaction: '{service_sid: service_sid, session_sid: sid}' + participant: '{service_sid: service_sid, session_sid: sid}' + parent: /Services/{Sid} + get: + description: Retrieve a list of all Sessions for the Service. A maximum of 100 + records will be returned per page. + tags: + - ProxyV1Session + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the resource to read. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: PageSize + in: query + description: How many resources to return in each list page. The default is + 50, and the maximum is 1000. + schema: + type: integer + minimum: 1 + maximum: 1000 + - name: Page + in: query + description: The page index. This value is simply for client state. + schema: + type: integer + minimum: 0 + - name: PageToken + in: query + description: The page token. This is provided by the API. + schema: + type: string + responses: + '200': + content: + application/json: + schema: + type: object + title: ListSessionResponse + properties: + sessions: + type: array + items: + $ref: '#/components/schemas/proxy.v1.service.session' + meta: + type: object + properties: + first_page_url: + type: string + format: uri + next_page_url: + type: string + format: uri + nullable: true + page: + type: integer + page_size: + type: integer + previous_page_url: + type: string + format: uri + nullable: true + url: + type: string + format: uri + key: + type: string + description: OK + security: + - accountSid_authToken: [] + operationId: ListSession + x-maturity: + - Beta + post: + description: Create a new Session + tags: + - ProxyV1Session + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + resource. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.session' + description: Created + security: + - accountSid_authToken: [] + operationId: CreateSession + x-maturity: + - Beta + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + title: CreateSessionRequest + properties: + UniqueName: + type: string + description: An application-defined string that uniquely identifies + the resource. This value must be 191 characters or fewer in length + and be unique. **This value should not have PII.** + DateExpiry: + type: string + format: date-time + description: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) + date when the Session should expire. If this is value is present, + it overrides the `ttl` value. + Ttl: + type: integer + description: The time, in seconds, when the session will expire. + The time is measured from the last Session create or the Session's + last Interaction. + Mode: + type: string + $ref: '#/components/schemas/session_enum_mode' + description: 'The Mode of the Session. Can be: `message-only`, `voice-only`, + or `voice-and-message` and the default value is `voice-and-message`.' + Status: + type: string + $ref: '#/components/schemas/session_enum_status' + description: 'The initial status of the Session. Can be: `open`, + `in-progress`, `closed`, `failed`, or `unknown`. The default is + `open` on create.' + Participants: + type: array + items: {} + description: The Participant objects to include in the new session. + /v1/Services/{ServiceSid}/ShortCodes: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - short_code + - iso_country + pathType: list + parent: /Services/{Sid} + post: + description: Add a Short Code to the Proxy Number Pool for the Service. + tags: + - ProxyV1ShortCode + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + resource. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.short_code' + description: Created + security: + - accountSid_authToken: [] + operationId: CreateShortCode + x-maturity: + - Beta + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + title: CreateShortCodeRequest + properties: + Sid: + type: string + minLength: 34 + maxLength: 34 + pattern: ^SC[0-9a-fA-F]{32}$ + description: The SID of a Twilio [ShortCode](https://www.twilio.com/docs/sms/api/short-code) + resource that represents the short code you would like to assign + to your Proxy Service. + required: + - Sid + get: + description: Retrieve a list of all Short Codes in the Proxy Number Pool for + the Service. A maximum of 100 records will be returned per page. + tags: + - ProxyV1ShortCode + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + to read the resources from. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: PageSize + in: query + description: How many resources to return in each list page. The default is + 50, and the maximum is 1000. + schema: + type: integer + minimum: 1 + maximum: 1000 + - name: Page + in: query + description: The page index. This value is simply for client state. + schema: + type: integer + minimum: 0 + - name: PageToken + in: query + description: The page token. This is provided by the API. + schema: + type: string + responses: + '200': + content: + application/json: + schema: + type: object + title: ListShortCodeResponse + properties: + short_codes: + type: array + items: + $ref: '#/components/schemas/proxy.v1.service.short_code' + meta: + type: object + properties: + first_page_url: + type: string + format: uri + next_page_url: + type: string + format: uri + nullable: true + page: + type: integer + page_size: + type: integer + previous_page_url: + type: string + format: uri + nullable: true + url: + type: string + format: uri + key: + type: string + description: OK + security: + - accountSid_authToken: [] + operationId: ListShortCode + x-maturity: + - Beta + /v1/Services/{ServiceSid}/ShortCodes/{Sid}: + servers: + - url: https://proxy.twilio.com + description: 'TODO: Resource-level docs' + x-twilio: + defaultOutputProperties: + - sid + - short_code + - iso_country + pathType: instance + parent: /Services/{Sid} + delete: + description: Delete a specific Short Code from a Service. + tags: + - ProxyV1ShortCode + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + resource to delete the ShortCode resource from. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the ShortCode + resource to delete. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^SC[0-9a-fA-F]{32}$ + required: true + responses: + '204': + description: The resource was deleted successfully. + security: + - accountSid_authToken: [] + operationId: DeleteShortCode + x-maturity: + - Beta + get: + description: Fetch a specific Short Code. + tags: + - ProxyV1ShortCode + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + to fetch the resource from. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the ShortCode + resource to fetch. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^SC[0-9a-fA-F]{32}$ + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.short_code' + description: OK + security: + - accountSid_authToken: [] + operationId: FetchShortCode + x-maturity: + - Beta + post: + description: Update a specific Short Code. + tags: + - ProxyV1ShortCode + parameters: + - name: ServiceSid + in: path + description: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) + of the resource to update. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^KS[0-9a-fA-F]{32}$ + required: true + - name: Sid + in: path + description: The Twilio-provided string that uniquely identifies the ShortCode + resource to update. + schema: + type: string + minLength: 34 + maxLength: 34 + pattern: ^SC[0-9a-fA-F]{32}$ + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/proxy.v1.service.short_code' + description: OK + security: + - accountSid_authToken: [] + operationId: UpdateShortCode + x-maturity: + - Beta + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + title: UpdateShortCodeRequest + properties: + IsReserved: + type: boolean + description: Whether the short code should be reserved and not be + assigned to a participant using proxy pool logic. See [Reserved + Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) + for more information. +servers: +- url: https://proxy.twilio.com +tags: +- name: ProxyV1Interaction +- name: ProxyV1MessageInteraction +- name: ProxyV1Participant +- name: ProxyV1PhoneNumber +- name: ProxyV1Service +- name: ProxyV1Session +- name: ProxyV1ShortCode +x-maturity: +- name: Beta + description: PLEASE NOTE that this is a Beta product that is subject to change. + Use it with caution. \ No newline at end of file diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index e581511fe..264b0833b 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -173,7 +173,7 @@ private JavaApiResources processCodegenOperations(List opList) javaApiResourceBuilder.updateOperations(new JavaParameterResolver(conventionMapper)) .updateResponseModel(new JavaPropertyResolver(conventionMapper), codegenModelResolver); if (isIngress) { - //javaApiResourceBuilder.updateModel(codegenModelResolver); + //javaApiResourceBuilder.updateModel(codegenModelResolver); } return javaApiResourceBuilder.build(); } diff --git a/src/main/java/com/twilio/oai/TwilioNodeGenerator.java b/src/main/java/com/twilio/oai/TwilioNodeGenerator.java index ff9b15478..bc7fc000f 100644 --- a/src/main/java/com/twilio/oai/TwilioNodeGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioNodeGenerator.java @@ -8,6 +8,8 @@ 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.NodeParameterResolver; import com.twilio.oai.resource.IResourceTree; @@ -43,6 +45,8 @@ public class TwilioNodeGenerator extends TypeScriptNodeClientCodegen { private final List allModels = new ArrayList<>(); private final Map modelFormatMap = new HashMap<>(); + public static final String JSON_INGRESS = "json_ingress"; + public TwilioNodeGenerator() { super(); twilioCodegen = new TwilioCodegenAdapter(this, getName()); @@ -102,12 +106,14 @@ private ApiResources generateResources(final List opList) { modelFormatMap, List.of(EnumConstants.NodeDataTypes.values())); - return new NodeApiResourceBuilder(actionTemplate, opList, allModels, directoryStructureService) - .updateApiPath() + NodeApiResourceBuilder nodeApiResourceBuilder = new NodeApiResourceBuilder(actionTemplate, opList, allModels, directoryStructureService + , twilioCodegen.getToggles(JSON_INGRESS)); + + nodeApiResourceBuilder.updateApiPath() .updateTemplate() .updateOperations(new NodeParameterResolver(conventionMapper)) - .updateResponseModel(new LanguagePropertyResolver(conventionMapper), codegenModelResolver) - .build(); + .updateResponseModel(new LanguagePropertyResolver(conventionMapper), codegenModelResolver); + return nodeApiResourceBuilder.build(); } @Override diff --git a/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java index f406ba657..a639fb45c 100644 --- a/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java @@ -468,7 +468,7 @@ private ArrayList> generateSignatureListBody(final Codegen } ArrayList> signatureList = new ArrayList<>(); for(List paramList : filteredConditionalCodegenParam){ - if (co.bodyParams != null && co.bodyParams.get(0) != null) + if (co.bodyParams != null && co.bodyParams.size() != 0 && co.bodyParams.get(0) != null) signatureList.add(addAllToList(co.bodyParams.get(0).requiredVars, paramList)); } return signatureList; diff --git a/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java index 24fbc1f91..0cbebee5a 100644 --- a/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java @@ -2,16 +2,20 @@ 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.template.IApiActionTemplate; import java.util.List; +import java.util.Map; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.CodegenParameter; +import static com.twilio.oai.template.AbstractApiActionTemplate.NESTED_MODELS; + public class NodeApiResourceBuilder extends FluentApiResourceBuilder { public NodeApiResourceBuilder(final IApiActionTemplate template, final List codegenOperations, @@ -20,6 +24,15 @@ public NodeApiResourceBuilder(final IApiActionTemplate template, super(template, codegenOperations, allModels, directoryStructureService); } + public NodeApiResourceBuilder(final IApiActionTemplate template, + final List codegenOperations, + final List allModels, + final DirectoryStructureService directoryStructureService, + final Map toggleMap) { + super(template, codegenOperations, allModels, directoryStructureService); + this.toggleMap = toggleMap; + } + @Override public ApiResourceBuilder updateOperations(final Resolver codegenParameterIResolver) { super.updateOperations(codegenParameterIResolver); @@ -52,6 +65,15 @@ public ApiResourceBuilder updateOperations(final Resolver code return this; } + @Override + public ApiResourceBuilder updateModel(Resolver codegenModelResolver) { + super.updateModel(codegenModelResolver); + if (Boolean.TRUE.equals(getToggleMap().get(EnumConstants.Generator.TWILIO_NODE.getValue())) && !nestedModels.isEmpty()) { + template.add(NESTED_MODELS); + } + return this; + } + @Override protected String getModelName(final String classname) { return removeEnumName(classname); diff --git a/src/main/java/com/twilio/oai/resolver/node/NodePropertyResolver.java b/src/main/java/com/twilio/oai/resolver/node/NodePropertyResolver.java new file mode 100644 index 000000000..c613f383a --- /dev/null +++ b/src/main/java/com/twilio/oai/resolver/node/NodePropertyResolver.java @@ -0,0 +1,81 @@ +package com.twilio.oai.resolver.node; + +import com.twilio.oai.Segments; +import com.twilio.oai.StringHelper; +import com.twilio.oai.api.ApiResourceBuilder; +import com.twilio.oai.common.EnumConstants; +import com.twilio.oai.resolver.ConfigurationSegment; +import com.twilio.oai.resolver.IConventionMapper; +import com.twilio.oai.resolver.LanguagePropertyResolver; +import org.openapitools.codegen.CodegenModel; +import org.openapitools.codegen.CodegenProperty; + +import java.util.HashMap; +import java.util.Map; + +import static com.twilio.oai.common.ApplicationConstants.VENDOR_PREFIX; + +public class NodePropertyResolver extends LanguagePropertyResolver { + public NodePropertyResolver(IConventionMapper mapper) { + super(mapper); + } + + @Override + public void resolveProperties(CodegenProperty property, ApiResourceBuilder apiResourceBuilder) { + super.resolveProperties(property, apiResourceBuilder); + Map> vendorExtensions = new HashMap<>(); + + for (Segments segment : Segments.values()) { + getMapperByType(segment).get(property.dataFormat).ifPresent(value -> { + Map segmentElements = new HashMap<>(); + segmentElements.put(VENDOR_PREFIX + property.dataFormat, + value.toString().replaceAll("\\{.*}", property.name)); + vendorExtensions.put(segment.getSegment(), segmentElements); + }); + } + + property.nameInSnakeCase = StringHelper.toSnakeCase(property.name); + + // Merges the vendorExtensions map with the existing property's vendor extensions + vendorExtensions.forEach( + (key, value) -> property.getVendorExtensions().merge(key, value, (oldValue, newValue) -> newValue) + ); + + if (apiResourceBuilder.getToggleMap().getOrDefault(EnumConstants.Generator.TWILIO_JAVA.getValue(), Boolean.FALSE) ) { + resolveIngressModel(property, apiResourceBuilder); + } + } + + ConfigurationSegment getMapperByType(Segments segments) { + switch (segments) { + case SEGMENT_PROPERTIES: + return mapper.properties(); + case SEGMENT_LIBRARY: + return mapper.libraries(); + case SEGMENT_DESERIALIZE: + return mapper.deserialize(); + case SEGMENT_SERIALIZE: + return mapper.serialize(); + case SEGMENT_PROMOTIONS: + return mapper.promotions(); + case SEGMENT_HYDRATE: + return mapper.hydrate(); + } + return null; + + } + + @Override + public void resolveDeSerialize(CodegenProperty codegenProperty) { + super.resolveDeSerialize(codegenProperty); + } + + private void resolveIngressModel(CodegenProperty property, ApiResourceBuilder apiResourceBuilder) { + for (CodegenModel model : apiResourceBuilder.getAllModels()) { + if(model.getClassname().equals(property.complexType)) { + // Fetch model from allModels and resolve that recursively + property.dataType = apiResourceBuilder.getApiName() + "." + property.dataType; + } + } + } +} diff --git a/src/main/resources/config/toggles.json b/src/main/resources/config/toggles.json index e0c3ec25d..09a026ca0 100644 --- a/src/main/resources/config/toggles.json +++ b/src/main/resources/config/toggles.json @@ -1,5 +1,6 @@ { "json_ingress": { - "twilio-java": true + "twilio-java": true, + "twilio-node": true } } diff --git a/src/test/java/com/twilio/oai/TwilioGeneratorTest.java b/src/test/java/com/twilio/oai/TwilioGeneratorTest.java index c93ef5293..02bd4bfe3 100644 --- a/src/test/java/com/twilio/oai/TwilioGeneratorTest.java +++ b/src/test/java/com/twilio/oai/TwilioGeneratorTest.java @@ -28,14 +28,7 @@ public class TwilioGeneratorTest { @Parameterized.Parameters public static Collection generators() { - 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); + return Arrays.asList(Generator.TWILIO_JAVA); } private final Generator generator; @@ -47,7 +40,8 @@ public static void setUp() { @Test public void launchGenerator() { - final String pathname = "examples/spec/twilio_api_v2010.yaml"; + // 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"; File filesList[] ; File directoryPath = new File(pathname); if (directoryPath.isDirectory()) { From 6e408c81853cd11f6f6bf5856f3c00543fd7924d Mon Sep 17 00:00:00 2001 From: kridai Date: Wed, 11 Oct 2023 12:07:00 +0530 Subject: [PATCH 08/12] feat: node json ingress changes --- .../java/com/twilio/oai/CodegenUtils.java | 14 ++++++++- .../com/twilio/oai/TwilioNodeGenerator.java | 2 +- .../oai/api/NodeApiResourceBuilder.java | 5 ---- .../oai/resolver/LanguageParamResolver.java | 30 ++++++++++++++++--- ...CodegenModelContainerDataTypeResolver.java | 13 ++++++++ .../resolver/common/CodegenModelResolver.java | 29 ++++++++++++++++-- .../resolver/node/NodeParameterResolver.java | 7 +++-- src/main/resources/twilio-node/model.mustache | 2 +- 8 files changed, 86 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/twilio/oai/CodegenUtils.java b/src/main/java/com/twilio/oai/CodegenUtils.java index fdb5b4e65..cf516cf98 100644 --- a/src/main/java/com/twilio/oai/CodegenUtils.java +++ b/src/main/java/com/twilio/oai/CodegenUtils.java @@ -3,6 +3,9 @@ import org.openapitools.codegen.CodegenParameter; import org.openapitools.codegen.CodegenProperty; +import java.util.LinkedHashMap; +import java.util.Map; + public class CodegenUtils { public static boolean isPropertySchemaEnum(CodegenProperty codegenProperty) { @@ -17,7 +20,7 @@ public static boolean isPropertySchemaEnum(CodegenProperty codegenProperty) { } public static boolean isParameterSchemaEnum(CodegenParameter codegenParameter) { - if(codegenParameter.isEnum) { + if (codegenParameter.isEnum) { return true; } boolean enumValues = codegenParameter.allowableValues != null && @@ -49,4 +52,13 @@ public static boolean isParameterSchemaEnumJava(CodegenParameter codegenParamete && codegenParameter.items.allowableValues.containsKey(TwilioJavaGenerator.VALUES)); return enumValues || listEnumValues; } + + public static void mergeVendorExtensionProperty(Map vendorExtensions, LinkedHashMap value, String field ) { + if (value != null && !value.isEmpty()) { + if( vendorExtensions.containsKey(field)) + ((LinkedHashMap)vendorExtensions.get(field)).putAll(value); + else + vendorExtensions.put(field, value); + } + } } diff --git a/src/main/java/com/twilio/oai/TwilioNodeGenerator.java b/src/main/java/com/twilio/oai/TwilioNodeGenerator.java index bc7fc000f..2db7f20e1 100644 --- a/src/main/java/com/twilio/oai/TwilioNodeGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioNodeGenerator.java @@ -111,7 +111,7 @@ private ApiResources generateResources(final List opList) { nodeApiResourceBuilder.updateApiPath() .updateTemplate() - .updateOperations(new NodeParameterResolver(conventionMapper)) + .updateOperations(new NodeParameterResolver(conventionMapper, codegenModelResolver)) .updateResponseModel(new LanguagePropertyResolver(conventionMapper), codegenModelResolver); return nodeApiResourceBuilder.build(); } diff --git a/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java index 0cbebee5a..d5aacdca7 100644 --- a/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java @@ -14,8 +14,6 @@ import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.CodegenParameter; -import static com.twilio.oai.template.AbstractApiActionTemplate.NESTED_MODELS; - public class NodeApiResourceBuilder extends FluentApiResourceBuilder { public NodeApiResourceBuilder(final IApiActionTemplate template, final List codegenOperations, @@ -68,9 +66,6 @@ public ApiResourceBuilder updateOperations(final Resolver code @Override public ApiResourceBuilder updateModel(Resolver codegenModelResolver) { super.updateModel(codegenModelResolver); - if (Boolean.TRUE.equals(getToggleMap().get(EnumConstants.Generator.TWILIO_NODE.getValue())) && !nestedModels.isEmpty()) { - template.add(NESTED_MODELS); - } return this; } diff --git a/src/main/java/com/twilio/oai/resolver/LanguageParamResolver.java b/src/main/java/com/twilio/oai/resolver/LanguageParamResolver.java index 74e3b4c02..9f2a6a211 100644 --- a/src/main/java/com/twilio/oai/resolver/LanguageParamResolver.java +++ b/src/main/java/com/twilio/oai/resolver/LanguageParamResolver.java @@ -1,26 +1,48 @@ package com.twilio.oai.resolver; +import com.twilio.oai.CodegenUtils; import com.twilio.oai.StringHelper; import com.twilio.oai.api.ApiResourceBuilder; import com.twilio.oai.common.ApplicationConstants; +import com.twilio.oai.resolver.common.CodegenModelResolver; import lombok.AllArgsConstructor; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenParameter; +import java.util.LinkedHashMap; import java.util.List; import static com.twilio.oai.common.ApplicationConstants.SERIALIZE_VEND_EXT; -@AllArgsConstructor public class LanguageParamResolver extends Resolver { protected IConventionMapper mapper; + protected CodegenModelResolver codegenModelResolver; + + public LanguageParamResolver(IConventionMapper mapper) { + this.mapper = mapper; + } + + public LanguageParamResolver(IConventionMapper mapper, CodegenModelResolver codegenModelResolver) { + this.mapper = mapper; + this.codegenModelResolver = codegenModelResolver; + } @Override public CodegenParameter resolve(CodegenParameter codegenParameter, ApiResourceBuilder apiResourceBuilder) { - resolveProperties(codegenParameter, apiResourceBuilder); - resolvePrefixedMap(codegenParameter); - resolveSerialize(codegenParameter); + + CodegenModel codegenModel = apiResourceBuilder.getModel(codegenParameter.dataType); + if (codegenModel != null && codegenModelResolver !=null && !CodegenUtils.isParameterSchemaEnum(codegenParameter)) { //json body + codegenModelResolver.resolve(codegenModel, apiResourceBuilder); + CodegenUtils.mergeVendorExtensionProperty(codegenParameter.vendorExtensions, + (LinkedHashMap) codegenModel.getVendorExtensions().get("x-import"), "x-import"); + apiResourceBuilder.addNestedModel(codegenModel); + } + else { + resolveProperties(codegenParameter, apiResourceBuilder); + resolvePrefixedMap(codegenParameter); + resolveSerialize(codegenParameter); + } return codegenParameter; } 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 318f51ca9..07b756a9d 100644 --- a/src/main/java/com/twilio/oai/resolver/common/CodegenModelContainerDataTypeResolver.java +++ b/src/main/java/com/twilio/oai/resolver/common/CodegenModelContainerDataTypeResolver.java @@ -6,6 +6,7 @@ import com.twilio.oai.resolver.Resolver; import lombok.RequiredArgsConstructor; +import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenProperty; import java.util.List; @@ -26,6 +27,18 @@ 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"). 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 0036f200d..ca5f88e7b 100644 --- a/src/main/java/com/twilio/oai/resolver/common/CodegenModelResolver.java +++ b/src/main/java/com/twilio/oai/resolver/common/CodegenModelResolver.java @@ -1,5 +1,6 @@ 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; @@ -7,6 +8,8 @@ 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; @@ -33,13 +36,35 @@ 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); + 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 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/NodeParameterResolver.java b/src/main/java/com/twilio/oai/resolver/node/NodeParameterResolver.java index 2930c30c9..772cf14f2 100644 --- a/src/main/java/com/twilio/oai/resolver/node/NodeParameterResolver.java +++ b/src/main/java/com/twilio/oai/resolver/node/NodeParameterResolver.java @@ -1,9 +1,11 @@ package com.twilio.oai.resolver.node; +import com.twilio.oai.CodegenUtils; import com.twilio.oai.api.ApiResourceBuilder; import com.twilio.oai.resolver.IConventionMapper; import com.twilio.oai.resolver.LanguageParamResolver; +import com.twilio.oai.resolver.common.CodegenModelResolver; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenParameter; @@ -13,8 +15,9 @@ import static com.twilio.oai.common.ApplicationConstants.SERIALIZE_VEND_EXT; public class NodeParameterResolver extends LanguageParamResolver { - public NodeParameterResolver(final IConventionMapper mapper) { - super(mapper); + + public NodeParameterResolver(final IConventionMapper mapper, final CodegenModelResolver codegenModelResolver) { + super(mapper, codegenModelResolver); } @Override diff --git a/src/main/resources/twilio-node/model.mustache b/src/main/resources/twilio-node/model.mustache index d3ba41889..b4e7e2353 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 {{name}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}|{{/-last}}{{/enumVars}}{{/allowableValues}}; +export type {{classname}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}|{{/-last}}{{/enumVars}}{{/allowableValues}}; {{/isEnum}} {{/models}} From 19b04b9e4a75d24e8c8ceedc4f8ffca02368cb55 Mon Sep 17 00:00:00 2001 From: kridai Date: Wed, 11 Oct 2023 12:26:08 +0530 Subject: [PATCH 09/12] fix: restore codegenUtil --- .../java/com/twilio/oai/CodegenUtils.java | 37 +------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/src/main/java/com/twilio/oai/CodegenUtils.java b/src/main/java/com/twilio/oai/CodegenUtils.java index 2664f2707..2b81d8fac 100644 --- a/src/main/java/com/twilio/oai/CodegenUtils.java +++ b/src/main/java/com/twilio/oai/CodegenUtils.java @@ -3,9 +3,6 @@ import org.openapitools.codegen.CodegenParameter; import org.openapitools.codegen.CodegenProperty; -import java.util.LinkedHashMap; -import java.util.Map; - public class CodegenUtils { public static boolean isPropertySchemaEnum(CodegenProperty codegenProperty) { @@ -20,29 +17,6 @@ public static boolean isPropertySchemaEnum(CodegenProperty codegenProperty) { } public static boolean isParameterSchemaEnum(CodegenParameter codegenParameter) { - if (codegenParameter.isEnum) { - return true; - } - boolean enumValues = codegenParameter.allowableValues != null && - codegenParameter.allowableValues.containsKey(TwilioJavaGenerator.VALUES); - boolean listEnumValues = codegenParameter.items != null && (codegenParameter.items.allowableValues != null - && codegenParameter.items.allowableValues.containsKey(TwilioJavaGenerator.VALUES)); - return enumValues || listEnumValues; - } - - // TODO: Refactor java code. - public static boolean isPropertySchemaEnumJava(CodegenProperty codegenProperty) { - if(codegenProperty.isEnum) { - return false; - } - boolean enumValues = codegenProperty.allowableValues != null && - codegenProperty.allowableValues.containsKey(TwilioJavaGenerator.VALUES); - boolean listEnumValues = codegenProperty.items != null && (codegenProperty.items.allowableValues != null - && codegenProperty.items.allowableValues.containsKey(TwilioJavaGenerator.VALUES)); - return enumValues || listEnumValues; - } - - public static boolean isParameterSchemaEnumJava(CodegenParameter codegenParameter) { if(codegenParameter.isEnum) { return true; } @@ -75,13 +49,4 @@ public static boolean isParameterSchemaEnumJava(CodegenParameter codegenParamete && codegenParameter.items.allowableValues.containsKey(TwilioJavaGenerator.VALUES)); return enumValues || listEnumValues; } - - public static void mergeVendorExtensionProperty(Map vendorExtensions, LinkedHashMap value, String field ) { - if (value != null && !value.isEmpty()) { - if( vendorExtensions.containsKey(field)) - ((LinkedHashMap)vendorExtensions.get(field)).putAll(value); - else - vendorExtensions.put(field, value); - } - } -} +} \ No newline at end of file From c9f611f04a5e37d37a0fe4e14566df13a2d6e0e1 Mon Sep 17 00:00:00 2001 From: kridai Date: Wed, 11 Oct 2023 12:34:57 +0530 Subject: [PATCH 10/12] fix: restore codegenUtil --- src/main/java/com/twilio/oai/CodegenUtils.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/twilio/oai/CodegenUtils.java b/src/main/java/com/twilio/oai/CodegenUtils.java index 2b81d8fac..49ffeca26 100644 --- a/src/main/java/com/twilio/oai/CodegenUtils.java +++ b/src/main/java/com/twilio/oai/CodegenUtils.java @@ -1,10 +1,16 @@ package com.twilio.oai; +import java.util.LinkedHashMap; +import java.util.Map; import org.openapitools.codegen.CodegenParameter; import org.openapitools.codegen.CodegenProperty; public class CodegenUtils { + private CodegenUtils() { + + } + public static boolean isPropertySchemaEnum(CodegenProperty codegenProperty) { if(codegenProperty.isEnum) { return true; @@ -49,4 +55,13 @@ public static boolean isParameterSchemaEnumJava(CodegenParameter codegenParamete && codegenParameter.items.allowableValues.containsKey(TwilioJavaGenerator.VALUES)); return enumValues || listEnumValues; } + + public static void mergeVendorExtensionProperty(Map vendorExtensions, Map value, String field ) { + if (value != null && !value.isEmpty()) { + if( vendorExtensions.containsKey(field)) + ((LinkedHashMap)vendorExtensions.get(field)).putAll(value); + else + vendorExtensions.put(field, value); + } + } } \ No newline at end of file From e9240831e1620f7e1e743f3ff69812640b2b6474 Mon Sep 17 00:00:00 2001 From: Shubham Date: Thu, 2 Nov 2023 11:18:26 +0530 Subject: [PATCH 11/12] 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()) { From c84819355fc20651e48234b260cf2d77cb95b8a1 Mon Sep 17 00:00:00 2001 From: Shubham Date: Thu, 2 Nov 2023 11:21:10 +0530 Subject: [PATCH 12/12] chore:sync with main (#537) # Fixes # Syncing changes with main branch ### Checklist - [x] I acknowledge that all my contributions will be made under the project's license - [ ] Run `make test-docker` - [ ] Verify affected language: - [ ] Generate [twilio-go](https://github.com/twilio/twilio-go) from our [OpenAPI specification](https://github.com/twilio/twilio-oai) using the [build_twilio_go.py](./examples/build_twilio_go.py) using `python examples/build_twilio_go.py path/to/twilio-oai/spec/yaml path/to/twilio-go` and inspect the diff - [ ] Run `make test` in `twilio-go` - [ ] Create a pull request in `twilio-go` - [ ] Provide a link below to the pull request - [ ] I have made a material change to the repo (functionality, testing, spelling, grammar) - [ ] I have read the [Contribution Guidelines](https://github.com/twilio/twilio-oai-generator/blob/main/CONTRIBUTING.md) and my PR follows them - [ ] I have titled the PR appropriately - [ ] I have updated my branch with the main branch - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added the necessary documentation about the functionality in the appropriate .md file - [ ] I have added inline documentation to the code I modified If you have questions, please create a GitHub Issue in this repository. --------- Co-authored-by: sbansla <104902068+sbansla@users.noreply.github.com> Co-authored-by: Athira Sabu <102021496+AsabuHere@users.noreply.github.com>