@@ -41,8 +41,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
41
41
public static final String PACKAGE_URL = "packageUrl" ;
42
42
public static final String DEFAULT_LIBRARY = "urllib3" ;
43
43
44
- protected String packageName ; // e.g. petstore_api
45
- protected String packageVersion ;
44
+ protected String packageName = "openapi_client" ;
45
+ protected String packageVersion = "1.0.0" ;
46
46
protected String projectName ; // for setup.py, e.g. petstore-api
47
47
protected String packageUrl ;
48
48
protected String apiDocPath = "docs/" ;
@@ -177,8 +177,6 @@ public void processOpts() {
177
177
178
178
if (additionalProperties .containsKey (CodegenConstants .PACKAGE_NAME )) {
179
179
setPackageName ((String ) additionalProperties .get (CodegenConstants .PACKAGE_NAME ));
180
- } else {
181
- setPackageName ("openapi_client" );
182
180
}
183
181
184
182
if (additionalProperties .containsKey (CodegenConstants .PROJECT_NAME )) {
@@ -191,9 +189,7 @@ public void processOpts() {
191
189
192
190
if (additionalProperties .containsKey (CodegenConstants .PACKAGE_VERSION )) {
193
191
setPackageVersion ((String ) additionalProperties .get (CodegenConstants .PACKAGE_VERSION ));
194
- } else {
195
- setPackageVersion ("1.0.0" );
196
- }
192
+ }
197
193
198
194
Boolean generateSourceCodeOnly = false ;
199
195
if (additionalProperties .containsKey (CodegenConstants .SOURCECODEONLY_GENERATION )) {
@@ -241,10 +237,22 @@ public void processOpts() {
241
237
supportingFiles .add (new SupportingFile ("__init__package.mustache" , packagePath (), "__init__.py" ));
242
238
supportingFiles .add (new SupportingFile ("__init__model.mustache" , packagePath () + File .separatorChar + modelPackage , "__init__.py" ));
243
239
supportingFiles .add (new SupportingFile ("__init__api.mustache" , packagePath () + File .separatorChar + apiPackage , "__init__.py" ));
240
+
241
+ // If the package name consists of dots(openapi.client), then we need to create the directory structure like openapi/client with __init__ files.
242
+ String [] packageNameSplits = packageName .split ("\\ ." );
243
+ String currentPackagePath = "" ;
244
+ for (int i = 0 ; i < packageNameSplits .length -1 ; i ++) {
245
+ if (i > 0 ) {
246
+ currentPackagePath = currentPackagePath + File .separatorChar ;
247
+ }
248
+ currentPackagePath = currentPackagePath + packageNameSplits [i ];
249
+ supportingFiles .add (new SupportingFile ("__init__.mustache" , currentPackagePath , "__init__.py" ));
250
+ }
251
+
244
252
supportingFiles .add (new SupportingFile ("exceptions.mustache" , packagePath (), "exceptions.py" ));
245
253
246
254
if (Boolean .FALSE .equals (excludeTests )) {
247
- supportingFiles .add (new SupportingFile ("__init__test .mustache" , testFolder , "__init__.py" ));
255
+ supportingFiles .add (new SupportingFile ("__init__ .mustache" , testFolder , "__init__.py" ));
248
256
}
249
257
250
258
supportingFiles .add (new SupportingFile ("api_client.mustache" , packagePath (), "api_client.py" ));
0 commit comments