Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] each Configuration instance now has its own dicts #4485

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/python-petstore-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

./bin/python-asyncio-petstore.sh
./bin/python-petstore.sh
./bin/python-experimental-petstore.sh
./bin/python-tornado-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from __future__ import absolute_import

import copy
import logging
{{^asyncio}}
import multiprocessing
Expand All @@ -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
Expand All @@ -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
"""
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from __future__ import absolute_import

import copy
import logging
import sys
import urllib3
Expand All @@ -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
Expand All @@ -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
"""
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from __future__ import absolute_import

import copy
import logging
import multiprocessing
import sys
Expand All @@ -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
Expand All @@ -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
"""
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from __future__ import absolute_import

import copy
import logging
import multiprocessing
import sys
Expand All @@ -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
Expand All @@ -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
"""
Expand All @@ -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
Expand Down
27 changes: 8 additions & 19 deletions samples/client/petstore/python/petstore_api/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from __future__ import absolute_import

import copy
import logging
import multiprocessing
import sys
Expand All @@ -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
Expand All @@ -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
"""
Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions samples/client/petstore/python/tests/test_configuration.py
Original file line number Diff line number Diff line change
@@ -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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

"""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()
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from __future__ import absolute_import

import copy
import logging
import multiprocessing
import sys
Expand All @@ -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
Expand All @@ -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
"""
Expand All @@ -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
Expand Down