Add process utils class to add index to properties (#1796)

* add process utils to add index to properties

* fix javadoc warning
This commit is contained in:
William Cheng
2019-01-03 16:06:22 +08:00
committed by GitHub
parent 92db181d97
commit ad5184efc1
13 changed files with 85 additions and 37 deletions

View File

@@ -29,6 +29,7 @@ import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.utils.ModelUtils;
import org.openapitools.codegen.utils.ProcessUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -425,6 +426,16 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
index++;
}
}
return objs;
}
@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
List<Object> models = (List<Object>) objs.get("models");
// add x-index to properties
ProcessUtils.addIndexToProperties(models);
return objs;
}
}

View File

@@ -0,0 +1,37 @@
package org.openapitools.codegen.utils;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenProperty;
import java.util.List;
import java.util.Map;
public class ProcessUtils {
/**
* Add x-index extension to the model's properties
*
* @param models List of models
*/
public static void addIndexToProperties(List<Object> models) {
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");
int i = 0;
for (CodegenProperty var : cm.vars) {
var.vendorExtensions.put("x-index", i);
i++;
}
int j = 0;
for (CodegenProperty var : cm.allVars) {
var.vendorExtensions.put("x-index", j);
j++;
}
}
}
}