Merge pull request #609 from geekerzp/develop_2.0_python_better_import

Better import for python client
This commit is contained in:
Tony Tam 2015-04-08 21:15:38 -06:00
commit 7dcdaca288
4 changed files with 59 additions and 6 deletions

View File

@ -27,10 +27,10 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
modelTemplateFiles.put("model.mustache", ".py");
apiTemplateFiles.put("api.mustache", ".py");
templateDir = "python";
apiPackage = module;
modelPackage = module + ".models";
languageSpecificPrimitives.clear();
languageSpecificPrimitives.add("int");
languageSpecificPrimitives.add("float");
@ -61,8 +61,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("swagger.mustache", module, "swagger.py"));
supportingFiles.add(new SupportingFile("__init__.mustache", module, "__init__.py"));
supportingFiles.add(new SupportingFile("__init__.mustache", modelPackage.replace('.', File.separatorChar), "__init__.py"));
supportingFiles.add(new SupportingFile("__init__package.mustache", module, "__init__.py"));
supportingFiles.add(new SupportingFile("__init__model.mustache", modelPackage.replace('.', File.separatorChar), "__init__.py"));
}
@Override
@ -113,7 +113,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
public String toDefaultValue(Property p) {
// TODO: Support Python def value
return "null";
}
}
@Override
public String toVarName(String name) {
@ -176,9 +176,15 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
public String toApiName(String name) {
if(name.length() == 0)
return "DefaultApi";
// e.g. phone_number_api => PhoneNumberApi
// e.g. phone_number_api => PhoneNumberApi
return camelize(name) + "Api";
}
@Override
public String toApiVarName(String name) {
if(name.length() == 0)
return "default_api";
return underscore(name) + "_api";
}
}

View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Add all of the modules in the current directory to __all__"""
import os
# import models into package
{{#models}}{{#model}}
from .models.{{classVarName}} import {{classname}}
{{/model}}{{/models}}
# import apis into package
{{#apiInfo}}{{#apis}}
from .{{classVarName}} import {{classname}}
{{/apis}}{{/apiInfo}}
# import ApiClient
from .swagger import ApiClient
__all__ = []
for module in os.listdir(os.path.dirname(__file__)):
if module != '__init__.py' and module[-3:] == '.py':
__all__.append(module[:-3])

View File

@ -2,6 +2,31 @@
"""Add all of the modules in the current directory to __all__"""
import os
# import models into package
from .models.user import User
from .models.category import Category
from .models.pet import Pet
from .models.tag import Tag
from .models.order import Order
# import apis into package
from .user_api import UserApi
from .pet_api import PetApi
from .store_api import StoreApi
# import ApiClient
from .swagger import ApiClient
__all__ = []
for module in os.listdir(os.path.dirname(__file__)):