From 39bb8690966ba6ae7cccc698de753d69f76aa26e Mon Sep 17 00:00:00 2001 From: Sai Giridhar P Date: Thu, 23 May 2019 13:49:36 +0530 Subject: [PATCH 1/5] feat(python): Support package names with dots --- .../codegen/languages/PythonClientCodegen.java | 13 ++++++++++++- .../{__init__test.mustache => __init__.mustache} | 0 2 files changed, 12 insertions(+), 1 deletion(-) rename modules/openapi-generator/src/main/resources/python/{__init__test.mustache => __init__.mustache} (100%) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index 66ed01279a94..0f0980063824 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -240,10 +240,21 @@ public void processOpts() { supportingFiles.add(new SupportingFile("__init__package.mustache", packagePath(), "__init__.py")); supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + modelPackage, "__init__.py")); supportingFiles.add(new SupportingFile("__init__api.mustache", packagePath() + File.separatorChar + apiPackage, "__init__.py")); + + String[] packageNameSplits = packageName.split("\\."); + String currentPackagePath = ""; + for (int i = 0; i < packageNameSplits.length-1; i++) { + if (i > 0) { + currentPackagePath = currentPackagePath + File.separatorChar; + } + currentPackagePath = currentPackagePath + packageNameSplits[i]; + supportingFiles.add(new SupportingFile("__init__.mustache", currentPackagePath, "__init__.py")); + } + supportingFiles.add(new SupportingFile("exceptions.mustache", packagePath(), "exceptions.py")); if (Boolean.FALSE.equals(excludeTests)) { - supportingFiles.add(new SupportingFile("__init__test.mustache", testFolder, "__init__.py")); + supportingFiles.add(new SupportingFile("__init__.mustache", testFolder, "__init__.py")); } supportingFiles.add(new SupportingFile("api_client.mustache", packagePath(), "api_client.py")); diff --git a/modules/openapi-generator/src/main/resources/python/__init__test.mustache b/modules/openapi-generator/src/main/resources/python/__init__.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/python/__init__test.mustache rename to modules/openapi-generator/src/main/resources/python/__init__.mustache From 2b1ed3b8ec4e439c2875edbe827b2af54d16e77e Mon Sep 17 00:00:00 2001 From: Sai Giridhar P Date: Thu, 23 May 2019 19:20:20 +0530 Subject: [PATCH 2/5] feat(python): Fixing tests --- .../codegen/languages/PythonClientCodegen.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index 0f0980063824..0cb5309213fd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -41,8 +41,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig public static final String PACKAGE_URL = "packageUrl"; public static final String DEFAULT_LIBRARY = "urllib3"; - protected String packageName; // e.g. petstore_api - protected String packageVersion; + protected String packageName = "openapi_client"; // e.g. petstore_api + protected String packageVersion = "1.0.0"; protected String projectName; // for setup.py, e.g. petstore-api protected String packageUrl; protected String apiDocPath = "docs/"; @@ -176,8 +176,6 @@ public void processOpts() { if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) { setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME)); - } else { - setPackageName("openapi_client"); } if (additionalProperties.containsKey(CodegenConstants.PROJECT_NAME)) { @@ -190,9 +188,7 @@ public void processOpts() { if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) { setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION)); - } else { - setPackageVersion("1.0.0"); - } + } Boolean generateSourceCodeOnly = false; if (additionalProperties.containsKey(CodegenConstants.SOURCECODEONLY_GENERATION)) { From 4aeee7a4a334fb8ec69bbf52ebb2a61b56a36d38 Mon Sep 17 00:00:00 2001 From: Sai Giridhar P Date: Fri, 24 May 2019 21:32:55 +0530 Subject: [PATCH 3/5] feat(python): Adding comment --- .../org/openapitools/codegen/languages/PythonClientCodegen.java | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index 0cb5309213fd..aed866bf1862 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -237,6 +237,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + modelPackage, "__init__.py")); supportingFiles.add(new SupportingFile("__init__api.mustache", packagePath() + File.separatorChar + apiPackage, "__init__.py")); + // If the package name consists of dots(openapi.client), then we need to create the directory structure like openapi/client with __init__ files. String[] packageNameSplits = packageName.split("\\."); String currentPackagePath = ""; for (int i = 0; i < packageNameSplits.length-1; i++) { From b23bec02e15e8a4901110eae5e8363ccc6804fd3 Mon Sep 17 00:00:00 2001 From: Sai Giridhar P Date: Fri, 24 May 2019 22:04:50 +0530 Subject: [PATCH 4/5] fix(python): Fixing indentation --- .../openapitools/codegen/languages/PythonClientCodegen.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index aed866bf1862..a49e17f32be5 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -41,7 +41,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig public static final String PACKAGE_URL = "packageUrl"; public static final String DEFAULT_LIBRARY = "urllib3"; - protected String packageName = "openapi_client"; // e.g. petstore_api + protected String packageName = "openapi_client"; protected String packageVersion = "1.0.0"; protected String projectName; // for setup.py, e.g. petstore-api protected String packageUrl; @@ -237,7 +237,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + modelPackage, "__init__.py")); supportingFiles.add(new SupportingFile("__init__api.mustache", packagePath() + File.separatorChar + apiPackage, "__init__.py")); - // If the package name consists of dots(openapi.client), then we need to create the directory structure like openapi/client with __init__ files. + // If the package name consists of dots(openapi.client), then we need to create the directory structure like openapi/client with __init__ files. String[] packageNameSplits = packageName.split("\\."); String currentPackagePath = ""; for (int i = 0; i < packageNameSplits.length-1; i++) { From 0f3eafb06f05fd4ae77ca139c5195e45c280ff9e Mon Sep 17 00:00:00 2001 From: Sai Giridhar P Date: Fri, 24 May 2019 22:18:33 +0530 Subject: [PATCH 5/5] fix(python): Fixing indentation --- .../openapitools/codegen/languages/PythonClientCodegen.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index a49e17f32be5..8f28acb3695c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -236,7 +236,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("__init__package.mustache", packagePath(), "__init__.py")); supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + modelPackage, "__init__.py")); supportingFiles.add(new SupportingFile("__init__api.mustache", packagePath() + File.separatorChar + apiPackage, "__init__.py")); - + // If the package name consists of dots(openapi.client), then we need to create the directory structure like openapi/client with __init__ files. String[] packageNameSplits = packageName.split("\\."); String currentPackagePath = ""; @@ -247,7 +247,7 @@ public void processOpts() { currentPackagePath = currentPackagePath + packageNameSplits[i]; supportingFiles.add(new SupportingFile("__init__.mustache", currentPackagePath, "__init__.py")); } - + supportingFiles.add(new SupportingFile("exceptions.mustache", packagePath(), "exceptions.py")); if (Boolean.FALSE.equals(excludeTests)) {