diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java index 44dfaeefcd4..4cb96497aff 100755 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java @@ -28,16 +28,15 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig eggPackage = module + "-python"; - invokerPackage = eggPackage + "." + module; - invokerPackage = invokerPackage.replace('.', File.separatorChar); + invokerPackage = eggPackage + File.separatorChar + module; - outputFolder = "generated-code/python"; + outputFolder = "generated-code" + File.separatorChar + "python"; modelTemplateFiles.put("model.mustache", ".py"); apiTemplateFiles.put("api.mustache", ".py"); templateDir = "python"; - apiPackage = invokerPackage + ".apis"; - modelPackage = invokerPackage + ".models"; + apiPackage = invokerPackage + File.separatorChar + "apis"; + modelPackage = invokerPackage + File.separatorChar + "models"; languageSpecificPrimitives.clear(); languageSpecificPrimitives.add("int"); @@ -70,13 +69,13 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig supportingFiles.add(new SupportingFile("README.mustache", eggPackage, "README.md")); supportingFiles.add(new SupportingFile("setup.mustache", eggPackage, "setup.py")); - supportingFiles.add(new SupportingFile("swagger.mustache", invokerPackage, "swagger.py")); + supportingFiles.add(new SupportingFile("api_client.mustache", invokerPackage, "api_client.py")); supportingFiles.add(new SupportingFile("rest.mustache", invokerPackage, "rest.py")); supportingFiles.add(new SupportingFile("util.mustache", invokerPackage, "util.py")); - supportingFiles.add(new SupportingFile("config.mustache", invokerPackage, "config.py")); + supportingFiles.add(new SupportingFile("configuration.mustache", invokerPackage, "configuration.py")); supportingFiles.add(new SupportingFile("__init__package.mustache", invokerPackage, "__init__.py")); - supportingFiles.add(new SupportingFile("__init__model.mustache", modelPackage.replace('.', File.separatorChar), "__init__.py")); - supportingFiles.add(new SupportingFile("__init__api.mustache", apiPackage.replace('.', File.separatorChar), "__init__.py")); + supportingFiles.add(new SupportingFile("__init__model.mustache", modelPackage, "__init__.py")); + supportingFiles.add(new SupportingFile("__init__api.mustache", apiPackage, "__init__.py")); } @Override diff --git a/modules/swagger-codegen/src/main/resources/python/__init__package.mustache b/modules/swagger-codegen/src/main/resources/python/__init__package.mustache index 7b48136d3a9..921f4dac0eb 100644 --- a/modules/swagger-codegen/src/main/resources/python/__init__package.mustache +++ b/modules/swagger-codegen/src/main/resources/python/__init__package.mustache @@ -7,4 +7,4 @@ from __future__ import absolute_import {{#apiInfo}}{{#apis}}from .apis.{{classVarName}} import {{classname}} {{/apis}}{{/apiInfo}} # import ApiClient -from .swagger import ApiClient +from .api_client import ApiClient diff --git a/modules/swagger-codegen/src/main/resources/python/api.mustache b/modules/swagger-codegen/src/main/resources/python/api.mustache index 55bfd9e82a4..69c90491b95 100644 --- a/modules/swagger-codegen/src/main/resources/python/api.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api.mustache @@ -29,7 +29,7 @@ from six import iteritems from ..util import remove_none -from .. import config +from ..api_client import ApiClient {{#operations}} class {{classname}}(object): diff --git a/modules/swagger-codegen/src/main/resources/python/swagger.mustache b/modules/swagger-codegen/src/main/resources/python/api_client.mustache similarity index 98% rename from modules/swagger-codegen/src/main/resources/python/swagger.mustache rename to modules/swagger-codegen/src/main/resources/python/api_client.mustache index d7b896d3c0e..4ba445e2fa6 100644 --- a/modules/swagger-codegen/src/main/resources/python/swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api_client.mustache @@ -28,7 +28,7 @@ except ImportError: # for python2 from urllib import quote -from . import config +from . import configuration class ApiClient(object): """ @@ -38,7 +38,7 @@ class ApiClient(object): :param header_name: a header to pass when making calls to the API :param header_value: a header value to pass when making calls to the API """ - def __init__(self, host=config.host, header_name=None, header_value=None): + def __init__(self, host=configuration.host, header_name=None, header_value=None): self.default_headers = {} if header_name is not None: self.default_headers[header_name] = header_value @@ -292,7 +292,7 @@ class ApiClient(object): return for auth in auth_settings: - auth_setting = config.auth_settings().get(auth) + auth_setting = configuration.auth_settings().get(auth) if auth_setting: if auth_setting['in'] == 'header': headers[auth_setting['key']] = auth_setting['value'] diff --git a/modules/swagger-codegen/src/main/resources/python/config.mustache b/modules/swagger-codegen/src/main/resources/python/configuration.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/python/config.mustache rename to modules/swagger-codegen/src/main/resources/python/configuration.mustache diff --git a/modules/swagger-codegen/src/main/resources/python/rest.mustache b/modules/swagger-codegen/src/main/resources/python/rest.mustache index da99abc2493..44a1022906b 100644 --- a/modules/swagger-codegen/src/main/resources/python/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/rest.mustache @@ -120,7 +120,7 @@ class RESTClientObject(object): r = RESTResponse(r) if r.status not in range(200, 206): - raise ErrorResponse(r) + raise ApiException(r) return self.process_response(r) @@ -157,7 +157,7 @@ class RESTClientObject(object): return self.request("PATCH", url, headers=headers, post_params=post_params, body=body) -class ErrorResponse(Exception): +class ApiException(Exception): """ Non-2xx HTTP response """ diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/__init__.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/__init__.py index 9d4b2db3de5..3e7b51b8467 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/__init__.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/__init__.py @@ -13,4 +13,4 @@ from .apis.pet_api import PetApi from .apis.store_api import StoreApi # import ApiClient -from .swagger import ApiClient +from .api_client import ApiClient diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/api_client.py similarity index 98% rename from samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/api_client.py index d7b896d3c0e..4ba445e2fa6 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/api_client.py @@ -28,7 +28,7 @@ except ImportError: # for python2 from urllib import quote -from . import config +from . import configuration class ApiClient(object): """ @@ -38,7 +38,7 @@ class ApiClient(object): :param header_name: a header to pass when making calls to the API :param header_value: a header value to pass when making calls to the API """ - def __init__(self, host=config.host, header_name=None, header_value=None): + def __init__(self, host=configuration.host, header_name=None, header_value=None): self.default_headers = {} if header_name is not None: self.default_headers[header_name] = header_value @@ -292,7 +292,7 @@ class ApiClient(object): return for auth in auth_settings: - auth_setting = config.auth_settings().get(auth) + auth_setting = configuration.auth_settings().get(auth) if auth_setting: if auth_setting['in'] == 'header': headers[auth_setting['key']] = auth_setting['value'] diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py index 37da9901597..1a738e4c317 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py @@ -29,7 +29,7 @@ from six import iteritems from ..util import remove_none -from .. import config +from ..api_client import ApiClient class PetApi(object): diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py index 649cb5f704d..aab7d0f11b6 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py @@ -29,7 +29,7 @@ from six import iteritems from ..util import remove_none -from .. import config +from ..api_client import ApiClient class StoreApi(object): diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py index 3f2b36a85fa..66cb235c3d7 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py @@ -29,7 +29,7 @@ from six import iteritems from ..util import remove_none -from .. import config +from ..api_client import ApiClient class UserApi(object): diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/config.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/configuration.py similarity index 100% rename from samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/config.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/configuration.py diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/rest.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/rest.py index da99abc2493..44a1022906b 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/rest.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/rest.py @@ -120,7 +120,7 @@ class RESTClientObject(object): r = RESTResponse(r) if r.status not in range(200, 206): - raise ErrorResponse(r) + raise ApiException(r) return self.process_response(r) @@ -157,7 +157,7 @@ class RESTClientObject(object): return self.request("PATCH", url, headers=headers, post_params=post_params, body=body) -class ErrorResponse(Exception): +class ApiException(Exception): """ Non-2xx HTTP response """ diff --git a/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py index 6bc3000f267..560d01d0f3d 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py @@ -12,7 +12,7 @@ import time import unittest import SwaggerPetstore -import SwaggerPetstore.config +import SwaggerPetstore.configuration HOST = 'http://petstore.swagger.io/v2' @@ -23,17 +23,17 @@ class ApiClientTests(unittest.TestCase): self.api_client = SwaggerPetstore.ApiClient(HOST) def test_configuratjion(self): - SwaggerPetstore.config.api_key['api_key'] = '123456' - SwaggerPetstore.config.api_key_prefix['api_key'] = 'PREFIX' - SwaggerPetstore.config.username = 'test_username' - SwaggerPetstore.config.password = 'test_password' + SwaggerPetstore.configuration.api_key['api_key'] = '123456' + SwaggerPetstore.configuration.api_key_prefix['api_key'] = 'PREFIX' + SwaggerPetstore.configuration.username = 'test_username' + SwaggerPetstore.configuration.password = 'test_password' header_params = {'test1': 'value1'} query_params = {'test2': 'value2'} auth_settings = ['api_key', 'unknown'] # test prefix - self.assertEqual('PREFIX', SwaggerPetstore.config.api_key_prefix['api_key']) + self.assertEqual('PREFIX', SwaggerPetstore.configuration.api_key_prefix['api_key']) # update parameters based on auth setting self.api_client.update_params_for_auth(header_params, query_params, auth_settings) @@ -44,8 +44,8 @@ class ApiClientTests(unittest.TestCase): self.assertEqual(query_params['test2'], 'value2') # test basic auth - self.assertEqual('test_username', SwaggerPetstore.config.username) - self.assertEqual('test_password', SwaggerPetstore.config.password) + self.assertEqual('test_username', SwaggerPetstore.configuration.username) + self.assertEqual('test_password', SwaggerPetstore.configuration.password) def test_select_header_accept(self): accepts = ['APPLICATION/JSON', 'APPLICATION/XML'] diff --git a/samples/client/petstore/python/SwaggerPetstore-python/tests/test_pet_api.py b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_pet_api.py index ee8c5dde14e..2c50ac861a1 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/tests/test_pet_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_pet_api.py @@ -12,8 +12,7 @@ import time import unittest import SwaggerPetstore -from SwaggerPetstore.rest import ErrorResponse -from SwaggerPetstore import config +from SwaggerPetstore.rest import ApiException HOST = 'http://petstore.swagger.io/v2' @@ -126,7 +125,7 @@ class PetApiTests(unittest.TestCase): additional_metadata=additional_metadata, file=self.foo ) - except ErrorResponse as e: + except ApiException as e: self.fail("upload_file() raised {0} unexpectedly".format(type(e))) def test_delete_pet(self): @@ -136,7 +135,7 @@ class PetApiTests(unittest.TestCase): try: self.pet_api.get_pet_by_id(pet_id=self.pet.id) raise "expected an error" - except ErrorResponse as e: + except ApiException as e: self.assertEqual(404, e.status) if __name__ == '__main__':