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

fix: handling nested enum correctly in python #589

Merged
merged 3 commits into from
Jun 27, 2024
Merged
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
10 changes: 7 additions & 3 deletions src/main/java/com/twilio/oai/CodegenUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public static boolean isPropertySchemaEnum(CodegenProperty codegenProperty) {
codegenProperty.allowableValues.containsKey(TwilioJavaGenerator.VALUES);
boolean listEnumValues = codegenProperty.items != null && (codegenProperty.items.allowableValues != null
&& codegenProperty.items.allowableValues.containsKey(TwilioJavaGenerator.VALUES));
return enumValues || listEnumValues;
boolean isEnum = enumValues || listEnumValues;
codegenProperty.vendorExtensions.put("x-enum-object", isEnum);
return isEnum;
}

public static boolean isParameterSchemaEnum(CodegenParameter codegenParameter) {
Expand All @@ -38,7 +40,9 @@ public static boolean isParameterSchemaEnum(CodegenParameter codegenParameter) {
codegenParameter.allowableValues.containsKey(TwilioJavaGenerator.VALUES);
boolean listEnumValues = codegenParameter.items != null && (codegenParameter.items.allowableValues != null
&& codegenParameter.items.allowableValues.containsKey(TwilioJavaGenerator.VALUES));
return enumValues || listEnumValues;
boolean isEnum = enumValues || listEnumValues;
codegenParameter.vendorExtensions.put("x-enum-object", isEnum);
return isEnum;
}

// TODO: Refactor java code.
Expand Down Expand Up @@ -103,4 +107,4 @@ public static boolean isPredefinedEnum(CodegenParameter codegenParameter) {
}
return false;
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/twilio-python/modelClasses.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
def to_dict(self):
return {
{{#vars}}
"{{{vendorExtensions.json-name}}}": {{#if complexType}}{{#containerType}}[{{name}}.to_dict() for {{name}} in self.{{name}}]{{/containerType}}{{^containerType}}self.{{name}}.to_dict(){{/containerType}}{{else}}self.{{name}}{{/if}},{{/vars}}
"{{{vendorExtensions.json-name}}}": {{#if complexType}}{{#containerType}}[{{name}}.to_dict() for {{name}} in self.{{name}}]{{/containerType}}{{^containerType}}self.{{name}}{{^vendorExtensions.x-enum-object}}.to_dict(){{/vendorExtensions.x-enum-object}}{{/containerType}}{{else}}self.{{name}}{{/if}},{{/vars}}
}
{{/hasVars}}{{/vendorExtensions.part-of-response-model}}{{/models}}
Loading