Skip to content

Commit 99bc3c3

Browse files
authored
Merge pull request #996 from Backbase/MF-2088-BOAT-ios-content-services-not-compiling
Fix: Nested freeform objects generating broken models
2 parents 1529a62 + d1fd992 commit 99bc3c3

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ It currently consists of
1414

1515
# Release Notes
1616
BOAT is still under development and subject to change.
17+
## 0.17.55
18+
* Enhanced `boat-swift5` generator to cater for nested freeformObjects. This issue was identified in `ContentServicesApi`
1719
## 0.17.54 and later
1820
Starting from 0.17.54 the release notes are available at https://github.com/Backbase/backbase-openapi-tools/releases
1921
## 0.17.53

boat-scaffold/src/main/java/org/openapitools/codegen/languages/BoatSwift5Codegen.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class BoatSwift5Codegen extends Swift5ClientCodegen implements CodegenCon
2121
protected static final String DEPENDENCY_MANAGEMENT_CARTFILE = "Cartfile";
2222
protected static final String[] DEPENDENCY_MANAGEMENT_OPTIONS = {DEPENDENCY_MANAGEMENT_CARTFILE, DEPENDENCY_MANAGEMENT_PODFILE};
2323
protected static final String MODULE_NAME = "moduleName";
24+
protected static final String NESTED_STRING_ANY_DICTIONARY = "[String: [String: Any]]";
25+
protected static final String STRING_ANY_DICTIONARY = "[String: Any]";
2426
protected String[] dependenciesAs = new String[0];
2527

2628
/**
@@ -143,6 +145,12 @@ private void fixFreeFormObject(List<CodegenProperty> codegenProperties) {
143145
codegenProperty.isMap = false;
144146
}
145147
}
148+
149+
if (hasNestedStringAnyDictionary(codegenProperty)) {
150+
codegenProperty.isFreeFormObject = true;
151+
codegenProperty.setDataType(STRING_ANY_DICTIONARY);
152+
codegenProperty.setDatatypeWithEnum(STRING_ANY_DICTIONARY);
153+
}
146154
}
147155
}
148156

@@ -211,6 +219,20 @@ private String sanitize(String projectName) {
211219
return projName;
212220
}
213221

222+
/*
223+
Helper method to check whether a codegenProperty has nested additional properties
224+
*/
225+
private boolean hasNestedAdditionalProperties(CodegenProperty codegenProperty) {
226+
return codegenProperty.isMap
227+
&& codegenProperty.additionalProperties != null
228+
&& codegenProperty.getAdditionalProperties().isContainer
229+
&& !codegenProperty.getAdditionalProperties().isArray;
230+
}
231+
232+
private boolean hasNestedStringAnyDictionary(CodegenProperty codegenProperty) {
233+
return hasNestedAdditionalProperties(codegenProperty) && codegenProperty.getDataType().equals(NESTED_STRING_ANY_DICTIONARY);
234+
}
235+
214236
@Override
215237
public void postProcess() {
216238
System.out.println("################################################################################");

boat-scaffold/src/test/java/org/openapitools/codegen/languages/BoatSwift5CodegenTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void testFromModelCodegenModel() {
204204
assertEquals(cm.name, "sample");
205205
assertEquals(cm.classname, "Sample");
206206
assertEquals(cm.description, "a sample model");
207-
assertEquals(cm.vars.size(), 6);
207+
assertEquals(cm.vars.size(), 7);
208208
assertEquals(cm.getDiscriminatorName(), "test");
209209
}
210210

@@ -380,6 +380,12 @@ private CodegenModel prepareForModelTests() {
380380
mapSchema1.setDescription("Sample ObjectSchema");
381381
mapSchema1.additionalProperties(new StringSchema());
382382

383+
final ObjectSchema oneLevelNestedObjectSchema = new ObjectSchema();
384+
final ObjectSchema nestedObjectSchema = new ObjectSchema();
385+
nestedObjectSchema.additionalProperties(oneLevelNestedObjectSchema);
386+
final ObjectSchema objectSchema1 = new ObjectSchema();
387+
objectSchema1.additionalProperties(nestedObjectSchema);
388+
383389
final Schema schema = new Schema()
384390
.description("a sample model")
385391
.addProperty("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT))
@@ -388,6 +394,7 @@ private CodegenModel prepareForModelTests() {
388394
.addProperty("nested", nestedArraySchema)
389395
.addProperty("map", mapSchema)
390396
.addProperty("secondMap", mapSchema1)
397+
.addProperty("link", objectSchema1)
391398
.addRequiredItem("id")
392399
.addRequiredItem("name")
393400
.name("sample")

0 commit comments

Comments
 (0)