Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,37 @@ private void patchPropertyVendorExtensions(CodegenProperty property) {
protected void patchPropertyIsInherited(CodegenModel model, CodegenProperty property) {
}

private void patchNestedMaps(CodegenProperty property) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: adding a docstring explaining what this function does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge this and ill send a docstring in the next pr? Ive got three or four others queued up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure bro

// Process nested types before making any replacements to ensure we have the correct inner type
if (property.items != null) {
patchNestedMaps(property.items);
}

String[] nestedTypes = {"List", "Collection", "ICollection", "Dictionary"};

if (property.datatypeWithEnum != null) {
String originalType = property.datatypeWithEnum;

for (String nestedType : nestedTypes) {
// fix incorrect data types for maps of maps
if (property.items != null) {
if (property.datatypeWithEnum.contains(", " + nestedType + ">")) {
property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + nestedType + ">", ", " + property.items.datatypeWithEnum + ">");
}

if (property.datatypeWithEnum.contains("<" + nestedType + ">")) {
property.datatypeWithEnum = property.datatypeWithEnum.replace("<" + nestedType + ">", "<" + property.items.datatypeWithEnum + ">");
}
}
}

// Only update dataType if we actually made changes
if (!originalType.equals(property.datatypeWithEnum)) {
property.dataType = property.datatypeWithEnum;
}
}
}

protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel model, CodegenProperty property) {
if (enumRefs.containsKey(property.dataType)) {
// Handle any enum properties referred to by $ref.
Expand All @@ -770,20 +801,7 @@ protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel mo

property.name = patchPropertyName(model, property.name, null);

String[] nestedTypes = {"List", "Collection", "ICollection", "Dictionary"};

Arrays.stream(nestedTypes).forEach(nestedType -> {
// fix incorrect data types for maps of maps
if (property.datatypeWithEnum.contains(", " + nestedType + ">") && property.items != null) {
property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + nestedType + ">", ", " + property.items.datatypeWithEnum + ">");
property.dataType = property.datatypeWithEnum;
}

if (property.datatypeWithEnum.contains("<" + nestedType + ">") && property.items != null) {
property.datatypeWithEnum = property.datatypeWithEnum.replace("<" + nestedType + ">", "<" + property.items.datatypeWithEnum + ">");
property.dataType = property.datatypeWithEnum;
}
});
patchNestedMaps(property);

// HOTFIX: https://github.com/OpenAPITools/openapi-generator/issues/14944
if (property.datatypeWithEnum.equals("decimal")) {
Expand Down
Loading