Skip to content

Commit 29ad76a

Browse files
svenpannewing328
authored andcommitted
[python-flask] [python-aiohttp] [bug] Fixed handling of dotted module names (OpenAPITools#2041)
Previously, if you used a packageName of the form "foo.bar.baz", half of the generated files of the python generator went into a subdirectory "foo/bar/baz" (correct), the other half went into a subdirectory "foo.bar.baz" (incorrect).
1 parent c99ecd9 commit 29ad76a

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ public void processOpts() {
199199
additionalProperties.put(SUPPORT_PYTHON2, Boolean.TRUE);
200200
typeMapping.put("long", "long");
201201
}
202-
supportingFiles.add(new SupportingFile("__main__.mustache", packageName, "__main__.py"));
203-
supportingFiles.add(new SupportingFile("util.mustache", packageName, "util.py"));
204-
supportingFiles.add(new SupportingFile("__init__.mustache", packageName + File.separatorChar + controllerPackage, "__init__.py"));
205-
supportingFiles.add(new SupportingFile("security_controller_.mustache", packageName + File.separatorChar + controllerPackage, "security_controller_.py"));
206-
supportingFiles.add(new SupportingFile("__init__model.mustache", packageName + File.separatorChar + modelPackage, "__init__.py"));
207-
supportingFiles.add(new SupportingFile("base_model_.mustache", packageName + File.separatorChar + modelPackage, "base_model_.py"));
208-
supportingFiles.add(new SupportingFile("openapi.mustache", packageName + File.separatorChar + "openapi", "openapi.yaml"));
202+
supportingFiles.add(new SupportingFile("__main__.mustache", packagePath(), "__main__.py"));
203+
supportingFiles.add(new SupportingFile("util.mustache", packagePath(), "util.py"));
204+
supportingFiles.add(new SupportingFile("__init__.mustache", packagePath() + File.separatorChar + controllerPackage, "__init__.py"));
205+
supportingFiles.add(new SupportingFile("security_controller_.mustache", packagePath() + File.separatorChar + controllerPackage, "security_controller_.py"));
206+
supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + modelPackage, "__init__.py"));
207+
supportingFiles.add(new SupportingFile("base_model_.mustache", packagePath() + File.separatorChar + modelPackage, "base_model_.py"));
208+
supportingFiles.add(new SupportingFile("openapi.mustache", packagePath() + File.separatorChar + "openapi", "openapi.yaml"));
209209
addSupportingFiles();
210210

211211
modelPackage = packageName + "." + modelPackage;
@@ -714,6 +714,9 @@ public void setPackageVersion(String packageVersion) {
714714
this.packageVersion = packageVersion;
715715
}
716716

717+
public String packagePath() {
718+
return packageName.replace('.', File.separatorChar);
719+
}
717720

718721
@Override
719722
public String escapeQuotationMark(String input) {

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAiohttpConnexionServerCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public String getName() {
4343
protected void addSupportingFiles() {
4444
supportingFiles.add(new SupportingFile("conftest.mustache", testPackage, "conftest.py"));
4545
supportingFiles.add(new SupportingFile("__init__test.mustache", testPackage, "__init__.py"));
46-
supportingFiles.add(new SupportingFile("__init__main.mustache", packageName, "__init__.py"));
46+
supportingFiles.add(new SupportingFile("__init__main.mustache", packagePath(), "__init__.py"));
4747
}
4848
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ protected void addSupportingFiles() {
4949
supportingFiles.add(new SupportingFile("tox.mustache", "", "tox.ini"));
5050
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
5151
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
52-
supportingFiles.add(new SupportingFile("encoder.mustache", packageName, "encoder.py"));
53-
supportingFiles.add(new SupportingFile("__init__test.mustache", packageName + File.separatorChar + testPackage, "__init__.py"));
54-
supportingFiles.add(new SupportingFile("__init__.mustache", packageName, "__init__.py"));
52+
supportingFiles.add(new SupportingFile("encoder.mustache", packagePath(), "encoder.py"));
53+
supportingFiles.add(new SupportingFile("__init__test.mustache", packagePath() + File.separatorChar + testPackage, "__init__.py"));
54+
supportingFiles.add(new SupportingFile("__init__.mustache", packagePath(), "__init__.py"));
5555
testPackage = packageName + "." + testPackage;
5656
}
5757
}

0 commit comments

Comments
 (0)