From e90fa5c4df00d7c568e95a43afc152ad68950d37 Mon Sep 17 00:00:00 2001 From: Josh Burton Date: Sun, 22 Dec 2019 21:05:32 +1300 Subject: [PATCH] Fixes issue where only some instances of List or Map were replaced with Built equivalents (#4645) If there was a type that had a nested type of List or Map, e.g. `Map>` only the outer types would be replaced with the Built variants, causing issues when running the builder. --- .../languages/DartDioClientCodegen.java | 49 +++++++------------ .../main/resources/dart-dio/class.mustache | 2 - 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java index 764a0ddac9e..66fc2a468fd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java @@ -285,37 +285,26 @@ public class DartDioClientCodegen extends DartClientCodegen { property.isNullable = true; } - if (property.isListContainer) { - //Updates any List properties on a model to a BuiltList. This happens in post processing rather - //than type mapping as we only want this to apply to models, not every other class. - if ("List".equals(property.baseType)) { - property.setDatatype( - property.dataType.replaceAll(property.baseType, "BuiltList")); - property.setBaseType("BuiltList"); - model.imports.add("BuiltList"); - if ("Object".equals(property.items.baseType)) { - property.setDatatype( - property.dataType.replaceAll("Object", "JsonObject")); - property.items.setDatatype("JsonObject"); - model.imports.add("JsonObject"); - } - } - } - if (property.isMapContainer) { - //Updates any List properties on a model to a BuiltList. This happens in post processing rather - //than type mapping as we only want this to apply to models, not every other class. - if ("Map".equals(property.baseType)) { - property.setDatatype(property.dataType.replaceAll(property.baseType, "BuiltMap")); - property.setBaseType("BuiltMap"); - model.imports.add("BuiltMap"); - if ("Object".equals(property.items.baseType)) { - property.setDatatype(property.dataType.replaceAll("Object", "JsonObject")); - property.items.setDatatype("JsonObject"); - model.imports.add("JsonObject"); - } - } - } + property.setDatatype(property.getDataType() + .replaceAll("\\bList\\b", "BuiltList") + .replaceAll("\\bMap\\b", "BuiltMap") + .replaceAll("\\bObject\\b", "JsonObject") + ); + property.setBaseType(property.getBaseType() + .replaceAll("\\bList\\b", "BuiltList") + .replaceAll("\\bMap\\b", "BuiltMap") + .replaceAll("\\bObject\\b", "JsonObject") + ); + if (property.dataType.contains("BuiltList")) { + model.imports.add("BuiltList"); + } + if (property.dataType.contains("BuiltMap")) { + model.imports.add("BuiltMap"); + } + if (property.dataType.contains("JsonObject")) { + model.imports.add("JsonObject"); + } } @Override diff --git a/modules/openapi-generator/src/main/resources/dart-dio/class.mustache b/modules/openapi-generator/src/main/resources/dart-dio/class.mustache index cf95d3ce0eb..c7e26935d34 100644 --- a/modules/openapi-generator/src/main/resources/dart-dio/class.mustache +++ b/modules/openapi-generator/src/main/resources/dart-dio/class.mustache @@ -10,8 +10,6 @@ abstract class {{classname}} implements Built<{{classname}}, {{classname}}Builde {{#isNullable}} @nullable {{/isNullable}} - - {{#description}}/* {{{description}}} */{{/description}} @BuiltValueField(wireName: '{{baseName}}') {{{dataType}}} get {{name}}; {{#allowableValues}}