Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Nextgen enum changes #491

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/twilio/oai/CodegenUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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 &&
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/twilio/oai/TwilioGoGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) 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;
Expand All @@ -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<String>) 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -53,7 +54,7 @@ public PythonApiResourceBuilder updateResponseModel(final Resolver<CodegenProper

if (responseModel != null) {
responseModel.getVars().forEach(variable -> {
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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Object> importStm = mapper.libraries().get(StringHelper.toSnakeCase(property.dataType).replace("_", "-"));
if (importStm.isPresent() && importStm.get() instanceof String && importStm.get().equals("Twilio.Types")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down