Skip to content

Commit

Permalink
Merge pull request #9930 from mitchnull/issue-9926
Browse files Browse the repository at this point in the history
Issue 9926
  • Loading branch information
HugoMario authored Apr 9, 2020
2 parents 784ec6a + de14de2 commit 1ebde9c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class CodegenModel {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class CodegenProperty implements Cloneable {
public List<String> _enum;
public Map<String, Object> allowableValues;
public CodegenProperty items;
public Integer itemsDepth;
public Map<String, Object> vendorExtensions;
public boolean hasValidation; // true if pattern, maximum, etc are set (only used in the mustache template)
public boolean isInherited;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1604,12 +1604,24 @@ public String getterAndSetterCapitalize(String name) {
* @return Codegen Property object
*/
public CodegenProperty fromProperty(String name, Property p) {
return fromProperty(name, p, null);
}
/**
* Convert Swagger Property object to Codegen Property object
*
* @param name name of the property
* @param p Swagger property object
* @param itemsDepth the depth in nested containers or null
* @return Codegen Property object
*/
private CodegenProperty fromProperty(String name, Property p, Integer itemsDepth) {
if (p == null) {
LOGGER.error("unexpected missing property for name " + name);
return null;
}

CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
property.itemsDepth = itemsDepth;
property.name = toVarName(name);
property.baseName = name;
property.nameInCamelCase = camelize(property.name, false);
Expand Down Expand Up @@ -1872,7 +1884,8 @@ public CodegenProperty fromProperty(String name, Property p) {
if (itemName == null) {
itemName = property.name;
}
CodegenProperty cp = fromProperty(itemName, ap.getItems());
CodegenProperty cp = fromProperty(itemName, ap.getItems(),
itemsDepth == null ? 1 : itemsDepth.intValue() + 1);
updatePropertyForArray(property, cp);
} else if (p instanceof MapProperty) {
MapProperty ap = (MapProperty) p;
Expand All @@ -1885,7 +1898,8 @@ public CodegenProperty fromProperty(String name, Property p) {
property.maxItems = ap.getMaxProperties();

// handle inner property
CodegenProperty cp = fromProperty("inner", ap.getAdditionalProperties());
CodegenProperty cp = fromProperty("inner", ap.getAdditionalProperties(),
itemsDepth == null ? 1 : itemsDepth.intValue() + 1);
updatePropertyForMap(property, cp);
} else {
setNonArrayMapProperty(property, type);
Expand Down Expand Up @@ -3088,10 +3102,10 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
}

private void addParentContainer(CodegenModel m, String name, Property property) {
final CodegenProperty tmp = fromProperty(name, property);
addImport(m, tmp.complexType);
m.parentContainer = fromProperty(name, property);
addImport(m, m.parentContainer.complexType);
m.parent = toInstantiationType(property);
final String containerType = tmp.containerType;
final String containerType = m.parentContainer.containerType;
final String instantiationType = instantiationTypes.get(containerType);
if (instantiationType != null) {
addImport(m, instantiationType);
Expand Down

0 comments on commit 1ebde9c

Please sign in to comment.