From 942a0dafb68c1cf9094455e0bc2ca1e91e683be6 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Tue, 30 Apr 2019 01:52:22 -0500 Subject: [PATCH] [Python Connexion Servers] BUGFIX: handle . in package names (#2508) This fixes adding supporting files to packages that have a '.'. If the controllersPackage or modelsPackage has a '.' (eg to put the controllers and/or models in a subpackage of the invokerPackage), supporting controller and models were ending up in directories that included the period instead of converting the periods to file separators. --- .../PythonAbstractConnexionServerCodegen.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java index 8bc5d2b4e8e..e3e9d4ebf65 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java @@ -201,10 +201,10 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme } supportingFiles.add(new SupportingFile("__main__.mustache", packagePath(), "__main__.py")); supportingFiles.add(new SupportingFile("util.mustache", packagePath(), "util.py")); - supportingFiles.add(new SupportingFile("__init__.mustache", packagePath() + File.separatorChar + controllerPackage, "__init__.py")); - supportingFiles.add(new SupportingFile("security_controller_.mustache", packagePath() + File.separatorChar + controllerPackage, "security_controller_.py")); - supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + modelPackage, "__init__.py")); - supportingFiles.add(new SupportingFile("base_model_.mustache", packagePath() + File.separatorChar + modelPackage, "base_model_.py")); + supportingFiles.add(new SupportingFile("__init__.mustache", packagePath() + File.separatorChar + packageToPath(controllerPackage), "__init__.py")); + supportingFiles.add(new SupportingFile("security_controller_.mustache", packagePath() + File.separatorChar + packageToPath(controllerPackage), "security_controller_.py")); + supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + packageToPath(modelPackage), "__init__.py")); + supportingFiles.add(new SupportingFile("base_model_.mustache", packagePath() + File.separatorChar + packageToPath(modelPackage), "base_model_.py")); supportingFiles.add(new SupportingFile("openapi.mustache", packagePath() + File.separatorChar + "openapi", "openapi.yaml")); addSupportingFiles(); @@ -212,6 +212,10 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme controllerPackage = packageName + "." + controllerPackage; } + private static String packageToPath(String pkg) { + return pkg.replace(".", File.separator); + } + private static String dropDots(String str) { return str.replaceAll("\\.", "_"); }