Skip to content

Commit 1ebde9c

Browse files
authored
Merge pull request #9930 from mitchnull/issue-9926
Issue 9926
2 parents 784ec6a + de14de2 commit 1ebde9c

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class CodegenModel {
4040

4141
public Set<String> imports = new TreeSet<String>();
4242
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired, hasOptional, isArrayModel, hasChildren;
43+
public CodegenProperty parentContainer;
4344
public boolean hasOnlyReadOnly = true; // true if all properties are read-only
4445
public ExternalDocs externalDocs;
4546

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class CodegenProperty implements Cloneable {
4646
public List<String> _enum;
4747
public Map<String, Object> allowableValues;
4848
public CodegenProperty items;
49+
public Integer itemsDepth;
4950
public Map<String, Object> vendorExtensions;
5051
public boolean hasValidation; // true if pattern, maximum, etc are set (only used in the mustache template)
5152
public boolean isInherited;

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,12 +1604,24 @@ public String getterAndSetterCapitalize(String name) {
16041604
* @return Codegen Property object
16051605
*/
16061606
public CodegenProperty fromProperty(String name, Property p) {
1607+
return fromProperty(name, p, null);
1608+
}
1609+
/**
1610+
* Convert Swagger Property object to Codegen Property object
1611+
*
1612+
* @param name name of the property
1613+
* @param p Swagger property object
1614+
* @param itemsDepth the depth in nested containers or null
1615+
* @return Codegen Property object
1616+
*/
1617+
private CodegenProperty fromProperty(String name, Property p, Integer itemsDepth) {
16071618
if (p == null) {
16081619
LOGGER.error("unexpected missing property for name " + name);
16091620
return null;
16101621
}
16111622

16121623
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
1624+
property.itemsDepth = itemsDepth;
16131625
property.name = toVarName(name);
16141626
property.baseName = name;
16151627
property.nameInCamelCase = camelize(property.name, false);
@@ -1872,7 +1884,8 @@ public CodegenProperty fromProperty(String name, Property p) {
18721884
if (itemName == null) {
18731885
itemName = property.name;
18741886
}
1875-
CodegenProperty cp = fromProperty(itemName, ap.getItems());
1887+
CodegenProperty cp = fromProperty(itemName, ap.getItems(),
1888+
itemsDepth == null ? 1 : itemsDepth.intValue() + 1);
18761889
updatePropertyForArray(property, cp);
18771890
} else if (p instanceof MapProperty) {
18781891
MapProperty ap = (MapProperty) p;
@@ -1885,7 +1898,8 @@ public CodegenProperty fromProperty(String name, Property p) {
18851898
property.maxItems = ap.getMaxProperties();
18861899

18871900
// handle inner property
1888-
CodegenProperty cp = fromProperty("inner", ap.getAdditionalProperties());
1901+
CodegenProperty cp = fromProperty("inner", ap.getAdditionalProperties(),
1902+
itemsDepth == null ? 1 : itemsDepth.intValue() + 1);
18891903
updatePropertyForMap(property, cp);
18901904
} else {
18911905
setNonArrayMapProperty(property, type);
@@ -3088,10 +3102,10 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
30883102
}
30893103

30903104
private void addParentContainer(CodegenModel m, String name, Property property) {
3091-
final CodegenProperty tmp = fromProperty(name, property);
3092-
addImport(m, tmp.complexType);
3105+
m.parentContainer = fromProperty(name, property);
3106+
addImport(m, m.parentContainer.complexType);
30933107
m.parent = toInstantiationType(property);
3094-
final String containerType = tmp.containerType;
3108+
final String containerType = m.parentContainer.containerType;
30953109
final String instantiationType = instantiationTypes.get(containerType);
30963110
if (instantiationType != null) {
30973111
addImport(m, instantiationType);

0 commit comments

Comments
 (0)