forked from loafle/openapi-generator-original
Fixes test folder cleaning in python-exp only (#12825)
* Adds test folder file removal in python-exp only * Samples regnerated * Removes unused code, tweaks unit test sample to test PR change * Reverts spec change * FIxes javadoc
This commit is contained in:
parent
574f6f3192
commit
84ac06abdc
@ -53,11 +53,7 @@ if [[ ${#files[@]} -eq 1 && "${files[0]}" != *'*'* ]]; then
|
||||
java ${JAVA_OPTS} -jar "$executable" generate -c ${files[0]} ${args[@]}
|
||||
else
|
||||
echo "Please press CTRL+C to stop or the script will continue in 5 seconds."
|
||||
|
||||
sleep 5
|
||||
# delete the 3_0_3 python-experimental tests because they are autogenerated our tooling needs to see differences
|
||||
rm -rf "${root}/samples/openapi3/client/3_0_3_unit_test/python-experimental/test"
|
||||
|
||||
if [ ${#files[@]} -eq 0 ]; then
|
||||
files=("${root}"/bin/configs/*.yaml)
|
||||
fi
|
||||
|
@ -25,6 +25,7 @@ import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import io.swagger.v3.oas.models.tags.Tag;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.openapitools.codegen.api.TemplatePathLocator;
|
||||
import org.openapitools.codegen.ignore.CodegenIgnoreProcessor;
|
||||
import org.openapitools.codegen.model.ModelMap;
|
||||
@ -740,6 +741,7 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
|
||||
* this means that the generated client does not use these models
|
||||
* because they are not used we do not write them
|
||||
* - fix the model imports, go from model name to the full import string with toModelImport + globalImportFixer
|
||||
* Also cleans the test folder if test cases exist and the testFolder is set because the tests are autogenerated
|
||||
*
|
||||
* @param objs a map going from the model name to a object hoding the model info
|
||||
* @return the updated objs
|
||||
@ -748,6 +750,7 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
|
||||
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
|
||||
super.postProcessAllModels(objs);
|
||||
|
||||
boolean anyModelContainsTestCases = false;
|
||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
||||
for (String schemaName : allDefinitions.keySet()) {
|
||||
Schema refSchema = new Schema().$ref("#/components/schemas/" + schemaName);
|
||||
@ -755,20 +758,36 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
|
||||
String modelName = toModelName(schemaName);
|
||||
if (unaliasedSchema.get$ref() == null) {
|
||||
continue;
|
||||
} else {
|
||||
ModelsMap objModel = objs.get(modelName);
|
||||
if (objModel != null) { // to avoid form parameter's models that are not generated (skipFormModel=true)
|
||||
for (ModelMap model : objModel.getModels()) {
|
||||
CodegenModel cm = model.getModel();
|
||||
String[] importModelNames = cm.imports.toArray(new String[0]);
|
||||
cm.imports.clear();
|
||||
for (String importModelName : importModelNames) {
|
||||
cm.imports.add(toModelImport(importModelName));
|
||||
}
|
||||
}
|
||||
}
|
||||
ModelsMap objModel = objs.get(modelName);
|
||||
if (objModel == null) {
|
||||
// to avoid form parameter's models that are not generated (skipFormModel=true)
|
||||
continue;
|
||||
}
|
||||
for (ModelMap model : objModel.getModels()) {
|
||||
CodegenModel cm = model.getModel();
|
||||
if (cm.testCases != null && !cm.testCases.isEmpty()) {
|
||||
anyModelContainsTestCases = true;
|
||||
}
|
||||
String[] importModelNames = cm.imports.toArray(new String[0]);
|
||||
cm.imports.clear();
|
||||
for (String importModelName : importModelNames) {
|
||||
cm.imports.add(toModelImport(importModelName));
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean testFolderSet = testFolder != null;
|
||||
if (testFolderSet && anyModelContainsTestCases) {
|
||||
// delete the test folder because tests there will be autogenerated
|
||||
String modelTestFolder = modelTestFileFolder();
|
||||
File testDirectory = new File(modelTestFolder);
|
||||
try {
|
||||
FileUtils.cleanDirectory(testDirectory);
|
||||
} catch (IOException e) {
|
||||
LOGGER.info("Unable to delete the test folder because of exception=" + e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user