forked from loafle/openapi-generator-original
Merge branch '2.3.0' of https://github.com/swagger-api/swagger-codegen into 2.3.0
This commit is contained in:
@@ -14,5 +14,3 @@ from __future__ import absolute_import
|
||||
from .api_client import ApiClient
|
||||
|
||||
from .configuration import Configuration
|
||||
|
||||
configuration = Configuration()
|
||||
|
||||
@@ -11,7 +11,6 @@ import re
|
||||
# python 2 and python 3 compatibility library
|
||||
from six import iteritems
|
||||
|
||||
from ..configuration import Configuration
|
||||
from ..api_client import ApiClient
|
||||
|
||||
|
||||
@@ -24,13 +23,9 @@ class {{classname}}(object):
|
||||
"""
|
||||
|
||||
def __init__(self, api_client=None):
|
||||
config = Configuration()
|
||||
if api_client:
|
||||
self.api_client = api_client
|
||||
else:
|
||||
if not config.api_client:
|
||||
config.api_client = ApiClient()
|
||||
self.api_client = config.api_client
|
||||
if api_client is None:
|
||||
api_client = ApiClient()
|
||||
self.api_client = api_client
|
||||
{{#operation}}
|
||||
|
||||
def {{operationId}}(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs):
|
||||
|
||||
@@ -50,18 +50,15 @@ class ApiClient(object):
|
||||
'object': object,
|
||||
}
|
||||
|
||||
def __init__(self, host=None, header_name=None, header_value=None, cookie=None):
|
||||
"""
|
||||
Constructor of the class.
|
||||
"""
|
||||
self.rest_client = RESTClientObject()
|
||||
def __init__(self, configuration=None, header_name=None, header_value=None, cookie=None):
|
||||
if configuration is None:
|
||||
configuration = Configuration()
|
||||
self.configuration = configuration
|
||||
|
||||
self.rest_client = RESTClientObject(configuration)
|
||||
self.default_headers = {}
|
||||
if header_name is not None:
|
||||
self.default_headers[header_name] = header_value
|
||||
if host is None:
|
||||
self.host = Configuration().host
|
||||
else:
|
||||
self.host = host
|
||||
self.cookie = cookie
|
||||
# Set default User-Agent.
|
||||
self.user_agent = '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/{{{packageVersion}}}/python{{/httpUserAgent}}'
|
||||
@@ -130,7 +127,7 @@ class ApiClient(object):
|
||||
body = self.sanitize_for_serialization(body)
|
||||
|
||||
# request url
|
||||
url = self.host + resource_path
|
||||
url = self.configuration.host + resource_path
|
||||
|
||||
# perform request and return response
|
||||
response_data = self.request(method, url,
|
||||
@@ -487,13 +484,11 @@ class ApiClient(object):
|
||||
:param querys: Query parameters tuple list to be updated.
|
||||
:param auth_settings: Authentication setting identifiers list.
|
||||
"""
|
||||
config = Configuration()
|
||||
|
||||
if not auth_settings:
|
||||
return
|
||||
|
||||
for auth in auth_settings:
|
||||
auth_setting = config.auth_settings().get(auth)
|
||||
auth_setting = self.configuration.auth_settings().get(auth)
|
||||
if auth_setting:
|
||||
if not auth_setting['value']:
|
||||
continue
|
||||
@@ -514,9 +509,7 @@ class ApiClient(object):
|
||||
:param response: RESTResponse.
|
||||
:return: file path.
|
||||
"""
|
||||
config = Configuration()
|
||||
|
||||
fd, path = tempfile.mkstemp(dir=config.temp_folder_path)
|
||||
fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
|
||||
os.close(fd)
|
||||
os.remove(path)
|
||||
|
||||
|
||||
@@ -26,20 +26,30 @@ from {{{packageName}}}.rest import ApiException
|
||||
from pprint import pprint
|
||||
{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
|
||||
# Configure HTTP basic authorization: {{{name}}}
|
||||
{{{packageName}}}.configuration.username = 'YOUR_USERNAME'
|
||||
{{{packageName}}}.configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{#isApiKey}}
|
||||
configuration = {{{packageName}}}.Configuration()
|
||||
configuration.username = 'YOUR_USERNAME'
|
||||
configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{#isApiKey}}
|
||||
# Configure API key authorization: {{{name}}}
|
||||
{{{packageName}}}.configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY'
|
||||
configuration = {{{packageName}}}.Configuration()
|
||||
configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY'
|
||||
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||
# {{{packageName}}}.configuration.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
|
||||
# configuration.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
|
||||
# Configure OAuth2 access token for authorization: {{{name}}}
|
||||
{{{packageName}}}.configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isOAuth}}{{/authMethods}}
|
||||
configuration = {{{packageName}}}.Configuration()
|
||||
configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isOAuth}}{{/authMethods}}
|
||||
|
||||
# create an instance of the API class
|
||||
api_instance = {{{packageName}}}.{{{classname}}}({{{packageName}}}.ApiClient(configuration))
|
||||
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
|
||||
{{/allParams}}
|
||||
{{/hasAuthMethods}}
|
||||
{{^hasAuthMethods}}
|
||||
|
||||
# create an instance of the API class
|
||||
api_instance = {{{packageName}}}.{{{classname}}}()
|
||||
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
|
||||
{{/allParams}}
|
||||
{{/hasAuthMethods}}
|
||||
|
||||
try:
|
||||
{{#summary}} # {{{.}}}
|
||||
|
||||
@@ -13,17 +13,6 @@ from six import iteritems
|
||||
from six.moves import http_client as httplib
|
||||
|
||||
|
||||
def singleton(cls, *args, **kw):
|
||||
instances = {}
|
||||
|
||||
def _singleton():
|
||||
if cls not in instances:
|
||||
instances[cls] = cls(*args, **kw)
|
||||
return instances[cls]
|
||||
return _singleton
|
||||
|
||||
|
||||
@singleton
|
||||
class Configuration(object):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
@@ -37,8 +26,6 @@ class Configuration(object):
|
||||
"""
|
||||
# Default Base url
|
||||
self.host = "{{{basePath}}}"
|
||||
# Default api client
|
||||
self.api_client = None
|
||||
# Temp file folder for downloading files
|
||||
self.temp_folder_path = None
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class {{classname}}(object):
|
||||
def {{name}}(self):
|
||||
"""
|
||||
Gets the {{name}} of this {{classname}}.
|
||||
{{#description}}
|
||||
{{#description}}
|
||||
{{{description}}}
|
||||
{{/description}}
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@ import re
|
||||
from six import PY3
|
||||
from six.moves.urllib.parse import urlencode
|
||||
|
||||
from .configuration import Configuration
|
||||
|
||||
try:
|
||||
import urllib3
|
||||
except ImportError:
|
||||
@@ -49,7 +47,7 @@ class RESTResponse(io.IOBase):
|
||||
|
||||
class RESTClientObject(object):
|
||||
|
||||
def __init__(self, pools_size=4, maxsize=4):
|
||||
def __init__(self, configuration, pools_size=4, maxsize=4):
|
||||
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
||||
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75
|
||||
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680
|
||||
@@ -58,37 +56,28 @@ class RESTClientObject(object):
|
||||
# http://stackoverflow.com/a/23957365/2985775
|
||||
|
||||
# cert_reqs
|
||||
if Configuration().verify_ssl:
|
||||
if configuration.verify_ssl:
|
||||
cert_reqs = ssl.CERT_REQUIRED
|
||||
else:
|
||||
cert_reqs = ssl.CERT_NONE
|
||||
|
||||
# ca_certs
|
||||
if Configuration().ssl_ca_cert:
|
||||
ca_certs = Configuration().ssl_ca_cert
|
||||
if configuration.ssl_ca_cert:
|
||||
ca_certs = configuration.ssl_ca_cert
|
||||
else:
|
||||
# if not set certificate file, use Mozilla's root certificates.
|
||||
ca_certs = certifi.where()
|
||||
|
||||
# cert_file
|
||||
cert_file = Configuration().cert_file
|
||||
|
||||
# key file
|
||||
key_file = Configuration().key_file
|
||||
|
||||
# proxy
|
||||
proxy = Configuration().proxy
|
||||
|
||||
# https pool manager
|
||||
if proxy:
|
||||
if configuration.proxy:
|
||||
self.pool_manager = urllib3.ProxyManager(
|
||||
num_pools=pools_size,
|
||||
maxsize=maxsize,
|
||||
cert_reqs=cert_reqs,
|
||||
ca_certs=ca_certs,
|
||||
cert_file=cert_file,
|
||||
key_file=key_file,
|
||||
proxy_url=proxy
|
||||
cert_file=configuration.cert_file,
|
||||
key_file=configuration.key_file,
|
||||
proxy_url=configuration.proxy
|
||||
)
|
||||
else:
|
||||
self.pool_manager = urllib3.PoolManager(
|
||||
@@ -96,11 +85,10 @@ class RESTClientObject(object):
|
||||
maxsize=maxsize,
|
||||
cert_reqs=cert_reqs,
|
||||
ca_certs=ca_certs,
|
||||
cert_file=cert_file,
|
||||
key_file=key_file
|
||||
cert_file=configuration.cert_file,
|
||||
key_file=configuration.key_file
|
||||
)
|
||||
|
||||
|
||||
def request(self, method, url, query_params=None, headers=None,
|
||||
body=None, post_params=None, _preload_content=True, _request_timeout=None):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user