From d3235c2b5631ea36c7992ce8b91c2cd234016687 Mon Sep 17 00:00:00 2001 From: chsingh Date: Thu, 30 Jun 2022 08:17:18 +0530 Subject: [PATCH 01/19] process enum schemas --- .../com/twilio/oai/TwilioJavaGenerator.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 849c35a82..2f2b8fae6 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -9,6 +9,7 @@ import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.PathItem; import lombok.AllArgsConstructor; +import org.commonmark.node.Code; import org.openapitools.codegen.*; import org.openapitools.codegen.languages.JavaClientCodegen; import org.openapitools.codegen.utils.StringUtils; @@ -208,10 +209,34 @@ public Map postProcessAllModels(final Map allMod .collect(Collectors.toCollection(() -> this.allModels)); } setObjectFormatMap(this.allModels); + setEnumProperties(this.allModels); // Return an empty collection so no model files get generated. return new HashMap<>(); } + private void setEnumProperties(List allModels) { + allModels.forEach(model -> { + model.vars.forEach(property -> { + allModels.forEach(enumModel -> { + if (property.items != null && property.items.allowableValues != null && property.items.allowableValues.containsKey("enumVars")) { + if (enumModel.getClassname().equals(property.items.getBaseType())) { + property.isEnum = true; + property.allowableValues = enumModel.allowableValues; + property._enum = (List) enumModel.allowableValues.get("values"); + } + } + if (property.allowableValues != null && property.allowableValues.containsKey("enumVars")) { + if (enumModel.getClassname().equals(property.getBaseType())) { + property.isEnum = true; + property.allowableValues = enumModel.allowableValues; + property._enum = (List) enumModel.allowableValues.get("values"); + } + } + }); + }); + }); + } + @Override public Map postProcessOperationsWithModels(final Map objs, @@ -653,6 +678,7 @@ private void updateCodeOperationParams(final CodegenOperation co) { .stream() .map(ConventionResolver::resolveParameter) .map(Optional::get) + .map(this::resolveEnumParameter) .collect(Collectors.toList()); co.pathParams = co.pathParams .stream() @@ -695,6 +721,28 @@ private List preProcessFormParams(CodegenOperation co) { return co.formParams; } + private CodegenParameter resolveEnumParameter(CodegenParameter parameter) { + allModels.forEach(model -> { + if (parameter.items != null && parameter.items.allowableValues != null && parameter.items.allowableValues.containsKey("enumVars")) { + if (model.getClassname().equals(parameter.baseName)) { + parameter.isEnum = true; + parameter.allowableValues = model.allowableValues; + parameter._enum = (List) model.allowableValues.get("values"); + + } + } + if (parameter.allowableValues != null && parameter.allowableValues.containsKey("enumVars")) { + if (model.getClassname().equals(parameter.baseName)) { + parameter.isEnum = true; + parameter.allowableValues = model.allowableValues; + parameter._enum = (List) model.allowableValues.get("values"); + + } + } + }); + return parameter; + } + @Override public String getName() { return "twilio-java"; From 49559f77adc734adc5c2b3c6194ad45a6bd115cc Mon Sep 17 00:00:00 2001 From: chsingh Date: Thu, 30 Jun 2022 17:14:13 +0530 Subject: [PATCH 02/19] fix enum dataType --- .../com/twilio/oai/TwilioJavaGenerator.java | 82 +++++++++---------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 2f2b8fae6..e2baa80be 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -217,27 +217,19 @@ public Map postProcessAllModels(final Map allMod private void setEnumProperties(List allModels) { allModels.forEach(model -> { model.vars.forEach(property -> { - allModels.forEach(enumModel -> { - if (property.items != null && property.items.allowableValues != null && property.items.allowableValues.containsKey("enumVars")) { - if (enumModel.getClassname().equals(property.items.getBaseType())) { - property.isEnum = true; - property.allowableValues = enumModel.allowableValues; - property._enum = (List) enumModel.allowableValues.get("values"); - } - } - if (property.allowableValues != null && property.allowableValues.containsKey("enumVars")) { - if (enumModel.getClassname().equals(property.getBaseType())) { - property.isEnum = true; - property.allowableValues = enumModel.allowableValues; - property._enum = (List) enumModel.allowableValues.get("values"); - } - } - }); + if (property.items != null && property.items.allowableValues != null && property.items.allowableValues.containsKey("enumVars")) { + property.isEnum = true; + property.allowableValues = property.items.allowableValues; + property._enum = (List) property.items.allowableValues.get("values"); + } + if (property.allowableValues != null && property.allowableValues.containsKey("enumVars")) { + property.isEnum = true; + property._enum = (List) property.allowableValues.get("values"); + } }); }); } - @Override public Map postProcessOperationsWithModels(final Map objs, final List allModels) { @@ -265,7 +257,7 @@ public Map postProcessOperationsWithModels(final Map resource = resources.computeIfAbsent(resourceName, k -> new LinkedHashMap<>()); populateCrudOperations(resource, co); - updateCodeOperationParams(co); + updateCodeOperationParams(co, resourceName); if (co.nickname.startsWith("update")) { resource.put("hasUpdate", true); addOperationName(co, "Update"); @@ -306,7 +298,6 @@ public Map postProcessOperationsWithModels(final Map postProcessOperationsWithModels(final Map ConventionResolver.resolveComplexType(item, modelFormatMap)) .flatMap(Optional::stream) .forEach(model -> { - resource.put("serialVersionUID", calculateSerialVersionUid(model.vars)); responseModels.add(model); processEnumVarsForAll(responseModels, co, model, resourceName); @@ -370,8 +360,14 @@ private void processEnumVarsForAll(List responseModels, CodegenOpe model.vars.forEach(item -> { if(item.isEnum){ - item.dataType = generateDataType(resourceName, item.nameInCamelCase); - + //item.dataType = generateDataType(resourceName, item.nameInCamelCase); + if (item.containerType != null && item.containerType.equals("array")) { + item.baseName = item.complexType; + item.dataType = "List<"+resourceName +"." + item.complexType+">"; + } else { + item.baseName = item.dataType; + item.dataType = resourceName + "." + item.dataType; + } item.vendorExtensions.put("x-is-other-data-type", true); } @@ -673,41 +669,48 @@ public static String capitalize(String str) { return str.substring(0, 1).toUpperCase() + str.substring(1); } - private void updateCodeOperationParams(final CodegenOperation co) { + private void updateCodeOperationParams(final CodegenOperation co, String resourceName) { co.allParams = co.allParams .stream() .map(ConventionResolver::resolveParameter) .map(Optional::get) - .map(this::resolveEnumParameter) + .map(item -> this.resolveEnumParameter(item, resourceName)) .collect(Collectors.toList()); co.pathParams = co.pathParams .stream() .map(ConventionResolver::resolveParameter) .map(Optional::get) + .map(item -> this.resolveEnumParameter(item, resourceName)) .collect(Collectors.toList()); co.pathParams.stream(). map(ConventionResolver::resolveParamTypes) + .map(item -> this.resolveEnumParameter(item, resourceName)) .forEach(param -> param.paramName = "path"+param.paramName); co.queryParams = co.queryParams.stream().map(ConventionResolver::resolveParamTypes) .map(ConventionResolver::prefixedCollapsibleMap) + .map(item -> this.resolveEnumParameter(item, resourceName)) .collect(Collectors.toList()); co.queryParams = preProcessQueryParameters(co); co.formParams = co.formParams.stream().map(ConventionResolver::resolveParamTypes) .map(ConventionResolver::prefixedCollapsibleMap) + .map(item -> this.resolveEnumParameter(item, resourceName)) .collect(Collectors.toList()); co.formParams = preProcessFormParams(co); co.headerParams = co.headerParams.stream().map(ConventionResolver::resolveParamTypes) .map(ConventionResolver::prefixedCollapsibleMap) + .map(item -> this.resolveEnumParameter(item, resourceName)) .collect(Collectors.toList()); co.optionalParams = co.optionalParams .stream() .map(ConventionResolver::resolveParameter) .map(Optional::get) + .map(item -> this.resolveEnumParameter(item, resourceName)) .collect(Collectors.toList()); co.requiredParams = co.requiredParams .stream() .map(ConventionResolver::resolveParameter) .map(Optional::get) + .map(item -> this.resolveEnumParameter(item, resourceName)) .collect(Collectors.toList()); } @@ -721,25 +724,18 @@ private List preProcessFormParams(CodegenOperation co) { return co.formParams; } - private CodegenParameter resolveEnumParameter(CodegenParameter parameter) { - allModels.forEach(model -> { - if (parameter.items != null && parameter.items.allowableValues != null && parameter.items.allowableValues.containsKey("enumVars")) { - if (model.getClassname().equals(parameter.baseName)) { - parameter.isEnum = true; - parameter.allowableValues = model.allowableValues; - parameter._enum = (List) model.allowableValues.get("values"); - - } - } - if (parameter.allowableValues != null && parameter.allowableValues.containsKey("enumVars")) { - if (model.getClassname().equals(parameter.baseName)) { - parameter.isEnum = true; - parameter.allowableValues = model.allowableValues; - parameter._enum = (List) model.allowableValues.get("values"); - - } - } - }); + private CodegenParameter resolveEnumParameter(CodegenParameter parameter, String resourceName) { + if (parameter.items != null && parameter.items.allowableValues != null && parameter.items.allowableValues.containsKey("enumVars")) { + parameter.isEnum = true; + parameter._enum = (List) parameter.items.allowableValues.get("values"); + parameter.dataType=resourceName+"."+parameter.items.dataType; + } + if (parameter.allowableValues != null && parameter.allowableValues.containsKey("enumVars")) { + parameter.isEnum = true; + parameter._enum = (List) parameter.allowableValues.get("values"); + parameter.baseName = parameter.dataType; + parameter.dataType=resourceName+"."+parameter.dataType; + } return parameter; } From baff4e1864e6498d47bbaf7d47c45339048950fe Mon Sep 17 00:00:00 2001 From: twilio-dx Date: Fri, 1 Jul 2022 13:07:13 +0530 Subject: [PATCH 03/19] fix(): enum fix changes --- .../com/twilio/oai/TwilioJavaGenerator.java | 28 +++++--- .../oai/mlambdas/ReplaceHyphenLambda.java | 70 +++++++++++++++++++ .../twilio-java/responseModel.mustache | 6 +- 3 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/twilio/oai/mlambdas/ReplaceHyphenLambda.java diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index e2baa80be..83df3aa87 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Lists; +import com.samskivert.mustache.Mustache; +import com.twilio.oai.mlambdas.ReplaceHyphenLambda; import com.twilio.oai.resource.IResourceTree; import com.twilio.oai.resource.ResourceMap; import io.swagger.v3.oas.models.OpenAPI; @@ -12,6 +14,7 @@ import org.commonmark.node.Code; import org.openapitools.codegen.*; import org.openapitools.codegen.languages.JavaClientCodegen; +import org.openapitools.codegen.templating.mustache.*; import org.openapitools.codegen.utils.StringUtils; import java.util.*; @@ -21,6 +24,8 @@ import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import com.google.common.collect.ImmutableMap; +import com.samskivert.mustache.Mustache.Lambda; public class TwilioJavaGenerator extends JavaClientCodegen { @@ -217,7 +222,7 @@ public Map postProcessAllModels(final Map allMod private void setEnumProperties(List allModels) { allModels.forEach(model -> { model.vars.forEach(property -> { - if (property.items != null && property.items.allowableValues != null && property.items.allowableValues.containsKey("enumVars")) { + if (property.items != null && property.items.allowableValues != null && property.items.allowableValues.containsKey("values")) { property.isEnum = true; property.allowableValues = property.items.allowableValues; property._enum = (List) property.items.allowableValues.get("values"); @@ -359,7 +364,7 @@ private void processEnumVarsForAll(List responseModels, CodegenOpe } model.vars.forEach(item -> { - if(item.isEnum){ + if(item.isEnum && !item.dataType.contains(resourceName+ ".")){ //item.dataType = generateDataType(resourceName, item.nameInCamelCase); if (item.containerType != null && item.containerType.equals("array")) { item.baseName = item.complexType; @@ -371,13 +376,7 @@ private void processEnumVarsForAll(List responseModels, CodegenOpe item.vendorExtensions.put("x-is-other-data-type", true); } - }); - co.queryParams.forEach(param -> processEnumVars(param, model, resourceName)); - co.formParams.forEach(param -> processEnumVars(param, model, resourceName)); - co.allParams.forEach(param -> processEnumVars(param, model, resourceName)); - co.headerParams.forEach(param -> processEnumVars(param, model, resourceName)); - co.requiredParams.forEach(param -> processEnumVars(param, model, resourceName)); } private CodegenProperty createCodeGenPropertyFromParameter(CodegenParameter co) { @@ -724,11 +723,20 @@ private List preProcessFormParams(CodegenOperation co) { return co.formParams; } + @Override + protected ImmutableMap.Builder addMustacheLambdas() { + ImmutableMap.Builder lambdaBuilder = super.addMustacheLambdas(); + lambdaBuilder.put("replacehyphen", new ReplaceHyphenLambda()); + return lambdaBuilder; + } + private CodegenParameter resolveEnumParameter(CodegenParameter parameter, String resourceName) { - if (parameter.items != null && parameter.items.allowableValues != null && parameter.items.allowableValues.containsKey("enumVars")) { + if (parameter.items != null && parameter.items.allowableValues != null && parameter.items.allowableValues.containsKey("values")) { parameter.isEnum = true; + parameter.baseName = parameter.baseType; parameter._enum = (List) parameter.items.allowableValues.get("values"); - parameter.dataType=resourceName+"."+parameter.items.dataType; + parameter.dataType = "List<" + resourceName + "." + parameter.items.complexType + ">"; + parameter.allowableValues = parameter.items.allowableValues; } if (parameter.allowableValues != null && parameter.allowableValues.containsKey("enumVars")) { parameter.isEnum = true; diff --git a/src/main/java/com/twilio/oai/mlambdas/ReplaceHyphenLambda.java b/src/main/java/com/twilio/oai/mlambdas/ReplaceHyphenLambda.java new file mode 100644 index 000000000..ee5075fa8 --- /dev/null +++ b/src/main/java/com/twilio/oai/mlambdas/ReplaceHyphenLambda.java @@ -0,0 +1,70 @@ +package com.twilio.oai.mlambdas; + + +import com.samskivert.mustache.Mustache; +import com.samskivert.mustache.Template; + +import java.io.IOException; +import java.io.Writer; +import java.util.Locale; + +/** + * Converts text in a fragment to title case. + * + * Register: + *
+ * additionalProperties.put("titlecase", new TitlecaseLambda());
+ * 
+ * + * Use: + *
+ * {{#titlecase}}{{classname}}{{/titlecase}}
+ * 
+ */ +public class ReplaceHyphenLambda implements Mustache.Lambda { + private String delimiter; + + /** + * Constructs a new instance of {@link org.openapitools.codegen.templating.mustache.TitlecaseLambda}, which will convert all text + * in a space delimited string to title-case. + */ + public ReplaceHyphenLambda() { + this(" "); + } + + /** + * Constructs a new instance of {@link org.openapitools.codegen.templating.mustache.TitlecaseLambda}, splitting on the specified + * delimiter and converting each word to title-case. + * + * NOTE: passing {@code null} results in a title-casing the first word only. + * + * @param delimiter Provided to allow an override for the default space delimiter. + */ + public ReplaceHyphenLambda(String delimiter) { + this.delimiter = delimiter; + } + + private String titleCase(final String input) { + return input.replaceAll("-","_"); + } + + @Override + public void execute(Template.Fragment fragment, Writer writer) throws IOException { + String text = fragment.execute(); + if (delimiter == null) { + writer.write(titleCase(text)); + return; + } + + // Split accepts regex. \Q and \E wrap the delimiter to create a literal regex, + // so things like "." and "|" aren't treated as their regex equivalents. + String[] parts = text.split("\\Q" + delimiter + "\\E"); + for (int i = 0; i < parts.length; i++) { + String part = parts[i]; + writer.write(titleCase(part)); + if (i != parts.length - 1) { + writer.write(delimiter); + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/twilio-java/responseModel.mustache b/src/main/resources/twilio-java/responseModel.mustache index fae339875..bb21ae4c3 100644 --- a/src/main/resources/twilio-java/responseModel.mustache +++ b/src/main/resources/twilio-java/responseModel.mustache @@ -3,9 +3,9 @@ {{#isEnum}} public enum {{#lambda.titlecase}}{{{baseName}}}{{/lambda.titlecase}} { {{#allowableValues}} - {{#enumVars}} - {{#lambda.uppercase}}{{{name}}}({{/lambda.uppercase}}{{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} - {{/enumVars}} + {{#values}} + {{#lambda.uppercase}}{{#lambda.replacehyphen}}{{{.}}}{{/lambda.replacehyphen}}({{/lambda.uppercase}}"{{{.}}}"){{^-last}},{{/-last}}{{#-last}};{{/-last}} + {{/values}} {{/allowableValues}} private final String value; From 27c478ba12925dc404f3b932f641836504d8bf8d Mon Sep 17 00:00:00 2001 From: twilio-dx Date: Fri, 1 Jul 2022 18:57:36 +0530 Subject: [PATCH 04/19] fix(): added enum changes --- src/main/java/com/twilio/oai/TwilioJavaGenerator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 83df3aa87..c94d27ee9 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -124,7 +124,8 @@ public String toParamName(String name) { @Override public void postProcessParameter(final CodegenParameter parameter) { super.postProcessParameter(parameter); - + String[] value = parameter.dataType.split("Enum"); + parameter.dataType = value[value.length-1]; // Make sure required non-path params get into the options block. parameter.paramName = StringUtils.camelize(parameter.paramName, false); } @@ -132,6 +133,8 @@ public void postProcessParameter(final CodegenParameter parameter) { @Override public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { super.postProcessModelProperty(model, property); + String[] value = property.dataType.split("Enum"); + property.dataType = value[value.length-1]; property.isEnum = property.isEnum && property.dataFormat == null; } @@ -355,7 +358,7 @@ public Map postProcessOperationsWithModels(final Map responseModels, CodegenOperation co, CodegenModel model, String resourceName) { for (CodegenParameter param : co.allParams) { if(param.isEnum){ - Optional alreadyExisting = model.vars.stream().filter(item -> item.name.equalsIgnoreCase(param.paramName)).findFirst(); + Optional alreadyExisting = model.vars.stream().filter(item -> item.name.equalsIgnoreCase(param.baseName) && item.dataType.equals(param.dataType)).findFirst(); if(!alreadyExisting.isPresent()){ responseModels.get(0).vars.add(createCodeGenPropertyFromParameter(param)); model.vars.add(createCodeGenPropertyFromParameter(param)); From 24395882dc9487ffa12c9e96226cab9ba95b60b0 Mon Sep 17 00:00:00 2001 From: chsingh Date: Mon, 4 Jul 2022 09:44:41 +0530 Subject: [PATCH 05/19] fix: enum types --- .../com/twilio/oai/TwilioJavaGenerator.java | 144 +++++++++++------- .../twilio-java/responseModel.mustache | 4 +- twilio-openapi-generator.iml | 87 +++++++++++ 3 files changed, 174 insertions(+), 61 deletions(-) create mode 100644 twilio-openapi-generator.iml diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index c94d27ee9..18724653c 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -124,8 +124,16 @@ public String toParamName(String name) { @Override public void postProcessParameter(final CodegenParameter parameter) { super.postProcessParameter(parameter); - String[] value = parameter.dataType.split("Enum"); - parameter.dataType = value[value.length-1]; + if (parameter.dataType.startsWith("List<") && parameter.dataType.contains("Enum")) { + String[] value = parameter.dataType.split("Enum"); + String lastValue = value[value.length-1]; + parameter.dataType = "List<"+lastValue; + parameter.baseType = lastValue.substring(0, lastValue.length()-1); + } else if(parameter.dataType.contains("Enum")) { + String[] value = parameter.dataType.split("Enum"); + parameter.dataType = value[value.length-1]; + parameter.baseType = value[value.length-1]; + } // Make sure required non-path params get into the options block. parameter.paramName = StringUtils.camelize(parameter.paramName, false); } @@ -133,8 +141,18 @@ public void postProcessParameter(final CodegenParameter parameter) { @Override public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { super.postProcessModelProperty(model, property); - String[] value = property.dataType.split("Enum"); - property.dataType = value[value.length-1]; + if (property.dataType.startsWith("List<") && property.dataType.contains("Enum")) { + String[] value = property.dataType.split("Enum"); + String lastValue = value[value.length-1]; + property.dataType = "List<" + lastValue; + property.complexType = lastValue.substring(0, lastValue.length()-1); + property.baseType = lastValue.substring(0, lastValue.length()-1); + } else if (property.dataType.contains("Enum")){ + String[] value = property.dataType.split("Enum"); + property.dataType = value[value.length-1]; + property.complexType = property.dataType; + property.baseType = property.dataType; + } property.isEnum = property.isEnum && property.dataFormat == null; } @@ -329,9 +347,8 @@ public Map postProcessOperationsWithModels(final Map { resource.put("serialVersionUID", calculateSerialVersionUid(model.vars)); - responseModels.add(model); - processEnumVarsForAll(responseModels, co, model, resourceName); - + CodegenModel responseModel = processEnumVarsForAll(model, co, resourceName); + responseModels.add(responseModel); }); results.put("recordKey", getRecordKey(opList, this.allModels)); @@ -355,31 +372,50 @@ public Map postProcessOperationsWithModels(final Map responseModels, CodegenOperation co, CodegenModel model, String resourceName) { - for (CodegenParameter param : co.allParams) { - if(param.isEnum){ - Optional alreadyExisting = model.vars.stream().filter(item -> item.name.equalsIgnoreCase(param.baseName) && item.dataType.equals(param.dataType)).findFirst(); - if(!alreadyExisting.isPresent()){ - responseModels.get(0).vars.add(createCodeGenPropertyFromParameter(param)); - model.vars.add(createCodeGenPropertyFromParameter(param)); - } - } - } - + private CodegenModel processEnumVarsForAll(CodegenModel model, CodegenOperation co, String resourceName) { + List enumProperties = new ArrayList<>(); model.vars.forEach(item -> { - if(item.isEnum && !item.dataType.contains(resourceName+ ".")){ - //item.dataType = generateDataType(resourceName, item.nameInCamelCase); + if (item.isEnum && item.dataFormat == null && !item.dataType.contains(resourceName+ ".")) { if (item.containerType != null && item.containerType.equals("array")) { - item.baseName = item.complexType; + item.baseName = item.baseType; item.dataType = "List<"+resourceName +"." + item.complexType+">"; } else { - item.baseName = item.dataType; + item.baseName = item.baseType; item.dataType = resourceName + "." + item.dataType; } item.vendorExtensions.put("x-is-other-data-type", true); - } }); + for (CodegenProperty codegenProperty: model.vars) { + if (codegenProperty.isEnum && codegenProperty.dataFormat == null) { + enumProperties.add(codegenProperty); + } + } + for (CodegenParameter param : co.allParams) { + if (param.isEnum) { + Optional alreadyAdded = enumProperties.stream(). + filter(item -> item.baseName.equalsIgnoreCase(param.baseName)).findFirst(); + if (!alreadyAdded.isPresent() && param.dataFormat == null) { + enumProperties.add(createCodeGenPropertyFromParameter(param)); + } + } + } + if (model.getVendorExtensions().get("enumVars") != null) { + List codegenProperties = (List) model.getVendorExtensions().get("enumVars"); + TreeSet ts = new TreeSet(new Comparator() { + public int compare(CodegenProperty cp1,CodegenProperty cp2) + { + return cp1.baseName.compareTo(cp2.getBaseName()); + } + }); + ts.addAll(enumProperties); + ts.addAll(codegenProperties); + model.vendorExtensions.put("enumVars",new ArrayList<>(ts)); + } else { + model.vendorExtensions.put("enumVars", enumProperties); + } + + return model; } private CodegenProperty createCodeGenPropertyFromParameter(CodegenParameter co) { @@ -391,8 +427,6 @@ private CodegenProperty createCodeGenPropertyFromParameter(CodegenParameter co) property.vendorExtensions = co.vendorExtensions; property.datatypeWithEnum = co.datatypeWithEnum; property.complexType = co.getComplexType(); - - property.name = co.paramName; property.nameInCamelCase = co.baseName.replaceAll("-",""); property.nameInSnakeCase = co.baseName.replaceAll("-","_").toLowerCase(); @@ -417,6 +451,31 @@ private CodegenModel getConcatenatedResponseModel(List responseMod resModel.allowableValues.forEach( (key, value) -> codegenModel.allowableValues.merge(key, value, (oldValue, newValue) -> newValue)); } + if (resModel.vendorExtensions != null && resModel.vendorExtensions.size() > 0) { + List resEnum1 = (List)resModel.vendorExtensions.get("enumVars"); + List codeModelEnums = (List)codegenModel.vendorExtensions.get("enumVars"); + if (codeModelEnums != null) { + for (CodegenProperty resCodegenProperty: resEnum1) { + boolean found = false; + for (CodegenProperty codeEnumProperty: codeModelEnums) { + if (codeEnumProperty.baseName.equals(resCodegenProperty.getBaseName())) { + found = true; + } + } + if (!found) { + codeModelEnums.add(resCodegenProperty); + } + } + resModel.vendorExtensions.forEach( + (key, value) -> codegenModel.vendorExtensions.merge(key, value, (oldValue, newValue) -> newValue)); + resModel.vendorExtensions.put("enumVars", codeModelEnums); + } else { + resModel.vendorExtensions.forEach( + (key, value) -> codegenModel.vendorExtensions.merge(key, value, (oldValue, newValue) -> newValue)); + + } + } + for (CodegenProperty modelProp : resModel.vars) { boolean contains = false; for (CodegenProperty property : codegenProperties) { @@ -450,39 +509,6 @@ private Optional getModelCoPath(final String modelName, CodegenOpe return allModels.stream().filter(model -> model.getClassname().equals(modelName)).findFirst(); } - private String generateDataType(String resourceName, String nameInCamelCase){ - String name = nameInCamelCase; - String dataType = ""; - String nameArr[] = name.split("[.]", 0); - if(nameArr.length > 0){ - String itemName = String.join("", nameArr); - dataType = resourceName + "." + itemName; - } - else{ - dataType = resourceName + "." + name; - } - return dataType; - } - - private CodegenParameter processEnumVars(CodegenParameter param, CodegenModel model, String resourceName) { - if(param.isEnum){ - model.vars.forEach(item -> { - if(param.paramName.equalsIgnoreCase(item.nameInCamelCase) && item.isEnum == true){ - String baseType = generateDataType(resourceName, item.nameInCamelCase); - if(param.isArray){ - param.dataType = "List<"+ baseType +">"; - param.baseType = baseType; - } - else{ - param.dataType = baseType; - } - param.vendorExtensions.put("x-is-other-data-type", true); - } - }); - } - return param; - } - private String getRecordKey(List opList, List models) { String recordKey = ""; for (CodegenOperation co: opList) { @@ -738,7 +764,7 @@ private CodegenParameter resolveEnumParameter(CodegenParameter parameter, String parameter.isEnum = true; parameter.baseName = parameter.baseType; parameter._enum = (List) parameter.items.allowableValues.get("values"); - parameter.dataType = "List<" + resourceName + "." + parameter.items.complexType + ">"; + parameter.dataType = "List<" + resourceName + "." + parameter.baseType + ">"; parameter.allowableValues = parameter.items.allowableValues; } if (parameter.allowableValues != null && parameter.allowableValues.containsKey("enumVars")) { diff --git a/src/main/resources/twilio-java/responseModel.mustache b/src/main/resources/twilio-java/responseModel.mustache index bb21ae4c3..03587dd5a 100644 --- a/src/main/resources/twilio-java/responseModel.mustache +++ b/src/main/resources/twilio-java/responseModel.mustache @@ -1,5 +1,5 @@ {{#responseModel}} -{{#vars}} +{{#vendorExtensions.enumVars}} {{#isEnum}} public enum {{#lambda.titlecase}}{{{baseName}}}{{/lambda.titlecase}} { {{#allowableValues}} @@ -24,7 +24,7 @@ } } {{/isEnum}} -{{/vars}} +{{/vendorExtensions.enumVars}} {{#vars}} private final {{{dataType}}} {{name}}; diff --git a/twilio-openapi-generator.iml b/twilio-openapi-generator.iml new file mode 100644 index 000000000..1e139e962 --- /dev/null +++ b/twilio-openapi-generator.iml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 1324258ab383e2c7e960484f7097f6cbde290089 Mon Sep 17 00:00:00 2001 From: twilio-dx Date: Mon, 4 Jul 2022 13:28:40 +0530 Subject: [PATCH 06/19] fix(): fixing enum issue --- src/main/java/com/twilio/oai/TwilioJavaGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 18724653c..0c3e08c2f 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -765,6 +765,7 @@ private CodegenParameter resolveEnumParameter(CodegenParameter parameter, String parameter.baseName = parameter.baseType; parameter._enum = (List) parameter.items.allowableValues.get("values"); parameter.dataType = "List<" + resourceName + "." + parameter.baseType + ">"; + parameter.baseType = resourceName + "." + parameter.baseType; parameter.allowableValues = parameter.items.allowableValues; } if (parameter.allowableValues != null && parameter.allowableValues.containsKey("enumVars")) { From d98278b0adcdaa09d9432212f09de02a3d72709e Mon Sep 17 00:00:00 2001 From: kridai Date: Mon, 4 Jul 2022 16:30:23 +0530 Subject: [PATCH 07/19] fix(): removing iml file --- twilio-openapi-generator.iml | 87 ------------------------------------ 1 file changed, 87 deletions(-) delete mode 100644 twilio-openapi-generator.iml diff --git a/twilio-openapi-generator.iml b/twilio-openapi-generator.iml deleted file mode 100644 index 1e139e962..000000000 --- a/twilio-openapi-generator.iml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 5bc74c2d1297ab978fee0867f5908b6473ca2d88 Mon Sep 17 00:00:00 2001 From: chsingh Date: Tue, 5 Jul 2022 14:32:12 +0530 Subject: [PATCH 08/19] fix delete header param enums --- .../com/twilio/oai/TwilioJavaGenerator.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 0c3e08c2f..398f1571c 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -296,6 +296,7 @@ public Map postProcessOperationsWithModels(final Map postProcessOperationsWithModels(final Map responseModels) { + List codegenProperties = new ArrayList<>(); + for (CodegenParameter cp: co.allParams) { + if (cp.isEnum && cp.isHeaderParam) { + codegenProperties.add(createCodeGenPropertyFromParameter(cp)); + } + } + if (codegenProperties.size() > 0) { + CodegenModel codegenModel = new CodegenModel(); + codegenModel.vendorExtensions.put("enumVars", codegenProperties); + responseModels.add(codegenModel); + } + } + private CodegenModel processEnumVarsForAll(CodegenModel model, CodegenOperation co, String resourceName) { List enumProperties = new ArrayList<>(); model.vars.forEach(item -> { @@ -466,14 +481,10 @@ private CodegenModel getConcatenatedResponseModel(List responseMod codeModelEnums.add(resCodegenProperty); } } - resModel.vendorExtensions.forEach( - (key, value) -> codegenModel.vendorExtensions.merge(key, value, (oldValue, newValue) -> newValue)); resModel.vendorExtensions.put("enumVars", codeModelEnums); - } else { - resModel.vendorExtensions.forEach( - (key, value) -> codegenModel.vendorExtensions.merge(key, value, (oldValue, newValue) -> newValue)); - } + resModel.vendorExtensions.forEach( + (key, value) -> codegenModel.vendorExtensions.merge(key, value, (oldValue, newValue) -> newValue)); } for (CodegenProperty modelProp : resModel.vars) { @@ -772,7 +783,7 @@ private CodegenParameter resolveEnumParameter(CodegenParameter parameter, String parameter.isEnum = true; parameter._enum = (List) parameter.allowableValues.get("values"); parameter.baseName = parameter.dataType; - parameter.dataType=resourceName+"."+parameter.dataType; + parameter.dataType=resourceName + "." + parameter.dataType; } return parameter; } From 5a3652f37b186680447f6f2dff28fcdebc33d017 Mon Sep 17 00:00:00 2001 From: sburman Date: Tue, 5 Jul 2022 16:24:58 +0530 Subject: [PATCH 09/19] changes for handling preview --- .../java/com/twilio/oai/TwilioJavaGenerator.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 0c3e08c2f..e79f1359a 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -63,9 +63,15 @@ public TwilioJavaGenerator() { public void processOpts() { super.processOpts(); String[] inputSpecs = inputSpec.split("_"); - final String version = inputSpecs[inputSpecs.length-1].replaceAll("\\.[^/]+$", ""); - final String domain = String.join("", Arrays.copyOfRange(inputSpecs, 1, inputSpecs.length-1)); - apiPackage = version; // Place the API files in the version folder. + String version = inputSpecs[inputSpecs.length-1].replaceAll("\\.[^/]+$", ""); + String domain = String.join("", Arrays.copyOfRange(inputSpecs, 1, inputSpecs.length-1)); + + if(inputSpecs.length <3){ // version is missing + version = ""; + domain = inputSpecs[inputSpecs.length-1].replaceAll("\\.[^/]+$", ""); + } + + apiPackage = (version != "")? version : domain ; // Place the API files in the version folder. additionalProperties.put("apiVersion", version); additionalProperties.put("apiVersionClass", version.toUpperCase()); additionalProperties.put("domain", StringUtils.camelize(domain)); From 16353bb0150ea7fc5f1ae11c47929d54a98b77a0 Mon Sep 17 00:00:00 2001 From: twilio-dx Date: Tue, 5 Jul 2022 18:38:25 +0530 Subject: [PATCH 10/19] fix(): fixing failing test issues --- .../com/twilio/oai/ConventionResolver.java | 7 ++ src/main/java/com/twilio/oai/Inflector.java | 1 + .../com/twilio/oai/TwilioJavaGenerator.java | 88 +++++++++---------- src/main/resources/twilio-java/api.mustache | 1 + .../resources/twilio-java/creator.mustache | 12 +-- .../resources/twilio-java/deleter.mustache | 12 +-- .../resources/twilio-java/fetcher.mustache | 12 +-- .../twilio-java/generate_uri.mustache | 15 ++++ .../twilio-java/headerParams.mustache | 6 ++ .../resources/twilio-java/postParams.mustache | 4 +- .../twilio-java/responseModel.mustache | 8 +- .../resources/twilio-java/updater.mustache | 12 +-- 12 files changed, 82 insertions(+), 96 deletions(-) create mode 100644 src/main/resources/twilio-java/generate_uri.mustache diff --git a/src/main/java/com/twilio/oai/ConventionResolver.java b/src/main/java/com/twilio/oai/ConventionResolver.java index 95bc628cb..e913cb78a 100644 --- a/src/main/java/com/twilio/oai/ConventionResolver.java +++ b/src/main/java/com/twilio/oai/ConventionResolver.java @@ -17,6 +17,10 @@ public class ConventionResolver { final static String HYPHEN = "-"; public static final String OBJECT = "object"; + public static final String PHONE_NUMBER_FORMAT = "phone-number"; + + final static String X_IS_PHONE_NUMBER_FORMAT = "x-is-phone-number-format"; + public static Optional resolve(Optional model) { for (CodegenProperty property : model.get().vars) { Map> vendorExtensions = new HashMap<>(); @@ -53,6 +57,9 @@ public static Optional resolveParameter(CodegenParameter param if (hasProperty) { parameter.dataType = (String)conventionMap.get(Segments.SEGMENT_PROPERTIES.getSegment()).get(parameter.dataFormat); } + if( PHONE_NUMBER_FORMAT.equals(parameter.dataFormat)) { + parameter.vendorExtensions.put(X_IS_PHONE_NUMBER_FORMAT, true); + } parameter.paramName = StringUtils.camelize(parameter.paramName, true); return Optional.of(parameter); } diff --git a/src/main/java/com/twilio/oai/Inflector.java b/src/main/java/com/twilio/oai/Inflector.java index 9a02014e1..61faa6984 100644 --- a/src/main/java/com/twilio/oai/Inflector.java +++ b/src/main/java/com/twilio/oai/Inflector.java @@ -115,6 +115,7 @@ public void initWildCardMapping() { wildCardMapping.put("BuildStatus", "BuildStatus"); wildCardMapping.put("Activities", "Activity"); wildCardMapping.put("Entities", "Entity"); + wildCardMapping.put("ESimProfiles", "EsimProfile"); } } } diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index c82431845..3b7dc5f94 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -273,7 +273,6 @@ public Map postProcessOperationsWithModels(final Map opList = (ArrayList) ops.get("operation"); String recordKey = getRecordKey(opList, this.allModels); List responseModels = new ArrayList(); - boolean isVersionV2010 = objs.get("package").equals("v2010"); apiTemplateFiles.remove("updater.mustache"); apiTemplateFiles.remove("creator.mustache"); apiTemplateFiles.remove("deleter.mustache"); @@ -284,7 +283,6 @@ public Map postProcessOperationsWithModels(final Map resource = resources.computeIfAbsent(resourceName, k -> new LinkedHashMap<>()); @@ -294,24 +292,24 @@ public Map postProcessOperationsWithModels(final Map postProcessOperationsWithModels(final Map { if (item.isEnum && item.dataFormat == null && !item.dataType.contains(resourceName+ ".")) { if (item.containerType != null && item.containerType.equals("array")) { - item.baseName = item.baseType; + item.enumName = item.baseType; item.dataType = "List<"+resourceName +"." + item.complexType+">"; } else { - item.baseName = item.baseType; + item.enumName = item.baseType; item.dataType = resourceName + "." + item.dataType; } item.vendorExtensions.put("x-is-other-data-type", true); @@ -415,7 +413,7 @@ private CodegenModel processEnumVarsForAll(CodegenModel model, CodegenOperation for (CodegenParameter param : co.allParams) { if (param.isEnum) { Optional alreadyAdded = enumProperties.stream(). - filter(item -> item.baseName.equalsIgnoreCase(param.baseName)).findFirst(); + filter(item -> item.enumName.equalsIgnoreCase(param.enumName)).findFirst(); if (!alreadyAdded.isPresent() && param.dataFormat == null) { enumProperties.add(createCodeGenPropertyFromParameter(param)); } @@ -426,7 +424,7 @@ private CodegenModel processEnumVarsForAll(CodegenModel model, CodegenOperation TreeSet ts = new TreeSet(new Comparator() { public int compare(CodegenProperty cp1,CodegenProperty cp2) { - return cp1.baseName.compareTo(cp2.getBaseName()); + return cp1.enumName.compareTo(cp2.getEnumName()); } }); ts.addAll(enumProperties); @@ -443,6 +441,7 @@ private CodegenProperty createCodeGenPropertyFromParameter(CodegenParameter co) CodegenProperty property = new CodegenProperty(); property.isEnum = co.isEnum; property.baseName = co.baseName; + property.enumName = co.enumName; property.allowableValues = co.allowableValues; property.dataType = co.dataType; property.vendorExtensions = co.vendorExtensions; @@ -479,7 +478,7 @@ private CodegenModel getConcatenatedResponseModel(List responseMod for (CodegenProperty resCodegenProperty: resEnum1) { boolean found = false; for (CodegenProperty codeEnumProperty: codeModelEnums) { - if (codeEnumProperty.baseName.equals(resCodegenProperty.getBaseName())) { + if (codeEnumProperty.enumName.equals(resCodegenProperty.getEnumName())) { found = true; } } @@ -555,41 +554,38 @@ private enum Operation { * keep track of signature list that would contain different combinations of signatures for constructor generation (since Account sid is optional, so different constructor are needed) * @param resource * @param co - * @param isVersionV2010 * @return */ - private ArrayList> generateSignatureList(final Map resource, final CodegenOperation co, boolean isVersionV2010) { + private ArrayList> generateSignatureList(final Map resource, final CodegenOperation co) { CodegenParameter accountSidParam = null; List> conditionalCodegenParam = new ArrayList<>(); - if (isVersionV2010) { - Optional optionalParam = co.allParams.stream() - .filter(param -> param.vendorExtensions.containsKey("x-is-account-sid")).findAny(); - if(optionalParam.isPresent()){ - accountSidParam = optionalParam.get(); - } - /** - * structure for vendorExtensions - * @ x-twilio: - * conditional: - * - - from - * - messaging_service_sid - * - - body - * - media_url - */ - if(co.vendorExtensions.containsKey("x-twilio")) { - HashMap twilioVendorExtension = (HashMap) co.vendorExtensions.get("x-twilio"); - if(twilioVendorExtension.containsKey("conditional")) { - List> conditionalParams = (List>) twilioVendorExtension.get("conditional"); - // map the conditional param names with the codegenParameter added in optional params - conditionalCodegenParam = conditionalParams.stream().map( - paramList -> paramList.stream().map( - cp -> co.optionalParams.stream().filter( - op -> op.paramName.equals(StringUtils.camelize(cp, true)) - ).findAny().get() - ).collect(Collectors.toList())).collect(Collectors.toList()); - // added filter to prevent same signature types - conditionalCodegenParam = conditionalCodegenParam.stream().filter(cpList -> (cpList.size() <=1 || !cpList.get(0).dataType.equals(cpList.get(1).dataType))).collect(Collectors.toList()); - } + Optional optionalParam = co.allParams.stream() + .filter(param -> param.vendorExtensions.containsKey("x-is-account-sid")).findAny(); + if(optionalParam.isPresent()){ + accountSidParam = optionalParam.get(); + } + /** + * structure for vendorExtensions + * @ x-twilio: + * conditional: + * - - from + * - messaging_service_sid + * - - body + * - media_url + */ + if(co.vendorExtensions.containsKey("x-twilio")) { + HashMap twilioVendorExtension = (HashMap) co.vendorExtensions.get("x-twilio"); + if(twilioVendorExtension.containsKey("conditional")) { + List> conditionalParams = (List>) twilioVendorExtension.get("conditional"); + // map the conditional param names with the codegenParameter added in optional params + conditionalCodegenParam = conditionalParams.stream().map( + paramList -> paramList.stream().map( + cp -> co.optionalParams.stream().filter( + op -> op.paramName.equals(StringUtils.camelize(cp, true)) + ).findAny().get() + ).collect(Collectors.toList())).collect(Collectors.toList()); + // added filter to prevent same signature types + conditionalCodegenParam = conditionalCodegenParam.stream().filter(cpList -> (cpList.size() <=1 || !cpList.get(0).dataType.equals(cpList.get(1).dataType))).collect(Collectors.toList()); } } conditionalCodegenParam = Lists.cartesianProduct(conditionalCodegenParam); @@ -779,7 +775,7 @@ protected ImmutableMap.Builder addMustacheLambdas() { private CodegenParameter resolveEnumParameter(CodegenParameter parameter, String resourceName) { if (parameter.items != null && parameter.items.allowableValues != null && parameter.items.allowableValues.containsKey("values")) { parameter.isEnum = true; - parameter.baseName = parameter.baseType; + parameter.enumName = parameter.baseType; parameter._enum = (List) parameter.items.allowableValues.get("values"); parameter.dataType = "List<" + resourceName + "." + parameter.baseType + ">"; parameter.baseType = resourceName + "." + parameter.baseType; @@ -788,8 +784,8 @@ private CodegenParameter resolveEnumParameter(CodegenParameter parameter, String if (parameter.allowableValues != null && parameter.allowableValues.containsKey("enumVars")) { parameter.isEnum = true; parameter._enum = (List) parameter.allowableValues.get("values"); - parameter.baseName = parameter.dataType; - parameter.dataType=resourceName + "." + parameter.dataType; + parameter.enumName = parameter.dataType; + parameter.dataType=resourceName+"."+parameter.dataType; } return parameter; } diff --git a/src/main/resources/twilio-java/api.mustache b/src/main/resources/twilio-java/api.mustache index 621be83e9..8b8fcc68d 100644 --- a/src/main/resources/twilio-java/api.mustache +++ b/src/main/resources/twilio-java/api.mustache @@ -57,6 +57,7 @@ import com.twilio.type.InboundSmsPrice; import com.twilio.type.OutboundSmsPrice; import com.twilio.type.OutboundCallPrice; import com.twilio.type.RecordingRule; +import com.twilio.type.SubscribeRule; @JsonIgnoreProperties(ignoreUnknown = true) @ToString diff --git a/src/main/resources/twilio-java/creator.mustache b/src/main/resources/twilio-java/creator.mustache index c0e1dc258..eb82b9c8a 100644 --- a/src/main/resources/twilio-java/creator.mustache +++ b/src/main/resources/twilio-java/creator.mustache @@ -64,17 +64,7 @@ public class {{resourceName}}Creator extends Creator<{{resourceName}}>{ @Override public {{resourceName}} create(final TwilioRestClient client){ - String path = "{{{path}}}"; - {{#allParams}} - {{#vendorExtensions.x-is-account-sid}} - this.{{paramName}} = this.{{paramName}} == null ? client.getAccountSid() : this.{{paramName}}; - path = path.replace("{"+"{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}"+"}", this.{{paramName}}.toString()); - {{/vendorExtensions.x-is-account-sid}} - {{/allParams}} - {{#requiredParams}} - path = path.replace("{"+"{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}"+"}", this.{{paramName}}.toString()); - {{/requiredParams}} - +{{>generate_uri}} Request request = new Request( HttpMethod.POST, Domains.{{#lambda.uppercase}}{{domainName}}{{/lambda.uppercase}}.toString(), diff --git a/src/main/resources/twilio-java/deleter.mustache b/src/main/resources/twilio-java/deleter.mustache index 4aed483be..d1ce087d5 100644 --- a/src/main/resources/twilio-java/deleter.mustache +++ b/src/main/resources/twilio-java/deleter.mustache @@ -57,17 +57,7 @@ public class {{resourceName}}Deleter extends Deleter<{{resourceName}}> { @Override public boolean delete(final TwilioRestClient client) { - String path = "{{{path}}}"; - {{#allParams}} - {{#vendorExtensions.x-is-account-sid}} - this.{{paramName}} = this.{{paramName}} == null ? client.getAccountSid() : this.{{paramName}}; - path = path.replace("{"+"{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}"+"}", this.{{paramName}}.toString()); - {{/vendorExtensions.x-is-account-sid}} - {{/allParams}} - {{#requiredParams}} - path = path.replace("{"+"{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}"+"}", this.{{paramName}}.toString()); - {{/requiredParams}} - +{{>generate_uri}} Request request = new Request( HttpMethod.DELETE, Domains.{{#lambda.uppercase}}{{domainName}}{{/lambda.uppercase}}.toString(), diff --git a/src/main/resources/twilio-java/fetcher.mustache b/src/main/resources/twilio-java/fetcher.mustache index a117187c4..92ca8ae57 100644 --- a/src/main/resources/twilio-java/fetcher.mustache +++ b/src/main/resources/twilio-java/fetcher.mustache @@ -58,17 +58,7 @@ public class {{resourceName}}Fetcher extends Fetcher<{{resourceName}}> { @Override public {{resourceName}} fetch(final TwilioRestClient client) { - String path = "{{{path}}}"; - {{#allParams}} - {{#vendorExtensions.x-is-account-sid}} - this.{{paramName}} = this.{{paramName}} == null ? client.getAccountSid() : this.{{paramName}}; - path = path.replace("{"+"{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}"+"}", this.{{paramName}}.toString()); - {{/vendorExtensions.x-is-account-sid}} - {{/allParams}} - {{#requiredParams}} - path = path.replace("{"+"{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}"+"}", this.{{paramName}}.toString()); - {{/requiredParams}} - +{{>generate_uri}} Request request = new Request( HttpMethod.GET, Domains.{{#lambda.uppercase}}{{domainName}}{{/lambda.uppercase}}.toString(), diff --git a/src/main/resources/twilio-java/generate_uri.mustache b/src/main/resources/twilio-java/generate_uri.mustache new file mode 100644 index 000000000..b74cf6363 --- /dev/null +++ b/src/main/resources/twilio-java/generate_uri.mustache @@ -0,0 +1,15 @@ + String path = "{{{path}}}"; +{{#allParams}} + {{#vendorExtensions.x-is-account-sid}} + this.{{paramName}} = this.{{paramName}} == null ? client.getAccountSid() : this.{{paramName}}; + path = path.replace("{"+"{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}"+"}", this.{{paramName}}.toString()); + {{/vendorExtensions.x-is-account-sid}} +{{/allParams}} +{{#requiredParams}} + {{#vendorExtensions.x-is-phone-number-format}} + path = path.replace("{"+"{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}"+"}", this.{{paramName}}.encode("utf-8")); + {{/vendorExtensions.x-is-phone-number-format}} + {{^vendorExtensions.x-is-phone-number-format}} + path = path.replace("{"+"{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}"+"}", this.{{paramName}}.toString()); + {{/vendorExtensions.x-is-phone-number-format}} +{{/requiredParams}} \ No newline at end of file diff --git a/src/main/resources/twilio-java/headerParams.mustache b/src/main/resources/twilio-java/headerParams.mustache index 1a4cc164f..bb423155a 100644 --- a/src/main/resources/twilio-java/headerParams.mustache +++ b/src/main/resources/twilio-java/headerParams.mustache @@ -5,12 +5,18 @@ request.addHeaderParam("{{baseName}}", {{paramName}}.toString()); {{/vendorExtensions.x-is-other-data-type}} {{^vendorExtensions.x-is-other-data-type}} + {{#isEnum}} + request.addHeaderParam("{{baseName}}", {{paramName}}.toString()); + {{/isEnum}} + {{^isEnum}} {{#isString}} request.addHeaderParam("{{baseName}}", {{paramName}}); {{/isString}} {{^isString}} request.addHeaderParam("{{baseName}}", {{paramName}}.toString()); {{/isString}} + {{/isEnum}} + {{/vendorExtensions.x-is-other-data-type}} } {{/headerParams}} diff --git a/src/main/resources/twilio-java/postParams.mustache b/src/main/resources/twilio-java/postParams.mustache index 70a1ab656..689ad4497 100644 --- a/src/main/resources/twilio-java/postParams.mustache +++ b/src/main/resources/twilio-java/postParams.mustache @@ -8,7 +8,7 @@ {{#isArray}} {{#isEnum}} for ({{baseType}} prop : {{paramName}}) { - request.addPostParam("{{baseName}}", prop.toString()); + request.addPostParam("{{#lambda.titlecase}}{{{paramName}}}{{/lambda.titlecase}}", prop.toString()); } {{/isEnum}} {{^isEnum}} @@ -26,7 +26,7 @@ {{/isArray}} {{^isArray}} {{#vendorExtensions.x-is-other-data-type}} - request.addPostParam("{{baseName}}", {{paramName}}.toString()); + request.addPostParam("{{#lambda.titlecase}}{{{paramName}}}{{/lambda.titlecase}}", {{paramName}}.toString()); {{/vendorExtensions.x-is-other-data-type}} {{^vendorExtensions.x-is-other-data-type}} {{#isString}} diff --git a/src/main/resources/twilio-java/responseModel.mustache b/src/main/resources/twilio-java/responseModel.mustache index 03587dd5a..e81fd1b97 100644 --- a/src/main/resources/twilio-java/responseModel.mustache +++ b/src/main/resources/twilio-java/responseModel.mustache @@ -1,7 +1,7 @@ {{#responseModel}} {{#vendorExtensions.enumVars}} {{#isEnum}} - public enum {{#lambda.titlecase}}{{{baseName}}}{{/lambda.titlecase}} { + public enum {{#lambda.titlecase}}{{{enumName}}}{{/lambda.titlecase}} { {{#allowableValues}} {{#values}} {{#lambda.uppercase}}{{#lambda.replacehyphen}}{{{.}}}{{/lambda.replacehyphen}}({{/lambda.uppercase}}"{{{.}}}"){{^-last}},{{/-last}}{{#-last}};{{/-last}} @@ -10,7 +10,7 @@ private final String value; - private {{#lambda.titlecase}}{{{baseName}}}{{/lambda.titlecase}}(final String value) { + private {{#lambda.titlecase}}{{{enumName}}}{{/lambda.titlecase}}(final String value) { this.value = value; } @@ -19,8 +19,8 @@ } @JsonCreator - public static {{#lambda.titlecase}}{{{baseName}}}{{/lambda.titlecase}} forValue(final String value) { - return Promoter.enumFromString(value, {{#lambda.titlecase}}{{{baseName}}}{{/lambda.titlecase}}.values()); + public static {{#lambda.titlecase}}{{{enumName}}}{{/lambda.titlecase}} forValue(final String value) { + return Promoter.enumFromString(value, {{#lambda.titlecase}}{{{enumName}}}{{/lambda.titlecase}}.values()); } } {{/isEnum}} diff --git a/src/main/resources/twilio-java/updater.mustache b/src/main/resources/twilio-java/updater.mustache index 1585cc413..694e3050c 100644 --- a/src/main/resources/twilio-java/updater.mustache +++ b/src/main/resources/twilio-java/updater.mustache @@ -58,17 +58,7 @@ public class {{resourceName}}Updater extends Updater<{{resourceName}}>{ @Override public {{resourceName}} update(final TwilioRestClient client){ - String path = "{{{path}}}"; - {{#allParams}} - {{#vendorExtensions.x-is-account-sid}} - this.{{paramName}} = this.{{paramName}} == null ? client.getAccountSid() : this.{{paramName}}; - path = path.replace("{"+"{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}"+"}", this.{{paramName}}.toString()); - {{/vendorExtensions.x-is-account-sid}} - {{/allParams}} - {{#requiredParams}} - path = path.replace("{"+"{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}"+"}", this.{{paramName}}.toString()); - {{/requiredParams}} - +{{>generate_uri}} Request request = new Request( HttpMethod.POST, Domains.{{#lambda.uppercase}}{{domainName}}{{/lambda.uppercase}}.toString(), From 347c60f1b2e238ac3235ceb9315cb5ccce0c2bc9 Mon Sep 17 00:00:00 2001 From: chsingh Date: Wed, 6 Jul 2022 05:20:15 +0530 Subject: [PATCH 11/19] fix url path --- .../com/twilio/oai/TwilioJavaGenerator.java | 78 ++++++++++++++++++- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 3b7dc5f94..12ef6f02a 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -4,17 +4,16 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Lists; -import com.samskivert.mustache.Mustache; import com.twilio.oai.mlambdas.ReplaceHyphenLambda; import com.twilio.oai.resource.IResourceTree; import com.twilio.oai.resource.ResourceMap; import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.PathItem; +import io.swagger.v3.oas.models.Paths; import lombok.AllArgsConstructor; -import org.commonmark.node.Code; import org.openapitools.codegen.*; import org.openapitools.codegen.languages.JavaClientCodegen; -import org.openapitools.codegen.templating.mustache.*; import org.openapitools.codegen.utils.StringUtils; import java.util.*; @@ -86,7 +85,7 @@ public void processOpenAPI(final OpenAPI openAPI) { resourceTree = new ResourceMap(inflector, PATH_SEPARATOR_PLACEHOLDER); // regex example : https://flex-api.twilio.com Pattern serverUrlPattern = Pattern.compile("https:\\/\\/([a-zA-Z-]+)\\.twilio\\.com"); - openAPI.getPaths().forEach((name, path) -> { + extendOpenAPI(openAPI).getPaths().forEach((name, path) -> { resourceTree.addResource(name, path); }); openAPI.getPaths().forEach((name, path) -> { @@ -102,6 +101,77 @@ public void processOpenAPI(final OpenAPI openAPI) { } }); } + + private OpenAPI extendOpenAPI(OpenAPI openAPI) { + Paths newPaths = new Paths(); + openAPI.getPaths().forEach((name, path) -> { + if (extracted(path)) { + for(Map.Entry newPathItem : extractOperatorToPathItem(name, path).entrySet()) { + newPaths.addPathItem(newPathItem.getKey(), newPathItem.getValue()); + } + } + else { + newPaths.addPathItem(name, path); + } + }); + openAPI.paths(newPaths); + return openAPI; + } + + private Map extractOperatorToPathItem(String name, PathItem path) { + ObjectMapper objectMapper = new ObjectMapper(); + Map pathItemMap = new HashMap<>(); + try { + PathItem pathItemOperatorClassVendExt = objectMapper + .readValue(objectMapper.writeValueAsString(path), PathItem.class); + PathItem pathItemClassVendExt = objectMapper + .readValue(objectMapper.writeValueAsString(path), PathItem.class); + pathItemClassVendExt.put(null); + pathItemClassVendExt.get(null); + pathItemClassVendExt.post(null); + pathItemClassVendExt.delete(null); + pathItemClassVendExt.patch(null); + pathItemOperatorClassVendExt.put(null); + pathItemOperatorClassVendExt.get(null); + pathItemOperatorClassVendExt.post(null); + pathItemOperatorClassVendExt.delete(null); + pathItemOperatorClassVendExt.patch(null); + for (Map.Entry entryMapOperation: path.readOperationsMap().entrySet()) { + if (isClassName(entryMapOperation.getValue())) { + String[] urls = name.split("/"); + String className = Arrays.stream(((Map)entryMapOperation.getValue() + .getExtensions().get("x-twilio")).get("className").split("_")). + map(StringUtils::camelize).collect(Collectors.joining()); + urls[urls.length-1] = className + ".json"; + String urlPath = String.join("/", urls); + pathItemOperatorClassVendExt.operation(entryMapOperation.getKey(), entryMapOperation.getValue()); + pathItemOperatorClassVendExt.getExtensions().put("parentUrl", name); + pathItemMap.put(urlPath, pathItemOperatorClassVendExt); + } else { + pathItemClassVendExt.operation(entryMapOperation.getKey(), entryMapOperation.getValue()); + pathItemMap.put(name, pathItemClassVendExt); + } + } + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return pathItemMap; + } + + private boolean extracted(PathItem path) { + for (io.swagger.v3.oas.models.Operation operation: path.readOperations()) { + if (isClassName(operation)) { + return true; + } + } + return false; + } + + private boolean isClassName(io.swagger.v3.oas.models.Operation operation) { + return (operation.getExtensions().containsKey("x-twilio")) && + ((Map) operation.getExtensions().get("x-twilio")).containsKey("className"); + } + /** * make accountSid an optional param * @param path From ac6e6bed069aedf1a28d2f15940606f8a95ff3a4 Mon Sep 17 00:00:00 2001 From: kridai Date: Wed, 6 Jul 2022 19:21:24 +0530 Subject: [PATCH 12/19] fix: incorrect uri issue --- src/main/java/com/twilio/oai/TwilioJavaGenerator.java | 2 +- src/main/resources/twilio-java/generate_uri.mustache | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 12ef6f02a..f2a993c4d 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -144,8 +144,8 @@ private Map extractOperatorToPathItem(String name, PathItem pa map(StringUtils::camelize).collect(Collectors.joining()); urls[urls.length-1] = className + ".json"; String urlPath = String.join("/", urls); + entryMapOperation.getValue().getExtensions().put("parentUrl", name); pathItemOperatorClassVendExt.operation(entryMapOperation.getKey(), entryMapOperation.getValue()); - pathItemOperatorClassVendExt.getExtensions().put("parentUrl", name); pathItemMap.put(urlPath, pathItemOperatorClassVendExt); } else { pathItemClassVendExt.operation(entryMapOperation.getKey(), entryMapOperation.getValue()); diff --git a/src/main/resources/twilio-java/generate_uri.mustache b/src/main/resources/twilio-java/generate_uri.mustache index b74cf6363..50c2061bd 100644 --- a/src/main/resources/twilio-java/generate_uri.mustache +++ b/src/main/resources/twilio-java/generate_uri.mustache @@ -1,4 +1,10 @@ - String path = "{{{path}}}"; +{{#vendorExtensions.parentUrl}} + String path = "{{{vendorExtensions.parentUrl}}}"; +{{/vendorExtensions.parentUrl}} +{{^vendorExtensions.parentUrl}} + String path = "{{{path}}}"; +{{/vendorExtensions.parentUrl}} + {{#allParams}} {{#vendorExtensions.x-is-account-sid}} this.{{paramName}} = this.{{paramName}} == null ? client.getAccountSid() : this.{{paramName}}; From 779601885dda5dcbe9f641ae6af5855633d0f809 Mon Sep 17 00:00:00 2001 From: chsingh Date: Fri, 8 Jul 2022 17:16:38 +0530 Subject: [PATCH 13/19] refactor path Item operator code --- .../com/twilio/oai/TwilioJavaGenerator.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index f2a993c4d..2cfd8d2e3 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -8,7 +8,6 @@ import com.twilio.oai.resource.IResourceTree; import com.twilio.oai.resource.ResourceMap; import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.PathItem; import io.swagger.v3.oas.models.Paths; import lombok.AllArgsConstructor; @@ -105,8 +104,8 @@ public void processOpenAPI(final OpenAPI openAPI) { private OpenAPI extendOpenAPI(OpenAPI openAPI) { Paths newPaths = new Paths(); openAPI.getPaths().forEach((name, path) -> { - if (extracted(path)) { - for(Map.Entry newPathItem : extractOperatorToPathItem(name, path).entrySet()) { + if (hasOperatorWithClassName(path)) { + for(Map.Entry newPathItem : extractMultiPathItemFromOperatorWithClassName(name, path).entrySet()) { newPaths.addPathItem(newPathItem.getKey(), newPathItem.getValue()); } } @@ -118,7 +117,7 @@ private OpenAPI extendOpenAPI(OpenAPI openAPI) { return openAPI; } - private Map extractOperatorToPathItem(String name, PathItem path) { + private Map extractMultiPathItemFromOperatorWithClassName(String name, PathItem path) { ObjectMapper objectMapper = new ObjectMapper(); Map pathItemMap = new HashMap<>(); try { @@ -126,16 +125,7 @@ private Map extractOperatorToPathItem(String name, PathItem pa .readValue(objectMapper.writeValueAsString(path), PathItem.class); PathItem pathItemClassVendExt = objectMapper .readValue(objectMapper.writeValueAsString(path), PathItem.class); - pathItemClassVendExt.put(null); - pathItemClassVendExt.get(null); - pathItemClassVendExt.post(null); - pathItemClassVendExt.delete(null); - pathItemClassVendExt.patch(null); - pathItemOperatorClassVendExt.put(null); - pathItemOperatorClassVendExt.get(null); - pathItemOperatorClassVendExt.post(null); - pathItemOperatorClassVendExt.delete(null); - pathItemOperatorClassVendExt.patch(null); + resetOperationMethodCalls(pathItemOperatorClassVendExt, pathItemClassVendExt); for (Map.Entry entryMapOperation: path.readOperationsMap().entrySet()) { if (isClassName(entryMapOperation.getValue())) { String[] urls = name.split("/"); @@ -158,7 +148,20 @@ private Map extractOperatorToPathItem(String name, PathItem pa return pathItemMap; } - private boolean extracted(PathItem path) { + private void resetOperationMethodCalls(PathItem pathItemOperatorClassVendExt, PathItem pathItemClassVendExt) { + pathItemClassVendExt.put(null); + pathItemClassVendExt.get(null); + pathItemClassVendExt.post(null); + pathItemClassVendExt.delete(null); + pathItemClassVendExt.patch(null); + pathItemOperatorClassVendExt.put(null); + pathItemOperatorClassVendExt.get(null); + pathItemOperatorClassVendExt.post(null); + pathItemOperatorClassVendExt.delete(null); + pathItemOperatorClassVendExt.patch(null); + } + + private boolean hasOperatorWithClassName(PathItem path) { for (io.swagger.v3.oas.models.Operation operation: path.readOperations()) { if (isClassName(operation)) { return true; From f4b07e686a2027c1f172a6df3072be001aeedda8 Mon Sep 17 00:00:00 2001 From: kridai Date: Mon, 11 Jul 2022 14:01:56 +0530 Subject: [PATCH 14/19] fix: added promotion types support --- .../com/twilio/oai/ConventionResolver.java | 17 +++++++++++++++- src/main/java/com/twilio/oai/Segments.java | 4 +++- .../com/twilio/oai/TwilioJavaGenerator.java | 2 +- src/main/resources/config/java.json | 13 +++++++----- .../resources/twilio-java/creator.mustache | 19 ++++++++++++++++++ .../resources/twilio-java/deleter.mustache | 20 +++++++++++++++++++ .../resources/twilio-java/fetcher.mustache | 20 +++++++++++++++++++ .../resources/twilio-java/reader.mustache | 20 +++++++++++++++++++ .../resources/twilio-java/updater.mustache | 19 ++++++++++++++++++ 9 files changed, 126 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/twilio/oai/ConventionResolver.java b/src/main/java/com/twilio/oai/ConventionResolver.java index e913cb78a..16104fc82 100644 --- a/src/main/java/com/twilio/oai/ConventionResolver.java +++ b/src/main/java/com/twilio/oai/ConventionResolver.java @@ -21,6 +21,10 @@ public class ConventionResolver { final static String X_IS_PHONE_NUMBER_FORMAT = "x-is-phone-number-format"; + final static String CONFIG_JAVA_JSON_PATH = "config/java.json"; + + final static String LIST_PREFIX = "list-"; + public static Optional resolve(Optional model) { for (CodegenProperty property : model.get().vars) { Map> vendorExtensions = new HashMap<>(); @@ -52,6 +56,17 @@ public static Optional resolveParameter(CodegenParameter param if(parameter.dataType.equalsIgnoreCase(OBJECT)) { parameter.dataType = (String)conventionMap.get(Segments.SEGMENT_PROPERTIES.getSegment()).get(OBJECT); } + boolean hasPromotion = conventionMap.get(Segments.SEGMENT_PROMOTIONS.getSegment()).containsKey(parameter.dataFormat); + if (hasPromotion) { + // cloning to prevent update in source map + HashMap promotionsMap = new HashMap<>((Map) conventionMap + .get(Segments.SEGMENT_PROMOTIONS.getSegment()).get(parameter.dataFormat)); + if(parameter.isArray && conventionMap.get(Segments.SEGMENT_PROMOTIONS.getSegment()).containsKey(LIST_PREFIX+parameter.dataFormat)) { + promotionsMap.put(parameter.baseType, (String) ((Map)conventionMap.get(Segments.SEGMENT_PROMOTIONS.getSegment()).get(LIST_PREFIX+parameter.dataFormat)).get(parameter.dataFormat)); + } + promotionsMap.replaceAll((dataType, value) -> String.format(value, parameter.paramName) ); + parameter.vendorExtensions.put("x-promotions", promotionsMap); + } boolean hasProperty = conventionMap.get(Segments.SEGMENT_PROPERTIES.getSegment()).containsKey(parameter.dataFormat); if (hasProperty) { @@ -84,7 +99,7 @@ public static CodegenParameter prefixedCollapsibleMap(CodegenParameter parameter public static Map> getConventionalMap() { try { - return new ObjectMapper().readValue(Thread.currentThread().getContextClassLoader().getResourceAsStream("config/java.json"), new TypeReference>>(){}); + return new ObjectMapper().readValue(Thread.currentThread().getContextClassLoader().getResourceAsStream(CONFIG_JAVA_JSON_PATH), new TypeReference>>(){}); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/com/twilio/oai/Segments.java b/src/main/java/com/twilio/oai/Segments.java index 08a9a72fb..fed0aefba 100644 --- a/src/main/java/com/twilio/oai/Segments.java +++ b/src/main/java/com/twilio/oai/Segments.java @@ -5,7 +5,9 @@ enum Segments { SEGMENT_SERIALIZE("serialize"), SEGMENT_DESERIALIZE("deserialize"), SEGMENT_PROPERTIES("properties"), - SEGMENT_LIBRARY("library"); + SEGMENT_LIBRARY("library"), + //promotions is uses to provide support for different datatypes of same parameter + SEGMENT_PROMOTIONS("promotions"); private final String segment; diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 2cfd8d2e3..5bdc4f541 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -214,7 +214,7 @@ public void postProcessParameter(final CodegenParameter parameter) { parameter.baseType = value[value.length-1]; } // Make sure required non-path params get into the options block. - parameter.paramName = StringUtils.camelize(parameter.paramName, false); + parameter.paramName = StringUtils.camelize(parameter.paramName, true); } @Override diff --git a/src/main/resources/config/java.json b/src/main/resources/config/java.json index 8b584ba15..b60bea694 100644 --- a/src/main/resources/config/java.json +++ b/src/main/resources/config/java.json @@ -95,14 +95,17 @@ }, "promotions": { - "url": { - "string": "Promoter.uriFromString({})" + "uri": { + "string": "Promoter.uriFromString(%s)" }, - "phone_number": { - "string": "Promoter.phoneNumberFromString({})" + "list-uri": { + "uri": "Promoter.listOfOne(%s)" + }, + "phone-number": { + "string": "Promoter.phoneNumberFromString(%s)" }, "twiml": { - "string": "Promoter.twimlFromString({})" + "string": "Promoter.twimlFromString(%s)" } }, diff --git a/src/main/resources/twilio-java/creator.mustache b/src/main/resources/twilio-java/creator.mustache index eb82b9c8a..ab49d024f 100644 --- a/src/main/resources/twilio-java/creator.mustache +++ b/src/main/resources/twilio-java/creator.mustache @@ -60,6 +60,25 @@ public class {{resourceName}}Creator extends Creator<{{resourceName}}>{ this.{{paramName}} = {{paramName}}; return this; } +{{#vendorExtensions.x-promotions}} +{{#isArray}} +{{#entrySet}} + + public {{resourceName}}Creator set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{#lambda.titlecase}}{{key}}{{/lambda.titlecase}} {{paramName}}){ + return set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}({{value}}); + } +{{/entrySet}} +{{/isArray}} +{{^isArray}} +{{#entrySet}} + + public {{resourceName}}Creator set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{#lambda.titlecase}}{{key}}{{/lambda.titlecase}} {{paramName}}){ + this.{{paramName}} = {{value}}; + return this; + } +{{/entrySet}} +{{/isArray}} +{{/vendorExtensions.x-promotions}} {{/vendorExtensions.x-non-path-params}} @Override diff --git a/src/main/resources/twilio-java/deleter.mustache b/src/main/resources/twilio-java/deleter.mustache index d1ce087d5..3f1ef2227 100644 --- a/src/main/resources/twilio-java/deleter.mustache +++ b/src/main/resources/twilio-java/deleter.mustache @@ -3,6 +3,7 @@ package com.twilio.rest.{{domainPackage}}.{{package}}{{packageSubPart}}; import com.twilio.base.Deleter; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; @@ -53,6 +54,25 @@ public class {{resourceName}}Deleter extends Deleter<{{resourceName}}> { this.{{paramName}} = {{paramName}}; return this; } +{{#vendorExtensions.x-promotions}} +{{#isArray}} +{{#entrySet}} + + public {{resourceName}}Deleter set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{#lambda.titlecase}}{{key}}{{/lambda.titlecase}} {{paramName}}){ + return set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}({{value}}); + } +{{/entrySet}} +{{/isArray}} +{{^isArray}} +{{#entrySet}} + + public {{resourceName}}Deleter set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{#lambda.titlecase}}{{key}}{{/lambda.titlecase}} {{paramName}}){ + this.{{paramName}} = {{value}}; + return this; + } +{{/entrySet}} +{{/isArray}} +{{/vendorExtensions.x-promotions}} {{/vendorExtensions.x-non-path-params}} @Override diff --git a/src/main/resources/twilio-java/fetcher.mustache b/src/main/resources/twilio-java/fetcher.mustache index 92ca8ae57..26fe18960 100644 --- a/src/main/resources/twilio-java/fetcher.mustache +++ b/src/main/resources/twilio-java/fetcher.mustache @@ -3,6 +3,7 @@ package com.twilio.rest.{{domainPackage}}.{{package}}{{packageSubPart}}; import com.twilio.base.Fetcher; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; @@ -54,6 +55,25 @@ public class {{resourceName}}Fetcher extends Fetcher<{{resourceName}}> { this.{{paramName}} = {{paramName}}; return this; } +{{#vendorExtensions.x-promotions}} +{{#isArray}} +{{#entrySet}} + + public {{resourceName}}Fetcher set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{#lambda.titlecase}}{{key}}{{/lambda.titlecase}} {{paramName}}){ + return set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}({{value}}); + } +{{/entrySet}} +{{/isArray}} +{{^isArray}} +{{#entrySet}} + + public {{resourceName}}Fetcher set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{#lambda.titlecase}}{{key}}{{/lambda.titlecase}} {{paramName}}){ + this.{{paramName}} = {{value}}; + return this; + } +{{/entrySet}} +{{/isArray}} +{{/vendorExtensions.x-promotions}} {{/vendorExtensions.x-non-path-params}} @Override diff --git a/src/main/resources/twilio-java/reader.mustache b/src/main/resources/twilio-java/reader.mustache index 5f1f93df5..1fa615367 100644 --- a/src/main/resources/twilio-java/reader.mustache +++ b/src/main/resources/twilio-java/reader.mustache @@ -4,6 +4,7 @@ package com.twilio.rest.{{domainPackage}}.{{package}}{{packageSubPart}}; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; @@ -56,6 +57,25 @@ public class {{resourceName}}Reader extends Reader<{{resourceName}}> { this.{{paramName}} = {{paramName}}; return this; } +{{#vendorExtensions.x-promotions}} +{{#isArray}} +{{#entrySet}} + + public {{resourceName}}Reader set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{#lambda.titlecase}}{{key}}{{/lambda.titlecase}} {{paramName}}){ + return set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}({{value}}); + } +{{/entrySet}} +{{/isArray}} +{{^isArray}} +{{#entrySet}} + + public {{resourceName}}Reader set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{#lambda.titlecase}}{{key}}{{/lambda.titlecase}} {{paramName}}){ + this.{{paramName}} = {{value}}; + return this; + } +{{/entrySet}} +{{/isArray}} +{{/vendorExtensions.x-promotions}} {{/vendorExtensions.x-non-path-params}} @Override diff --git a/src/main/resources/twilio-java/updater.mustache b/src/main/resources/twilio-java/updater.mustache index 694e3050c..6d147501c 100644 --- a/src/main/resources/twilio-java/updater.mustache +++ b/src/main/resources/twilio-java/updater.mustache @@ -54,6 +54,25 @@ public class {{resourceName}}Updater extends Updater<{{resourceName}}>{ this.{{paramName}} = {{paramName}}; return this; } +{{#vendorExtensions.x-promotions}} +{{#isArray}} +{{#entrySet}} + + public {{resourceName}}Updater set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{#lambda.titlecase}}{{key}}{{/lambda.titlecase}} {{paramName}}){ + return set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}({{value}}); + } +{{/entrySet}} +{{/isArray}} +{{^isArray}} +{{#entrySet}} + + public {{resourceName}}Updater set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{#lambda.titlecase}}{{key}}{{/lambda.titlecase}} {{paramName}}){ + this.{{paramName}} = {{value}}; + return this; + } +{{/entrySet}} +{{/isArray}} +{{/vendorExtensions.x-promotions}} {{/vendorExtensions.x-non-path-params}} @Override From 73abe45bdd8fd01f8aff3f71a856f674a79a195b Mon Sep 17 00:00:00 2001 From: kridai Date: Wed, 13 Jul 2022 14:20:57 +0530 Subject: [PATCH 15/19] fix: basic enum types --- .../com/twilio/oai/TwilioJavaGenerator.java | 73 ++++++++++++++----- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 5bdc4f541..8f88191ed 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -204,15 +204,20 @@ public String toParamName(String name) { public void postProcessParameter(final CodegenParameter parameter) { super.postProcessParameter(parameter); if (parameter.dataType.startsWith("List<") && parameter.dataType.contains("Enum")) { + parameter.vendorExtensions.put("refEnum", true); String[] value = parameter.dataType.split("Enum"); String lastValue = value[value.length-1]; parameter.dataType = "List<"+lastValue; parameter.baseType = lastValue.substring(0, lastValue.length()-1); } else if(parameter.dataType.contains("Enum")) { + parameter.vendorExtensions.put("refEnum", true); String[] value = parameter.dataType.split("Enum"); parameter.dataType = value[value.length-1]; parameter.baseType = value[value.length-1]; } + else if (parameter.isEnum) { + parameter.enumName = parameter.paramName; + } // Make sure required non-path params get into the options block. parameter.paramName = StringUtils.camelize(parameter.paramName, true); } @@ -221,16 +226,25 @@ public void postProcessParameter(final CodegenParameter parameter) { public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { super.postProcessModelProperty(model, property); if (property.dataType.startsWith("List<") && property.dataType.contains("Enum")) { + property.vendorExtensions.put("refEnum", true); String[] value = property.dataType.split("Enum"); String lastValue = value[value.length-1]; property.dataType = "List<" + lastValue; property.complexType = lastValue.substring(0, lastValue.length()-1); property.baseType = lastValue.substring(0, lastValue.length()-1); - } else if (property.dataType.contains("Enum")){ + property.isEnum = true; + property.allowableValues = property.items.allowableValues; + property._enum = (List) property.items.allowableValues.get("values"); + } else if (property.dataType.contains("Enum")) { + property.vendorExtensions.put("refEnum", true); String[] value = property.dataType.split("Enum"); - property.dataType = value[value.length-1]; + property.dataType = value[value.length - 1]; property.complexType = property.dataType; property.baseType = property.dataType; + property.isEnum = true; + property._enum = (List) property.allowableValues.get("values"); + } else if (property.isEnum ) { + property.enumName = property.baseName; } property.isEnum = property.isEnum && property.dataFormat == null; } @@ -314,7 +328,7 @@ public Map postProcessAllModels(final Map allMod .collect(Collectors.toCollection(() -> this.allModels)); } setObjectFormatMap(this.allModels); - setEnumProperties(this.allModels); + // setEnumProperties(this.allModels); // Return an empty collection so no model files get generated. return new HashMap<>(); } @@ -351,6 +365,7 @@ public Map postProcessOperationsWithModels(final Map postProcessOperationsWithModels(final Map item.getVendorExtensions().remove("enumVars")); + } + private void addDeleteHeaderEnums(CodegenOperation co, List responseModels) { List codegenProperties = new ArrayList<>(); for (CodegenParameter cp: co.allParams) { @@ -468,12 +487,20 @@ private CodegenModel processEnumVarsForAll(CodegenModel model, CodegenOperation List enumProperties = new ArrayList<>(); model.vars.forEach(item -> { if (item.isEnum && item.dataFormat == null && !item.dataType.contains(resourceName+ ".")) { - if (item.containerType != null && item.containerType.equals("array")) { - item.enumName = item.baseType; - item.dataType = "List<"+resourceName +"." + item.complexType+">"; + if (item.vendorExtensions.containsKey("refEnum")) { + if (item.containerType != null && item.containerType.equals("array")) { + item.enumName = item.baseType; + item.dataType = "List<"+resourceName +"." + item.complexType+">"; + } else { + item.enumName = item.baseType; + String[] values = item.dataType.split("\\."); + item.dataType = resourceName + "." + values[values.length -1]; + } } else { - item.enumName = item.baseType; - item.dataType = resourceName + "." + item.dataType; + String baseName = Arrays.stream(item.baseName.split("_")).map(StringUtils::camelize) + .collect(Collectors.joining()); + item.enumName = baseName; + item.dataType = resourceName + "." + baseName; } item.vendorExtensions.put("x-is-other-data-type", true); } @@ -492,24 +519,24 @@ private CodegenModel processEnumVarsForAll(CodegenModel model, CodegenOperation } } } + TreeSet ts = getEnumPropertyComparator(); + ts.addAll(enumProperties); if (model.getVendorExtensions().get("enumVars") != null) { List codegenProperties = (List) model.getVendorExtensions().get("enumVars"); - TreeSet ts = new TreeSet(new Comparator() { - public int compare(CodegenProperty cp1,CodegenProperty cp2) - { - return cp1.enumName.compareTo(cp2.getEnumName()); - } - }); - ts.addAll(enumProperties); ts.addAll(codegenProperties); - model.vendorExtensions.put("enumVars",new ArrayList<>(ts)); - } else { - model.vendorExtensions.put("enumVars", enumProperties); } - + model.vendorExtensions.put("enumVars",new ArrayList<>(ts)); return model; } + private TreeSet getEnumPropertyComparator() { + return new TreeSet(new Comparator() { + public int compare(CodegenProperty cp1, CodegenProperty cp2) { + return cp1.enumName.compareTo(cp2.getEnumName()); + } + }); + } + private CodegenProperty createCodeGenPropertyFromParameter(CodegenParameter co) { CodegenProperty property = new CodegenProperty(); property.isEnum = co.isEnum; @@ -846,7 +873,13 @@ protected ImmutableMap.Builder addMustacheLambdas() { } private CodegenParameter resolveEnumParameter(CodegenParameter parameter, String resourceName) { - if (parameter.items != null && parameter.items.allowableValues != null && parameter.items.allowableValues.containsKey("values")) { + if( parameter.isEnum && !parameter.vendorExtensions.containsKey("refEnum")) { + parameter.enumName = Arrays.stream(parameter.enumName.split("_")).map(StringUtils::camelize) + .collect(Collectors.joining()); + parameter.dataType = resourceName+"."+ parameter.enumName; + return parameter; + } + if (parameter.items != null && parameter.items.allowableValues != null && parameter.items.allowableValues.containsKey("values") ) { parameter.isEnum = true; parameter.enumName = parameter.baseType; parameter._enum = (List) parameter.items.allowableValues.get("values"); From cec4bebf12382fefbead6fa2bf2eef7951ce6ed0 Mon Sep 17 00:00:00 2001 From: kridai Date: Wed, 13 Jul 2022 17:55:42 +0530 Subject: [PATCH 16/19] fix: update examples --- .../com/twilio/rest/api/v2010/Account.java | 69 +++++-------- .../twilio/rest/api/v2010/AccountCreator.java | 9 +- .../twilio/rest/api/v2010/AccountDeleter.java | 4 +- .../twilio/rest/api/v2010/AccountFetcher.java | 4 +- .../twilio/rest/api/v2010/AccountReader.java | 1 + .../twilio/rest/api/v2010/AccountUpdater.java | 3 +- .../java/com/twilio/rest/api/v2010/Aws.java | 99 ++++--------------- .../com/twilio/rest/api/v2010/AwsCreator.java | 9 +- .../com/twilio/rest/api/v2010/AwsDeleter.java | 4 +- .../com/twilio/rest/api/v2010/AwsFetcher.java | 4 +- .../com/twilio/rest/api/v2010/AwsReader.java | 1 + .../com/twilio/rest/api/v2010/AwsUpdater.java | 3 +- .../java/com/twilio/rest/api/v2010/Call.java | 94 +----------------- .../twilio/rest/api/v2010/CallCreator.java | 3 +- .../twilio/rest/api/v2010/CallDeleter.java | 4 +- .../twilio/rest/api/v2010/CallFetcher.java | 4 +- .../api/v2010/call/FeedbackCallSummary.java | 94 +----------------- .../call/FeedbackCallSummaryCreator.java | 3 +- 18 files changed, 95 insertions(+), 317 deletions(-) diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/Account.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/Account.java index 6f33163e5..8886932ff 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/Account.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/Account.java @@ -67,11 +67,12 @@ import com.twilio.type.OutboundSmsPrice; import com.twilio.type.OutboundCallPrice; import com.twilio.type.RecordingRule; +import com.twilio.type.SubscribeRule; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Account extends Resource { - private static final long serialVersionUID = 101016944188709L; + private static final long serialVersionUID = 259833493148625L; public static AccountCreator creator(){ return new AccountCreator(); @@ -138,13 +139,17 @@ public static Account fromJson(final InputStream json, final ObjectMapper object throw new ApiConnectionException(e.getMessage(), e); } } - public enum TestEnum { - DIALVERB("DialVerb"), - TRUNKING("Trunking"); + public enum Status { + IN_PROGRESS("in-progress"), + PAUSED("paused"), + STOPPED("stopped"), + PROCESSING("processing"), + COMPLETED("completed"), + ABSENT("absent"); private final String value; - private TestEnum(final String value) { + private Status(final String value) { this.value = value; } @@ -153,17 +158,17 @@ public String toString() { } @JsonCreator - public static TestEnum forValue(final String value) { - return Promoter.enumFromString(value, TestEnum.values()); + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); } } - public enum XTwilioWebhookEnabled { - TRUE("true"), - FALSE("false"); + public enum TestEnum { + DIALVERB("DialVerb"), + TRUNKING("Trunking"); private final String value; - private XTwilioWebhookEnabled(final String value) { + private TestEnum(final String value) { this.value = value; } @@ -172,21 +177,17 @@ public String toString() { } @JsonCreator - public static XTwilioWebhookEnabled forValue(final String value) { - return Promoter.enumFromString(value, XTwilioWebhookEnabled.values()); + public static TestEnum forValue(final String value) { + return Promoter.enumFromString(value, TestEnum.values()); } } - public enum Status { - IN_PROGRESS("in-progress"), - PAUSED("paused"), - STOPPED("stopped"), - PROCESSING("processing"), - COMPLETED("completed"), - ABSENT("absent"); + public enum XTwilioWebhookEnabled { + TRUE("true"), + FALSE("false"); private final String value; - private Status(final String value) { + private XTwilioWebhookEnabled(final String value) { this.value = value; } @@ -195,8 +196,8 @@ public String toString() { } @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); + public static XTwilioWebhookEnabled forValue(final String value) { + return Promoter.enumFromString(value, XTwilioWebhookEnabled.values()); } } @@ -213,8 +214,6 @@ public static Status forValue(final String value) { private final List testArrayOfIntegers; private final List> testArrayOfArrayOfIntegers; private final List testArrayOfObjects; - private final Account.XTwilioWebhookEnabled xTwilioWebhookEnabled; - private final Account.Status status; @JsonCreator private Account( @@ -256,13 +255,7 @@ private Account( final List> testArrayOfArrayOfIntegers, @JsonProperty("test_array_of_objects") - final List testArrayOfObjects, - - @JsonProperty("x_twilio_webhook_enabled") - final Account.XTwilioWebhookEnabled xTwilioWebhookEnabled, - - @JsonProperty("status") - final Account.Status status + final List testArrayOfObjects ) { this.accountSid = accountSid; this.sid = sid; @@ -277,8 +270,6 @@ private Account( this.testArrayOfIntegers = testArrayOfIntegers; this.testArrayOfArrayOfIntegers = testArrayOfArrayOfIntegers; this.testArrayOfObjects = testArrayOfObjects; - this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; - this.status = status; } public final String getAccountSid() { @@ -320,12 +311,6 @@ public final List> getTestArrayOfArrayOfIntegers() { public final List getTestArrayOfObjects() { return this.testArrayOfObjects; } - public final Account.XTwilioWebhookEnabled getXTwilioWebhookEnabled() { - return this.xTwilioWebhookEnabled; - } - public final Account.Status getStatus() { - return this.status; - } @Override public boolean equals(final Object o) { @@ -339,12 +324,12 @@ public boolean equals(final Object o) { Account other = (Account) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) && Objects.equals(xTwilioWebhookEnabled, other.xTwilioWebhookEnabled) && Objects.equals(status, other.status) ; + return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) ; } @Override public int hashCode() { - return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects, xTwilioWebhookEnabled, status); + return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects); } } 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 10e75b726..ec8e532e9 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 @@ -76,6 +76,11 @@ public AccountCreator setRecordingStatusCallback(final URI recordingStatusCallba this.recordingStatusCallback = recordingStatusCallback; return this; } + + public AccountCreator setRecordingStatusCallback(final String recordingStatusCallback){ + this.recordingStatusCallback = Promoter.uriFromString(recordingStatusCallback); + return this; + } public AccountCreator setRecordingStatusCallbackEvent(final List recordingStatusCallbackEvent){ this.recordingStatusCallbackEvent = recordingStatusCallbackEvent; return this; @@ -83,7 +88,8 @@ public AccountCreator setRecordingStatusCallbackEvent(final List recordi @Override public Account create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts.json"; + String path = "/2010-04-01/Accounts.json"; + Request request = new Request( HttpMethod.POST, @@ -120,6 +126,7 @@ 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 c5657c797..ddc07e60d 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 @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010; import com.twilio.base.Deleter; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; @@ -65,7 +66,8 @@ public AccountDeleter(final String sid){ @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{Sid}.json"; + String path = "/2010-04-01/Accounts/{Sid}.json"; + this.sid = this.sid == null ? client.getAccountSid() : this.sid; path = path.replace("{"+"Sid"+"}", this.sid.toString()); 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 c81bf596b..a20780cb7 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 @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010; import com.twilio.base.Fetcher; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; @@ -66,7 +67,8 @@ public AccountFetcher(final String sid){ @Override public Account fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{Sid}.json"; + String path = "/2010-04-01/Accounts/{Sid}.json"; + this.sid = this.sid == null ? client.getAccountSid() : this.sid; path = path.replace("{"+"Sid"+"}", this.sid.toString()); 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 b55241916..060f802e9 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 @@ -16,6 +16,7 @@ import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; 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 8ac5eae14..e787098a4 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 @@ -78,7 +78,8 @@ public AccountUpdater setPauseBehavior(final String pauseBehavior){ @Override public Account update(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{Sid}.json"; + String path = "/2010-04-01/Accounts/{Sid}.json"; + this.sid = this.sid == null ? client.getAccountSid() : this.sid; path = path.replace("{"+"Sid"+"}", this.sid.toString()); path = path.replace("{"+"Status"+"}", this.status.toString()); diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/Aws.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/Aws.java index c6649d209..89e27d1f9 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/Aws.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/Aws.java @@ -67,11 +67,12 @@ import com.twilio.type.OutboundSmsPrice; import com.twilio.type.OutboundCallPrice; import com.twilio.type.RecordingRule; +import com.twilio.type.SubscribeRule; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Aws extends Resource { - private static final long serialVersionUID = 259030760536895L; + private static final long serialVersionUID = 204159094531598L; public static AwsCreator creator(final String testString, final Integer testInteger, final Float testNumberFloat){ return new AwsCreator(testString, testInteger, testNumberFloat); @@ -138,55 +139,13 @@ public static Aws fromJson(final InputStream json, final ObjectMapper objectMapp throw new ApiConnectionException(e.getMessage(), e); } } - public enum TestEnum { - DIALVERB("DialVerb"), - TRUNKING("Trunking"); - - private final String value; - - private TestEnum(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - @JsonCreator - public static TestEnum forValue(final String value) { - return Promoter.enumFromString(value, TestEnum.values()); - } - } - public enum XTwilioWebhookEnabled { - TRUE("true"), - FALSE("false"); - - private final String value; - - private XTwilioWebhookEnabled(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - @JsonCreator - public static XTwilioWebhookEnabled forValue(final String value) { - return Promoter.enumFromString(value, XTwilioWebhookEnabled.values()); - } - } - public enum Status { - IN_PROGRESS("in-progress"), - PAUSED("paused"), - STOPPED("stopped"), - PROCESSING("processing"), - COMPLETED("completed"), - ABSENT("absent"); + public enum Permissions { + GET_ALL("get-all"), + POST_ALL("post-all"); private final String value; - private Status(final String value) { + private Permissions(final String value) { this.value = value; } @@ -195,17 +154,17 @@ public String toString() { } @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); + public static Permissions forValue(final String value) { + return Promoter.enumFromString(value, Permissions.values()); } } - public enum Permissions { - GET_ALL("get-all"), - POST_ALL("post-all"); + public enum TestEnum { + DIALVERB("DialVerb"), + TRUNKING("Trunking"); private final String value; - private Permissions(final String value) { + private TestEnum(final String value) { this.value = value; } @@ -214,8 +173,8 @@ public String toString() { } @JsonCreator - public static Permissions forValue(final String value) { - return Promoter.enumFromString(value, Permissions.values()); + public static TestEnum forValue(final String value) { + return Promoter.enumFromString(value, TestEnum.values()); } } @@ -232,9 +191,6 @@ public static Permissions forValue(final String value) { private final List testArrayOfIntegers; private final List> testArrayOfArrayOfIntegers; private final List testArrayOfObjects; - private final Aws.XTwilioWebhookEnabled xTwilioWebhookEnabled; - private final Aws.Status status; - private final Aws.Permissions permissions; @JsonCreator private Aws( @@ -276,16 +232,7 @@ private Aws( final List> testArrayOfArrayOfIntegers, @JsonProperty("test_array_of_objects") - final List testArrayOfObjects, - - @JsonProperty("x_twilio_webhook_enabled") - final Aws.XTwilioWebhookEnabled xTwilioWebhookEnabled, - - @JsonProperty("status") - final Aws.Status status, - - @JsonProperty("permissions") - final Aws.Permissions permissions + final List testArrayOfObjects ) { this.accountSid = accountSid; this.sid = sid; @@ -300,9 +247,6 @@ private Aws( this.testArrayOfIntegers = testArrayOfIntegers; this.testArrayOfArrayOfIntegers = testArrayOfArrayOfIntegers; this.testArrayOfObjects = testArrayOfObjects; - this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; - this.status = status; - this.permissions = permissions; } public final String getAccountSid() { @@ -344,15 +288,6 @@ public final List> getTestArrayOfArrayOfIntegers() { public final List getTestArrayOfObjects() { return this.testArrayOfObjects; } - public final Aws.XTwilioWebhookEnabled getXTwilioWebhookEnabled() { - return this.xTwilioWebhookEnabled; - } - public final Aws.Status getStatus() { - return this.status; - } - public final Aws.Permissions getPermissions() { - return this.permissions; - } @Override public boolean equals(final Object o) { @@ -366,12 +301,12 @@ public boolean equals(final Object o) { Aws other = (Aws) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) && Objects.equals(xTwilioWebhookEnabled, other.xTwilioWebhookEnabled) && Objects.equals(status, other.status) && Objects.equals(permissions, other.permissions) ; + return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) ; } @Override public int hashCode() { - return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects, xTwilioWebhookEnabled, status, permissions); + return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects); } } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java index d59c13696..12a743960 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java @@ -75,7 +75,7 @@ public class AwsCreator extends Creator{ private Aws.TestEnum testEnum; private List testObjectArray; private Map testAnyType; - private List permissions; + private Aws.Permissions permissions; public AwsCreator(final String testString, final Integer testInteger, final Float testNumberFloat) { this.testString = testString; @@ -154,14 +154,15 @@ public AwsCreator setTestAnyType(final Map testAnyType){ this.testAnyType = testAnyType; return this; } - public AwsCreator setPermissions(final List permissions){ + public AwsCreator setPermissions(final Aws.Permissions permissions){ this.permissions = permissions; return this; } @Override public Aws create(final TwilioRestClient client){ - String path = "/v1/Credentials/AWS"; + String path = "/v1/Credentials/AWS"; + path = path.replace("{"+"TestString"+"}", this.testString.toString()); Request request = new Request( @@ -243,7 +244,7 @@ private void addPostParams(final Request request) { } if (permissions != null) { - for (Aws.Permissions prop : permissions) { + for (String prop : permissions) { request.addPostParam("Permissions", prop.toString()); } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsDeleter.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsDeleter.java index 1fe29b0ca..1eb70c795 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsDeleter.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsDeleter.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010; import com.twilio.base.Deleter; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; @@ -63,7 +64,8 @@ public AwsDeleter(final String sid){ @Override public boolean delete(final TwilioRestClient client) { - String path = "/v1/Credentials/AWS/{Sid}"; + String path = "/v1/Credentials/AWS/{Sid}"; + path = path.replace("{"+"Sid"+"}", this.sid.toString()); Request request = new Request( diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsFetcher.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsFetcher.java index 62f2fd1e9..6593c28f7 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsFetcher.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsFetcher.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010; import com.twilio.base.Fetcher; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; @@ -64,7 +65,8 @@ public AwsFetcher(final String sid){ @Override public Aws fetch(final TwilioRestClient client) { - String path = "/v1/Credentials/AWS/{Sid}"; + String path = "/v1/Credentials/AWS/{Sid}"; + path = path.replace("{"+"Sid"+"}", this.sid.toString()); Request request = new Request( diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsReader.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsReader.java index a796f4618..82c132bd2 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsReader.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsReader.java @@ -16,6 +16,7 @@ import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsUpdater.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsUpdater.java index 705cf45e3..eaf4b3029 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsUpdater.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsUpdater.java @@ -69,7 +69,8 @@ public AwsUpdater setTestString(final String testString){ @Override public Aws update(final TwilioRestClient client){ - String path = "/v1/Credentials/AWS/{Sid}"; + String path = "/v1/Credentials/AWS/{Sid}"; + path = path.replace("{"+"Sid"+"}", this.sid.toString()); Request request = new Request( diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/Call.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/Call.java index c76b87b98..633640b91 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/Call.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/Call.java @@ -67,11 +67,12 @@ import com.twilio.type.OutboundSmsPrice; import com.twilio.type.OutboundCallPrice; import com.twilio.type.RecordingRule; +import com.twilio.type.SubscribeRule; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class Call extends Resource { - private static final long serialVersionUID = 196847422539171L; + private static final long serialVersionUID = 67961494484503L; public static CallCreator creator(final String requiredStringProperty){ return new CallCreator(requiredStringProperty); @@ -151,67 +152,6 @@ public static TestEnum forValue(final String value) { return Promoter.enumFromString(value, TestEnum.values()); } } - public enum XTwilioWebhookEnabled { - TRUE("true"), - FALSE("false"); - - private final String value; - - private XTwilioWebhookEnabled(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - @JsonCreator - public static XTwilioWebhookEnabled forValue(final String value) { - return Promoter.enumFromString(value, XTwilioWebhookEnabled.values()); - } - } - public enum Status { - IN_PROGRESS("in-progress"), - PAUSED("paused"), - STOPPED("stopped"), - PROCESSING("processing"), - COMPLETED("completed"), - ABSENT("absent"); - - private final String value; - - private Status(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); - } - } - public enum Permissions { - GET_ALL("get-all"), - POST_ALL("post-all"); - - private final String value; - - private Permissions(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - @JsonCreator - public static Permissions forValue(final String value) { - return Promoter.enumFromString(value, Permissions.values()); - } - } private final String accountSid; private final String sid; @@ -226,9 +166,6 @@ public static Permissions forValue(final String value) { private final List testArrayOfIntegers; private final List> testArrayOfArrayOfIntegers; private final List testArrayOfObjects; - private final Call.XTwilioWebhookEnabled xTwilioWebhookEnabled; - private final Call.Status status; - private final Call.Permissions permissions; @JsonCreator private Call( @@ -270,16 +207,7 @@ private Call( final List> testArrayOfArrayOfIntegers, @JsonProperty("test_array_of_objects") - final List testArrayOfObjects, - - @JsonProperty("x_twilio_webhook_enabled") - final Call.XTwilioWebhookEnabled xTwilioWebhookEnabled, - - @JsonProperty("status") - final Call.Status status, - - @JsonProperty("permissions") - final Call.Permissions permissions + final List testArrayOfObjects ) { this.accountSid = accountSid; this.sid = sid; @@ -294,9 +222,6 @@ private Call( this.testArrayOfIntegers = testArrayOfIntegers; this.testArrayOfArrayOfIntegers = testArrayOfArrayOfIntegers; this.testArrayOfObjects = testArrayOfObjects; - this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; - this.status = status; - this.permissions = permissions; } public final String getAccountSid() { @@ -338,15 +263,6 @@ public final List> getTestArrayOfArrayOfIntegers() { public final List getTestArrayOfObjects() { return this.testArrayOfObjects; } - public final Call.XTwilioWebhookEnabled getXTwilioWebhookEnabled() { - return this.xTwilioWebhookEnabled; - } - public final Call.Status getStatus() { - return this.status; - } - public final Call.Permissions getPermissions() { - return this.permissions; - } @Override public boolean equals(final Object o) { @@ -360,12 +276,12 @@ public boolean equals(final Object o) { Call other = (Call) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) && Objects.equals(xTwilioWebhookEnabled, other.xTwilioWebhookEnabled) && Objects.equals(status, other.status) && Objects.equals(permissions, other.permissions) ; + return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) ; } @Override public int hashCode() { - return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects, xTwilioWebhookEnabled, status, permissions); + return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects); } } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/CallCreator.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/CallCreator.java index 4e207089f..4d567a9e0 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/CallCreator.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/CallCreator.java @@ -84,7 +84,8 @@ public CallCreator setTestArrayOfStrings(final List testArrayOfStrings){ @Override public Call create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls.json"; + String path = "/2010-04-01/Accounts/{AccountSid}/Calls.json"; + this.accountSid = this.accountSid == null ? client.getAccountSid() : this.accountSid; path = path.replace("{"+"AccountSid"+"}", this.accountSid.toString()); path = path.replace("{"+"RequiredStringProperty"+"}", this.requiredStringProperty.toString()); diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/CallDeleter.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/CallDeleter.java index 0e5861e0e..7d496a18a 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/CallDeleter.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/CallDeleter.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010; import com.twilio.base.Deleter; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; @@ -68,7 +69,8 @@ public CallDeleter(final String accountSid, final Integer testInteger){ @Override public boolean delete(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{TestInteger}.json"; + String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{TestInteger}.json"; + this.accountSid = this.accountSid == null ? client.getAccountSid() : this.accountSid; path = path.replace("{"+"AccountSid"+"}", this.accountSid.toString()); path = path.replace("{"+"TestInteger"+"}", this.testInteger.toString()); diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/CallFetcher.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/CallFetcher.java index a0613a1a8..fd7994542 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/CallFetcher.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/CallFetcher.java @@ -15,6 +15,7 @@ package com.twilio.rest.api.v2010; import com.twilio.base.Fetcher; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.converter.PrefixedCollapsibleMap; import com.twilio.exception.ApiException; @@ -69,7 +70,8 @@ public CallFetcher(final String accountSid, final Integer testInteger){ @Override public Call fetch(final TwilioRestClient client) { - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{TestInteger}.json"; + String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{TestInteger}.json"; + this.accountSid = this.accountSid == null ? client.getAccountSid() : this.accountSid; path = path.replace("{"+"AccountSid"+"}", this.accountSid.toString()); path = path.replace("{"+"TestInteger"+"}", this.testInteger.toString()); diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/call/FeedbackCallSummary.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/call/FeedbackCallSummary.java index 64058149f..b835ed913 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/call/FeedbackCallSummary.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/call/FeedbackCallSummary.java @@ -67,11 +67,12 @@ import com.twilio.type.OutboundSmsPrice; import com.twilio.type.OutboundCallPrice; import com.twilio.type.RecordingRule; +import com.twilio.type.SubscribeRule; @JsonIgnoreProperties(ignoreUnknown = true) @ToString public class FeedbackCallSummary extends Resource { - private static final long serialVersionUID = 196847422539171L; + private static final long serialVersionUID = 67961494484503L; public static FeedbackCallSummaryCreator creator(final LocalDate endDate, final LocalDate startDate){ return new FeedbackCallSummaryCreator(endDate, startDate); @@ -139,67 +140,6 @@ public static TestEnum forValue(final String value) { return Promoter.enumFromString(value, TestEnum.values()); } } - public enum XTwilioWebhookEnabled { - TRUE("true"), - FALSE("false"); - - private final String value; - - private XTwilioWebhookEnabled(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - @JsonCreator - public static XTwilioWebhookEnabled forValue(final String value) { - return Promoter.enumFromString(value, XTwilioWebhookEnabled.values()); - } - } - public enum Status { - IN_PROGRESS("in-progress"), - PAUSED("paused"), - STOPPED("stopped"), - PROCESSING("processing"), - COMPLETED("completed"), - ABSENT("absent"); - - private final String value; - - private Status(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); - } - } - public enum Permissions { - GET_ALL("get-all"), - POST_ALL("post-all"); - - private final String value; - - private Permissions(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - @JsonCreator - public static Permissions forValue(final String value) { - return Promoter.enumFromString(value, Permissions.values()); - } - } private final String accountSid; private final String sid; @@ -214,9 +154,6 @@ public static Permissions forValue(final String value) { private final List testArrayOfIntegers; private final List> testArrayOfArrayOfIntegers; private final List testArrayOfObjects; - private final FeedbackCallSummary.XTwilioWebhookEnabled xTwilioWebhookEnabled; - private final FeedbackCallSummary.Status status; - private final FeedbackCallSummary.Permissions permissions; @JsonCreator private FeedbackCallSummary( @@ -258,16 +195,7 @@ private FeedbackCallSummary( final List> testArrayOfArrayOfIntegers, @JsonProperty("test_array_of_objects") - final List testArrayOfObjects, - - @JsonProperty("x_twilio_webhook_enabled") - final FeedbackCallSummary.XTwilioWebhookEnabled xTwilioWebhookEnabled, - - @JsonProperty("status") - final FeedbackCallSummary.Status status, - - @JsonProperty("permissions") - final FeedbackCallSummary.Permissions permissions + final List testArrayOfObjects ) { this.accountSid = accountSid; this.sid = sid; @@ -282,9 +210,6 @@ private FeedbackCallSummary( this.testArrayOfIntegers = testArrayOfIntegers; this.testArrayOfArrayOfIntegers = testArrayOfArrayOfIntegers; this.testArrayOfObjects = testArrayOfObjects; - this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; - this.status = status; - this.permissions = permissions; } public final String getAccountSid() { @@ -326,15 +251,6 @@ public final List> getTestArrayOfArrayOfIntegers() { public final List getTestArrayOfObjects() { return this.testArrayOfObjects; } - public final FeedbackCallSummary.XTwilioWebhookEnabled getXTwilioWebhookEnabled() { - return this.xTwilioWebhookEnabled; - } - public final FeedbackCallSummary.Status getStatus() { - return this.status; - } - public final FeedbackCallSummary.Permissions getPermissions() { - return this.permissions; - } @Override public boolean equals(final Object o) { @@ -348,12 +264,12 @@ public boolean equals(final Object o) { FeedbackCallSummary other = (FeedbackCallSummary) o; - return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) && Objects.equals(xTwilioWebhookEnabled, other.xTwilioWebhookEnabled) && Objects.equals(status, other.status) && Objects.equals(permissions, other.permissions) ; + return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) ; } @Override public int hashCode() { - return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects, xTwilioWebhookEnabled, status, permissions); + return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects); } } diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/call/FeedbackCallSummaryCreator.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/call/FeedbackCallSummaryCreator.java index 1c0e0c8da..d48e2a2d7 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/call/FeedbackCallSummaryCreator.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/call/FeedbackCallSummaryCreator.java @@ -86,7 +86,8 @@ public FeedbackCallSummaryCreator setStartDate(final LocalDate startDate){ @Override public FeedbackCallSummary create(final TwilioRestClient client){ - String path = "/2010-04-01/Accounts/{AccountSid}/Calls/FeedbackSummary.json"; + String path = "/2010-04-01/Accounts/{AccountSid}/Calls/FeedbackSummary.json"; + this.accountSid = this.accountSid == null ? client.getAccountSid() : this.accountSid; path = path.replace("{"+"AccountSid"+"}", this.accountSid.toString()); path = path.replace("{"+"EndDate"+"}", this.endDate.toString()); From 45b8f45db08f4c2fab3c568b61b55d37e2fcfd3f Mon Sep 17 00:00:00 2001 From: kridai Date: Wed, 13 Jul 2022 18:25:30 +0530 Subject: [PATCH 17/19] fix: enum changes --- .../java/com/twilio/rest/api/v2010/AwsCreator.java | 4 ++-- .../java/com/twilio/oai/TwilioJavaGenerator.java | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java index 12a743960..8c9886044 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java @@ -75,7 +75,7 @@ public class AwsCreator extends Creator{ private Aws.TestEnum testEnum; private List testObjectArray; private Map testAnyType; - private Aws.Permissions permissions; + private List permissions; public AwsCreator(final String testString, final Integer testInteger, final Float testNumberFloat) { this.testString = testString; @@ -154,7 +154,7 @@ public AwsCreator setTestAnyType(final Map testAnyType){ this.testAnyType = testAnyType; return this; } - public AwsCreator setPermissions(final Aws.Permissions permissions){ + public AwsCreator setPermissions(final List permissions){ this.permissions = permissions; return this; } diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 8f88191ed..4d78c392c 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -500,7 +500,12 @@ private CodegenModel processEnumVarsForAll(CodegenModel model, CodegenOperation String baseName = Arrays.stream(item.baseName.split("_")).map(StringUtils::camelize) .collect(Collectors.joining()); item.enumName = baseName; - item.dataType = resourceName + "." + baseName; + if (item.containerType != null && item.containerType.equals("array")) { + item.dataType = "List<"+ resourceName + "." + baseName + ">"; + } else { + item.dataType = resourceName + "." + baseName; + } + } item.vendorExtensions.put("x-is-other-data-type", true); } @@ -876,7 +881,12 @@ private CodegenParameter resolveEnumParameter(CodegenParameter parameter, String if( parameter.isEnum && !parameter.vendorExtensions.containsKey("refEnum")) { parameter.enumName = Arrays.stream(parameter.enumName.split("_")).map(StringUtils::camelize) .collect(Collectors.joining()); - parameter.dataType = resourceName+"."+ parameter.enumName; + if (parameter.items != null && parameter.items.allowableValues != null && parameter.items.allowableValues.containsKey("values")) { + parameter.dataType = "List<" + resourceName+"."+ parameter.enumName + ">"; + } else { + parameter.dataType = resourceName+"."+ parameter.enumName; + } + return parameter; } if (parameter.items != null && parameter.items.allowableValues != null && parameter.items.allowableValues.containsKey("values") ) { From 08e00036efa42d50486ba9ec0a3f8c514c5b9b5b Mon Sep 17 00:00:00 2001 From: kridai Date: Wed, 13 Jul 2022 19:00:25 +0530 Subject: [PATCH 18/19] fix: enum changes --- .../src/main/java/com/twilio/rest/api/v2010/AwsCreator.java | 2 +- src/main/java/com/twilio/oai/TwilioJavaGenerator.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java index 8c9886044..290ad3ef3 100644 --- a/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java +++ b/examples/java/src/main/java/com/twilio/rest/api/v2010/AwsCreator.java @@ -244,7 +244,7 @@ private void addPostParams(final Request request) { } if (permissions != null) { - for (String prop : permissions) { + for (Aws.Permissions prop : permissions) { request.addPostParam("Permissions", prop.toString()); } diff --git a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java index 4d78c392c..5ace24bf7 100644 --- a/src/main/java/com/twilio/oai/TwilioJavaGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioJavaGenerator.java @@ -502,6 +502,7 @@ private CodegenModel processEnumVarsForAll(CodegenModel model, CodegenOperation item.enumName = baseName; if (item.containerType != null && item.containerType.equals("array")) { item.dataType = "List<"+ resourceName + "." + baseName + ">"; + item.baseType = resourceName + "." + baseName; } else { item.dataType = resourceName + "." + baseName; } @@ -883,6 +884,7 @@ private CodegenParameter resolveEnumParameter(CodegenParameter parameter, String .collect(Collectors.joining()); if (parameter.items != null && parameter.items.allowableValues != null && parameter.items.allowableValues.containsKey("values")) { parameter.dataType = "List<" + resourceName+"."+ parameter.enumName + ">"; + parameter.baseType = resourceName + "." + parameter.enumName; } else { parameter.dataType = resourceName+"."+ parameter.enumName; } From 021e7fce5176b20e1d6453c9c1f5bf91a50a9859 Mon Sep 17 00:00:00 2001 From: chsingh Date: Wed, 13 Jul 2022 19:21:05 +0530 Subject: [PATCH 19/19] fix: unit test --- .../java/unit-test/rest/TwilioRestTest.java | 53 +------------------ 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/examples/java/unit-test/rest/TwilioRestTest.java b/examples/java/unit-test/rest/TwilioRestTest.java index 5539cd8cb..6fa660a33 100644 --- a/examples/java/unit-test/rest/TwilioRestTest.java +++ b/examples/java/unit-test/rest/TwilioRestTest.java @@ -204,7 +204,6 @@ public void testShouldSendIncorrectStatusForAccountCreator() { when(twilioRestClient.getObjectMapper()).thenReturn(objectMapper); AccountCreator accountCreator = new AccountCreator(); accountCreator.setRecordingStatusCallbackEvent(null); - accountCreator.setRecordingStatusCallback(null); accountCreator.setXTwilioWebhookEnabled(null); accountCreator.create(twilioRestClient); @@ -741,7 +740,7 @@ public void testShouldMakeInValidAPICallReturnsNullForAccountUpdater() { public void testShouldMakeInValidAPICallReturnsWrongStatusForAccountUpdater() { Request mockRequest = new Request( HttpMethod.POST, - com.twilio.rest.Domains.API.toString(), + Domains.API.toString(), "/2010-04-01/Accounts/AC222222222222222222222222222222.json" ); mockRequest.addPostParam("PauseBehavior", "test"); @@ -948,33 +947,6 @@ public void testAccountCrud() { assertNotNull(accountUpdater); } - - @Test - public void testCallVariables() { - Call.TestEnum testEnum = Call.TestEnum.forValue("DialVerb"); - Call.XTwilioWebhookEnabled xTwilioWebhookEnabled = Call.XTwilioWebhookEnabled.forValue("true"); - Call.Status status = Call.Status.forValue("paused"); - Call.Permissions permissions = Call.Permissions.forValue("get-all"); - - assertEquals("DialVerb", testEnum.toString()); - assertEquals("true", xTwilioWebhookEnabled.toString()); - assertEquals("paused", status.toString()); - assertEquals("get-all", permissions.toString()); - } - - @Test - public void testAwsVariables() { - Aws.TestEnum testEnum = Aws.TestEnum.forValue("DialVerb"); - Aws.XTwilioWebhookEnabled xTwilioWebhookEnabled = Aws.XTwilioWebhookEnabled.forValue("true"); - Aws.Status status = Aws.Status.forValue("paused"); - Aws.Permissions permissions = Aws.Permissions.forValue("get-all"); - - assertEquals("DialVerb", testEnum.toString()); - assertEquals("true", xTwilioWebhookEnabled.toString()); - assertEquals("paused", status.toString()); - assertEquals("get-all", permissions.toString()); - } - @Test public void testAccountVariables() { Account.TestEnum testEnum = Account.TestEnum.forValue("DialVerb"); @@ -1085,9 +1057,6 @@ public void testCallGetters() { assertNull(call.getTestArrayOfIntegers()); assertNull(call.getTestArrayOfArrayOfIntegers()); assertNull(call.getTestArrayOfObjects()); - assertNull(call.getXTwilioWebhookEnabled()); - assertNull(call.getStatus()); - assertNull(call.getPermissions()); assertNull(call.getTestString()); assertTrue(call.equals(callDuplicate)); @@ -1119,9 +1088,6 @@ public void testAwsGetters() { assertNull(aws.getTestArrayOfIntegers()); assertNull(aws.getTestArrayOfArrayOfIntegers()); assertNull(aws.getTestArrayOfObjects()); - assertNull(aws.getXTwilioWebhookEnabled()); - assertNull(aws.getStatus()); - assertNull(aws.getPermissions()); assertNull(aws.getTestString()); assertTrue(aws.equals(awsDuplicate)); @@ -1153,8 +1119,6 @@ public void testAccountGetters() { assertNull(account.getTestArrayOfIntegers()); assertNull(account.getTestArrayOfArrayOfIntegers()); assertNull(account.getTestArrayOfObjects()); - assertNull(account.getXTwilioWebhookEnabled()); - assertNull(account.getStatus()); assertNull(account.getTestString()); assertTrue(account.equals(accountDuplicate)); @@ -1293,18 +1257,6 @@ public void testFeedbackCallSummaryObjectCreationResponseNotSuccess() { creator.create(twilioRestClient); } - @Test - public void testFeedbackCallSummaryVariables() { - FeedbackCallSummary.TestEnum testEnum = FeedbackCallSummary.TestEnum.forValue("DialVerb"); - FeedbackCallSummary.XTwilioWebhookEnabled xTwilioWebhookEnabled = FeedbackCallSummary.XTwilioWebhookEnabled.forValue("true"); - FeedbackCallSummary.Status status = FeedbackCallSummary.Status.forValue("paused"); - FeedbackCallSummary.Permissions permissions = FeedbackCallSummary.Permissions.forValue("get-all"); - - assertEquals("DialVerb", testEnum.toString()); - assertEquals("true", xTwilioWebhookEnabled.toString()); - assertEquals("paused", status.toString()); - assertEquals("get-all", permissions.toString()); - } @Test public void testFeedbackCallSummaryObjectCreationFromString() { @@ -1326,12 +1278,9 @@ public void testFeedbackCallSummaryObjectCreationFromString() { assertNull(feedbackCallSummary.getPriceUnit()); assertEquals(Float.valueOf("123.2"), feedbackCallSummary.getTestNumberFloat()); assertEquals("Trunking", feedbackCallSummary.getTestEnum().toString()); - assertEquals("paused", feedbackCallSummary.getStatus().toString()); assertNull(feedbackCallSummary.getTestArrayOfIntegers()); assertNull(feedbackCallSummary.getTestArrayOfArrayOfIntegers()); assertNull(feedbackCallSummary.getTestArrayOfObjects()); - assertNull(feedbackCallSummary.getXTwilioWebhookEnabled()); - assertNull(feedbackCallSummary.getPermissions()); assertNull(feedbackCallSummary.getTestString()); assertTrue(feedbackCallSummary.equals(feedbackCallSummaryDuplicate));