From f4d292581d8eca36dc3bdb02e2088bd076e92781 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Wed, 13 Nov 2019 22:46:34 -0800 Subject: [PATCH] Fixes Python client Configuration class so each instance uses its own dicts --- bin/python-petstore-all.sh | 1 + .../resources/python/configuration.mustache | 27 +++++--------- .../petstore_api/configuration.py | 27 +++++--------- .../petstore_api/configuration.py | 27 +++++--------- .../petstore_api/configuration.py | 27 +++++--------- .../python/petstore_api/configuration.py | 27 +++++--------- .../python/tests/test_configuration.py | 36 +++++++++++++++++++ .../python/petstore_api/configuration.py | 27 +++++--------- 8 files changed, 85 insertions(+), 114 deletions(-) create mode 100644 samples/client/petstore/python/tests/test_configuration.py diff --git a/bin/python-petstore-all.sh b/bin/python-petstore-all.sh index 1efab14e6e95..86c179eaa0d9 100755 --- a/bin/python-petstore-all.sh +++ b/bin/python-petstore-all.sh @@ -3,4 +3,5 @@ ./bin/python-asyncio-petstore.sh ./bin/python-petstore.sh +./bin/python-experimental-petstore.sh ./bin/python-tornado-petstore.sh diff --git a/modules/openapi-generator/src/main/resources/python/configuration.mustache b/modules/openapi-generator/src/main/resources/python/configuration.mustache index 9677031a8c98..6e02b238da1a 100644 --- a/modules/openapi-generator/src/main/resources/python/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/python/configuration.mustache @@ -4,7 +4,6 @@ from __future__ import absolute_import -import copy import logging {{^asyncio}} import multiprocessing @@ -16,21 +15,7 @@ import six from six.moves import http_client as httplib -class TypeWithDefault(type): - def __init__(cls, name, bases, dct): - super(TypeWithDefault, cls).__init__(name, bases, dct) - cls._default = None - - def __call__(cls, **kwargs): - if cls._default is None: - cls._default = type.__call__(cls, **kwargs) - return copy.copy(cls._default) - - def set_default(cls, default): - cls._default = copy.copy(default) - - -class Configuration(six.with_metaclass(TypeWithDefault, object)): +class Configuration(object): """NOTE: This class is auto generated by OpenAPI Generator Ref: https://openapi-generator.tech @@ -44,7 +29,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): """ def __init__(self, host="{{{basePath}}}", - api_key={}, api_key_prefix={}, + api_key=None, api_key_prefix=None, username="", password=""): """Constructor """ @@ -55,10 +40,14 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): """Temp file folder for downloading files """ # Authentication Settings - self.api_key = api_key + self.api_key = {} + if api_key: + self.api_key = api_key """dict to store API key(s) """ - self.api_key_prefix = api_key_prefix + self.api_key_prefix = {} + if api_key_prefix: + self.api_key_prefix = api_key_prefix """dict to store API prefix (e.g. Bearer) """ self.refresh_api_key_hook = None diff --git a/samples/client/petstore/python-asyncio/petstore_api/configuration.py b/samples/client/petstore/python-asyncio/petstore_api/configuration.py index ae776ad8c4e0..fa90c926deef 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/configuration.py +++ b/samples/client/petstore/python-asyncio/petstore_api/configuration.py @@ -12,7 +12,6 @@ from __future__ import absolute_import -import copy import logging import sys import urllib3 @@ -21,21 +20,7 @@ from six.moves import http_client as httplib -class TypeWithDefault(type): - def __init__(cls, name, bases, dct): - super(TypeWithDefault, cls).__init__(name, bases, dct) - cls._default = None - - def __call__(cls, **kwargs): - if cls._default is None: - cls._default = type.__call__(cls, **kwargs) - return copy.copy(cls._default) - - def set_default(cls, default): - cls._default = copy.copy(default) - - -class Configuration(six.with_metaclass(TypeWithDefault, object)): +class Configuration(object): """NOTE: This class is auto generated by OpenAPI Generator Ref: https://openapi-generator.tech @@ -49,7 +34,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): """ def __init__(self, host="http://petstore.swagger.io:80/v2", - api_key={}, api_key_prefix={}, + api_key=None, api_key_prefix=None, username="", password=""): """Constructor """ @@ -60,10 +45,14 @@ def __init__(self, host="http://petstore.swagger.io:80/v2", """Temp file folder for downloading files """ # Authentication Settings - self.api_key = api_key + self.api_key = {} + if api_key: + self.api_key = api_key """dict to store API key(s) """ - self.api_key_prefix = api_key_prefix + self.api_key_prefix = {} + if api_key_prefix: + self.api_key_prefix = api_key_prefix """dict to store API prefix (e.g. Bearer) """ self.refresh_api_key_hook = None diff --git a/samples/client/petstore/python-experimental/petstore_api/configuration.py b/samples/client/petstore/python-experimental/petstore_api/configuration.py index 5e9d7b5d41d3..9a0c95c90458 100644 --- a/samples/client/petstore/python-experimental/petstore_api/configuration.py +++ b/samples/client/petstore/python-experimental/petstore_api/configuration.py @@ -12,7 +12,6 @@ from __future__ import absolute_import -import copy import logging import multiprocessing import sys @@ -22,21 +21,7 @@ from six.moves import http_client as httplib -class TypeWithDefault(type): - def __init__(cls, name, bases, dct): - super(TypeWithDefault, cls).__init__(name, bases, dct) - cls._default = None - - def __call__(cls, **kwargs): - if cls._default is None: - cls._default = type.__call__(cls, **kwargs) - return copy.copy(cls._default) - - def set_default(cls, default): - cls._default = copy.copy(default) - - -class Configuration(six.with_metaclass(TypeWithDefault, object)): +class Configuration(object): """NOTE: This class is auto generated by OpenAPI Generator Ref: https://openapi-generator.tech @@ -50,7 +35,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): """ def __init__(self, host="http://petstore.swagger.io:80/v2", - api_key={}, api_key_prefix={}, + api_key=None, api_key_prefix=None, username="", password=""): """Constructor """ @@ -61,10 +46,14 @@ def __init__(self, host="http://petstore.swagger.io:80/v2", """Temp file folder for downloading files """ # Authentication Settings - self.api_key = api_key + self.api_key = {} + if api_key: + self.api_key = api_key """dict to store API key(s) """ - self.api_key_prefix = api_key_prefix + self.api_key_prefix = {} + if api_key_prefix: + self.api_key_prefix = api_key_prefix """dict to store API prefix (e.g. Bearer) """ self.refresh_api_key_hook = None diff --git a/samples/client/petstore/python-tornado/petstore_api/configuration.py b/samples/client/petstore/python-tornado/petstore_api/configuration.py index 5e9d7b5d41d3..9a0c95c90458 100644 --- a/samples/client/petstore/python-tornado/petstore_api/configuration.py +++ b/samples/client/petstore/python-tornado/petstore_api/configuration.py @@ -12,7 +12,6 @@ from __future__ import absolute_import -import copy import logging import multiprocessing import sys @@ -22,21 +21,7 @@ from six.moves import http_client as httplib -class TypeWithDefault(type): - def __init__(cls, name, bases, dct): - super(TypeWithDefault, cls).__init__(name, bases, dct) - cls._default = None - - def __call__(cls, **kwargs): - if cls._default is None: - cls._default = type.__call__(cls, **kwargs) - return copy.copy(cls._default) - - def set_default(cls, default): - cls._default = copy.copy(default) - - -class Configuration(six.with_metaclass(TypeWithDefault, object)): +class Configuration(object): """NOTE: This class is auto generated by OpenAPI Generator Ref: https://openapi-generator.tech @@ -50,7 +35,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): """ def __init__(self, host="http://petstore.swagger.io:80/v2", - api_key={}, api_key_prefix={}, + api_key=None, api_key_prefix=None, username="", password=""): """Constructor """ @@ -61,10 +46,14 @@ def __init__(self, host="http://petstore.swagger.io:80/v2", """Temp file folder for downloading files """ # Authentication Settings - self.api_key = api_key + self.api_key = {} + if api_key: + self.api_key = api_key """dict to store API key(s) """ - self.api_key_prefix = api_key_prefix + self.api_key_prefix = {} + if api_key_prefix: + self.api_key_prefix = api_key_prefix """dict to store API prefix (e.g. Bearer) """ self.refresh_api_key_hook = None diff --git a/samples/client/petstore/python/petstore_api/configuration.py b/samples/client/petstore/python/petstore_api/configuration.py index 5e9d7b5d41d3..9a0c95c90458 100644 --- a/samples/client/petstore/python/petstore_api/configuration.py +++ b/samples/client/petstore/python/petstore_api/configuration.py @@ -12,7 +12,6 @@ from __future__ import absolute_import -import copy import logging import multiprocessing import sys @@ -22,21 +21,7 @@ from six.moves import http_client as httplib -class TypeWithDefault(type): - def __init__(cls, name, bases, dct): - super(TypeWithDefault, cls).__init__(name, bases, dct) - cls._default = None - - def __call__(cls, **kwargs): - if cls._default is None: - cls._default = type.__call__(cls, **kwargs) - return copy.copy(cls._default) - - def set_default(cls, default): - cls._default = copy.copy(default) - - -class Configuration(six.with_metaclass(TypeWithDefault, object)): +class Configuration(object): """NOTE: This class is auto generated by OpenAPI Generator Ref: https://openapi-generator.tech @@ -50,7 +35,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): """ def __init__(self, host="http://petstore.swagger.io:80/v2", - api_key={}, api_key_prefix={}, + api_key=None, api_key_prefix=None, username="", password=""): """Constructor """ @@ -61,10 +46,14 @@ def __init__(self, host="http://petstore.swagger.io:80/v2", """Temp file folder for downloading files """ # Authentication Settings - self.api_key = api_key + self.api_key = {} + if api_key: + self.api_key = api_key """dict to store API key(s) """ - self.api_key_prefix = api_key_prefix + self.api_key_prefix = {} + if api_key_prefix: + self.api_key_prefix = api_key_prefix """dict to store API prefix (e.g. Bearer) """ self.refresh_api_key_hook = None diff --git a/samples/client/petstore/python/tests/test_configuration.py b/samples/client/petstore/python/tests/test_configuration.py new file mode 100644 index 000000000000..f1074b17e70a --- /dev/null +++ b/samples/client/petstore/python/tests/test_configuration.py @@ -0,0 +1,36 @@ +# coding: utf-8 + +# flake8: noqa + +""" +Run the tests. +$ pip install nose (optional) +$ cd petstore_api-python +$ nosetests -v +""" +from __future__ import absolute_import + +import unittest + +import petstore_api + + +class TestConfiguration(unittest.TestCase): + """Animal unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testConfiguration(self): + # check that different instances use different dictionaries + c1 = petstore_api.Configuration() + c2 = petstore_api.Configuration() + assert id(c1.api_key) != id(c2.api_key) + assert id(c1.api_key_prefix) != id(c2.api_key_prefix) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python/petstore_api/configuration.py b/samples/openapi3/client/petstore/python/petstore_api/configuration.py index d03bd91e1971..91109c7d78cb 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python/petstore_api/configuration.py @@ -12,7 +12,6 @@ from __future__ import absolute_import -import copy import logging import multiprocessing import sys @@ -22,21 +21,7 @@ from six.moves import http_client as httplib -class TypeWithDefault(type): - def __init__(cls, name, bases, dct): - super(TypeWithDefault, cls).__init__(name, bases, dct) - cls._default = None - - def __call__(cls, **kwargs): - if cls._default is None: - cls._default = type.__call__(cls, **kwargs) - return copy.copy(cls._default) - - def set_default(cls, default): - cls._default = copy.copy(default) - - -class Configuration(six.with_metaclass(TypeWithDefault, object)): +class Configuration(object): """NOTE: This class is auto generated by OpenAPI Generator Ref: https://openapi-generator.tech @@ -50,7 +35,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): """ def __init__(self, host="http://petstore.swagger.io:80/v2", - api_key={}, api_key_prefix={}, + api_key=None, api_key_prefix=None, username="", password=""): """Constructor """ @@ -61,10 +46,14 @@ def __init__(self, host="http://petstore.swagger.io:80/v2", """Temp file folder for downloading files """ # Authentication Settings - self.api_key = api_key + self.api_key = {} + if api_key: + self.api_key = api_key """dict to store API key(s) """ - self.api_key_prefix = api_key_prefix + self.api_key_prefix = {} + if api_key_prefix: + self.api_key_prefix = api_key_prefix """dict to store API prefix (e.g. Bearer) """ self.refresh_api_key_hook = None