mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-18 05:19:16 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user