From ca1ea8c0f0e22e12f32eb3fb93d27e18708316cd Mon Sep 17 00:00:00 2001 From: sbansla Date: Thu, 27 Apr 2023 08:08:38 +0530 Subject: [PATCH 1/2] chore: remove dependendency on enum constant to identify enum --- src/main/java/com/twilio/oai/CodegenUtils.java | 4 ++-- src/main/java/com/twilio/oai/TwilioGoGenerator.java | 4 ++-- .../java/com/twilio/oai/api/PythonApiResourceBuilder.java | 3 ++- .../resolver/csharp/CsharpCodegenModelDataTypeResolver.java | 3 ++- .../csharp/CsharpCodegenParameterDataTypeResolver.java | 3 ++- .../com/twilio/oai/resolver/php/PhpParameterResolver.java | 3 ++- .../java/com/twilio/oai/resolver/php/PhpPropertyResolver.java | 3 ++- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/twilio/oai/CodegenUtils.java b/src/main/java/com/twilio/oai/CodegenUtils.java index 638926763..12d9d42be 100644 --- a/src/main/java/com/twilio/oai/CodegenUtils.java +++ b/src/main/java/com/twilio/oai/CodegenUtils.java @@ -6,7 +6,7 @@ public class CodegenUtils { public static boolean isPropertySchemaEnum(CodegenProperty codegenProperty) { - if(codegenProperty.isEnum) { + if(codegenProperty.getFormat() != null) { return false; } boolean enumValues = codegenProperty.allowableValues != null && @@ -17,7 +17,7 @@ public static boolean isPropertySchemaEnum(CodegenProperty codegenProperty) { } public static boolean isParameterSchemaEnum(CodegenParameter codegenParameter) { - if(codegenParameter.isEnum) { + if(codegenParameter.getFormat() != null) { return false; } boolean enumValues = codegenParameter.allowableValues != null && diff --git a/src/main/java/com/twilio/oai/TwilioGoGenerator.java b/src/main/java/com/twilio/oai/TwilioGoGenerator.java index cfbb2e806..8cecdcaee 100644 --- a/src/main/java/com/twilio/oai/TwilioGoGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioGoGenerator.java @@ -71,13 +71,13 @@ public ModelsMap postProcessModels(final ModelsMap objs) { @Override public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { super.postProcessModelProperty(model, property); - if (property.dataType.startsWith("[]") && property.dataType.contains("Enum")) { + if (property.dataType.startsWith("[]") && CodegenUtils.isPropertySchemaEnum(property)) { property._enum = (List) property.items.allowableValues.get("values"); property.allowableValues = property.items.allowableValues; property.dataType = "[]" + STRING; property.isEnum = property.dataFormat == null; property.isNullable = true; - } else if (property.dataType.contains("Enum")) { + } else if (CodegenUtils.isPropertySchemaEnum(property)) { property.datatypeWithEnum = Utility.removeEnumName(property.dataType); property.dataType = STRING; property.isEnum = property.dataFormat == null; diff --git a/src/main/java/com/twilio/oai/api/PythonApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/PythonApiResourceBuilder.java index 7458d86ef..44d7ec483 100644 --- a/src/main/java/com/twilio/oai/api/PythonApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/PythonApiResourceBuilder.java @@ -1,5 +1,6 @@ package com.twilio.oai.api; +import com.twilio.oai.CodegenUtils; import com.twilio.oai.DirectoryStructureService; import com.twilio.oai.StringHelper; import com.twilio.oai.common.ApplicationConstants; @@ -53,7 +54,7 @@ public PythonApiResourceBuilder updateResponseModel(final Resolver { - if (variable.complexType != null && !variable.complexType.contains(ApplicationConstants.ENUM)) { + if (variable.complexType != null && !CodegenUtils.isPropertySchemaEnum(variable)) { getModelByClassname(variable.complexType).ifPresent(model -> { variable.baseType = variable.baseType.replace(variable.datatypeWithEnum, "str"); variable.datatypeWithEnum = "str"; diff --git a/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java b/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java index 44fdd65d6..bf9c9d37c 100644 --- a/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java +++ b/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenModelDataTypeResolver.java @@ -1,5 +1,6 @@ package com.twilio.oai.resolver.csharp; +import com.twilio.oai.CodegenUtils; import com.twilio.oai.StringHelper; import com.twilio.oai.common.ApplicationConstants; import com.twilio.oai.common.Utility; @@ -35,7 +36,7 @@ private void resolveEnum(CodegenProperty property) { } OperationStore operationStore = OperationStore.getInstance(); - if (property.complexType == null || !property.complexType.contains("Enum")) { + if (property.complexType == null || !CodegenUtils.isPropertySchemaEnum(property)) { if (property.dataType != null) { Optional importStm = mapper.libraries().get(StringHelper.toSnakeCase(property.dataType).replace("_", "-")); if (importStm.isPresent() && importStm.get() instanceof String && importStm.get().equals("Twilio.Types")) { diff --git a/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenParameterDataTypeResolver.java b/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenParameterDataTypeResolver.java index 45c6ac09c..c3f7783f1 100644 --- a/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenParameterDataTypeResolver.java +++ b/src/main/java/com/twilio/oai/resolver/csharp/CsharpCodegenParameterDataTypeResolver.java @@ -1,5 +1,6 @@ package com.twilio.oai.resolver.csharp; +import com.twilio.oai.CodegenUtils; import com.twilio.oai.StringHelper; import com.twilio.oai.common.ApplicationConstants; import com.twilio.oai.common.Utility; @@ -34,7 +35,7 @@ private void resolveEnum(CodegenParameter parameter) { } return; } - if (parameter.dataType.contains(ApplicationConstants.ENUM)) { + if (CodegenUtils.isParameterSchemaEnum(parameter)) { parameter.isEnum = true; parameter.enumName = Utility.removeEnumName(parameter.dataType) + ApplicationConstants.ENUM; } diff --git a/src/main/java/com/twilio/oai/resolver/php/PhpParameterResolver.java b/src/main/java/com/twilio/oai/resolver/php/PhpParameterResolver.java index 089c1b886..16240a1ae 100644 --- a/src/main/java/com/twilio/oai/resolver/php/PhpParameterResolver.java +++ b/src/main/java/com/twilio/oai/resolver/php/PhpParameterResolver.java @@ -1,5 +1,6 @@ package com.twilio.oai.resolver.php; +import com.twilio.oai.CodegenUtils; import com.twilio.oai.resolver.IConventionMapper; import com.twilio.oai.resolver.LanguageConventionResolver; import com.twilio.oai.resolver.LanguageParamResolver; @@ -37,7 +38,7 @@ public void resolveProperties(CodegenParameter codegenParameter) { codegenParameter.dataType.equals(LanguageConventionResolver.LIST_OBJECT)) { codegenParameter.dataType = ARRAY; } - if (codegenParameter.dataType.contains("Enum") || codegenParameter.dataType.equals(FLOAT)) { + if (CodegenUtils.isParameterSchemaEnum(codegenParameter) || codegenParameter.dataType.equals(FLOAT)) { codegenParameter.dataType = STRING; } if (codegenParameter.dataType.equals(STRING)) { diff --git a/src/main/java/com/twilio/oai/resolver/php/PhpPropertyResolver.java b/src/main/java/com/twilio/oai/resolver/php/PhpPropertyResolver.java index 699830e72..6d65f71bb 100644 --- a/src/main/java/com/twilio/oai/resolver/php/PhpPropertyResolver.java +++ b/src/main/java/com/twilio/oai/resolver/php/PhpPropertyResolver.java @@ -1,5 +1,6 @@ package com.twilio.oai.resolver.php; +import com.twilio.oai.CodegenUtils; import com.twilio.oai.StringHelper; import com.twilio.oai.resolver.IConventionMapper; import com.twilio.oai.resolver.LanguageConventionResolver; @@ -45,7 +46,7 @@ public void resolveProperties(CodegenProperty codegenProperty) { if (codegenProperty.dataType.equals(LanguageConventionResolver.LIST_OBJECT)) { codegenProperty.dataType = ARRAY; } - if (codegenProperty.dataType.contains("Enum") || codegenProperty.complexType != null) { + if (codegenProperty.complexType != null || CodegenUtils.isPropertySchemaEnum(codegenProperty)) { if (codegenProperty.openApiType.equals(ARRAY)) { codegenProperty.dataType = STRING + "[]"; } else if (codegenProperty.openApiType.equals(STRING) || codegenProperty.dataType.contains(OPEN_API_STRING)) { From 89cf19c97bbfbfbd684ed566d36e32a388ba0117 Mon Sep 17 00:00:00 2001 From: sbansla Date: Thu, 27 Apr 2023 08:41:43 +0530 Subject: [PATCH 2/2] chore: go enum changes --- src/main/java/com/twilio/oai/TwilioGoGenerator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/twilio/oai/TwilioGoGenerator.java b/src/main/java/com/twilio/oai/TwilioGoGenerator.java index 8cecdcaee..15faf7273 100644 --- a/src/main/java/com/twilio/oai/TwilioGoGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioGoGenerator.java @@ -86,13 +86,13 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert } private void processEnumParameters(final CodegenParameter parameter) { - if (parameter.dataType.startsWith("[]") && parameter.dataType.contains("Enum")) { + if (parameter.dataType.startsWith("[]") && CodegenUtils.isParameterSchemaEnum(parameter)) { parameter._enum = (List) parameter.items.allowableValues.get("values"); parameter.allowableValues = parameter.items.allowableValues; parameter.dataType = "[]" + STRING; parameter.isEnum = parameter.dataFormat == null; parameter.isNullable = true; - } else if (parameter.dataType.contains("Enum")) { + } else if (CodegenUtils.isParameterSchemaEnum(parameter)) { parameter.datatypeWithEnum = Utility.removeEnumName(parameter.dataType); parameter.dataType = STRING; parameter.isEnum = parameter.dataFormat == null;