diff --git a/modules/swagger-codegen/src/main/resources/python/api.mustache b/modules/swagger-codegen/src/main/resources/python/api.mustache index 9811288e929..3620e9fb9ee 100644 --- a/modules/swagger-codegen/src/main/resources/python/api.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api.mustache @@ -1,4 +1,3 @@ -#!/usr/bin/env python # coding: utf-8 """ @@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - -NOTE: This class is auto generated by the swagger code generator program. - Do not edit the class manually. """ + from __future__ import absolute_import import sys @@ -34,6 +31,10 @@ from ..api_client import ApiClient {{#operations}} class {{classname}}(object): + """ + NOTE: This class is auto generated by the swagger code generator program. + Do not edit the class manually. + """ def __init__(self, api_client=None): config = Configuration() diff --git a/modules/swagger-codegen/src/main/resources/python/api_client.mustache b/modules/swagger-codegen/src/main/resources/python/api_client.mustache index 637bba9d765..24b1e52ff3e 100644 --- a/modules/swagger-codegen/src/main/resources/python/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api_client.mustache @@ -1,10 +1,20 @@ -#!/usr/bin/env python # coding: utf-8 -"""Swagger generic API client. This client handles the client- -server communication, and is invariant across implementations. Specifics of -the methods and models for each application are generated from the Swagger -templates.""" +""" +Copyright 2015 SmartBear Software + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" from __future__ import absolute_import from . import models @@ -38,15 +48,27 @@ from .configuration import Configuration class ApiClient(object): """ - Generic API client for Swagger client library builds + Generic API client for Swagger client library builds. - :param host: The base path for the server to call - :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 + Swagger generic API client. This client handles the client- + server communication, and is invariant across implementations. Specifics of + the methods and models for each application are generated from the Swagger + templates. + + NOTE: This class is auto generated by the swagger code generator program. + https://github.com/swagger-api/swagger-codegen + Do not edit the class manually. + + :param host: The base path for the server to call. + :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=Configuration().host, header_name=None, header_value=None, cookie=None): + """ + Constructor of the class. + """ self.default_headers = {} if header_name is not None: self.default_headers[header_name] = header_value @@ -57,10 +79,16 @@ class ApiClient(object): @property def user_agent(self): + """ + Gets user agent. + """ return self.default_headers['User-Agent'] @user_agent.setter def user_agent(self, value): + """ + Sets user agent. + """ self.default_headers['User-Agent'] = value def set_default_header(self, header_name, header_value): @@ -129,11 +157,12 @@ class ApiClient(object): def to_path_value(self, obj): """ - Convert a string or object to a path-friendly value + Takes value and turn it into a string suitable for inclusion in + the path, by url-encoding. - :param obj: object or string value + :param obj: object or string value. - :return string: quoted value + :return string: quoted value. """ if type(obj) == list: return ','.join(obj) @@ -142,7 +171,7 @@ class ApiClient(object): def sanitize_for_serialization(self, obj): """ - Sanitize an object for Request. + Builds a JSON POST object. If obj is None, return None. If obj is str, int, float, bool, return directly. @@ -151,6 +180,9 @@ class ApiClient(object): If obj is list, santize each element in the list. If obj is dict, return the dict. If obj is swagger model, return the properties dict. + + :param obj: The data to serialize. + :return: The serialized form of data. """ if isinstance(obj, type(None)): return None @@ -181,13 +213,13 @@ class ApiClient(object): def deserialize(self, response, response_type): """ - Derialize response into an object. + Deserializes response into an object. - :param response: RESTResponse object to be deserialized + :param response: RESTResponse object to be deserialized. :param response_type: class literal for - deserialzied object, or string of class name + deserialzied object, or string of class name. - :return: deserialized object + :return: deserialized object. """ # handle file downloading # save response body into a tmp file and return the instance @@ -204,10 +236,12 @@ class ApiClient(object): def __deserialize(self, data, klass): """ - :param data: dict, list or str - :param klass: class literal, or string of class name + Deserializes dict, list, str into an object. - :return: object + :param data: dict, list or str. + :param klass: class literal, or string of class name. + + :return: object. """ if data is None: return None @@ -248,8 +282,7 @@ class ApiClient(object): body=None, post_params=None, files=None, response_type=None, auth_settings=None, callback=None): """ - Perform http request and return deserialized data - + Makes the HTTP request and return the deserialized data. :param resource_path: Path to method endpoint. :param method: Method to call. @@ -293,7 +326,7 @@ class ApiClient(object): def request(self, method, url, query_params=None, headers=None, post_params=None, body=None): """ - Perform http request using RESTClient. + Makes the HTTP request using RESTClient. """ if method == "GET": return RESTClient.GET(url, @@ -329,6 +362,13 @@ class ApiClient(object): ) def prepare_post_parameters(self, post_params=None, files=None): + """ + Builds form parameters. + + :param post_params: Normal form parameters. + :param files: File parameters. + :return: Form parameters with files. + """ params = {} if post_params: @@ -350,7 +390,10 @@ class ApiClient(object): def select_header_accept(self, accepts): """ - Return `Accept` based on an array of accepts provided + Returns `Accept` based on an array of accepts provided. + + :param accepts: List of headers. + :return: Accept (e.g. application/json). """ if not accepts: return @@ -364,7 +407,10 @@ class ApiClient(object): def select_header_content_type(self, content_types): """ - Return `Content-Type` baseed on an array of content_types provided + Returns `Content-Type` based on an array of content_types provided. + + :param content_types: List of content-types. + :return: Content-Type (e.g. application/json). """ if not content_types: return 'application/json' @@ -378,7 +424,11 @@ class ApiClient(object): def update_params_for_auth(self, headers, querys, auth_settings): """ - Update header and query params based on authentication setting + Updates header and query params based on authentication setting. + + :param headers: Header parameters dict to be updated. + :param querys: Query parameters dict to be updated. + :param auth_settings: Authentication setting identifiers list. """ config = Configuration() @@ -399,12 +449,12 @@ class ApiClient(object): def __deserialize_file(self, response): """ - Save response body into a file in (the defined) temporary folder, + Saves response body into a file in (the defined) temporary folder, using the filename from the `Content-Disposition` header if provided, otherwise a random filename. - :param response: RESTResponse - :return: file path + :param response: RESTResponse. + :return: file path. """ config = Configuration() @@ -426,12 +476,12 @@ class ApiClient(object): def __deserialize_primitive(self, data, klass): """ - Deserialize string to primitive type + Deserializes string to primitive type. - :param data: str - :param klass: class literal + :param data: str. + :param klass: class literal. - :return: int, float, str, bool + :return: int, float, str, bool. """ try: value = klass(data) @@ -443,16 +493,18 @@ class ApiClient(object): def __deserialize_object(self): """ - Deserialize empty object + Deserializes empty object. + + :return: object. """ return object() def __deserialize_date(self, string): """ - Deserialize string to date + Deserializes string to date. - :param string: str - :return: date + :param string: str. + :return: date. """ try: from dateutil.parser import parse @@ -468,12 +520,12 @@ class ApiClient(object): def __deserialize_datatime(self, string): """ - Deserialize string to datetime. + Deserializes string to datetime. The string should be in iso8601 datetime format. - :param string: str - :return: datetime + :param string: str. + :return: datetime. """ try: from dateutil.parser import parse @@ -489,10 +541,11 @@ class ApiClient(object): def __deserialize_model(self, data, klass): """ - Deserialize list or dict to model + Deserializes list or dict to model. - :param data: dict, list - :param klass: class literal + :param data: dict, list. + :param klass: class literal. + :return: model object. """ instance = klass() diff --git a/modules/swagger-codegen/src/main/resources/python/configuration.mustache b/modules/swagger-codegen/src/main/resources/python/configuration.mustache index bf26ab362b1..f2a52cb6e84 100644 --- a/modules/swagger-codegen/src/main/resources/python/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/python/configuration.mustache @@ -1,3 +1,21 @@ +# coding: utf-8 + +""" +Copyright 2015 SmartBear Software + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" + from __future__ import absolute_import import base64 import urllib3 @@ -18,26 +36,45 @@ def singleton(cls, *args, **kw): @singleton class Configuration(object): + """ + NOTE: This class is auto generated by the swagger code generator program. + https://github.com/swagger-api/swagger-codegen + Do not edit the class manually. + """ def __init__(self): + """ + Constructor + """ # Default Base url self.host = "{{basePath}}" # Default api client self.api_client = None - # Temp file folder + # Temp file folder for download self.temp_folder_path = None + # Authentication Settings + # dict to store API key(s) self.api_key = {} + # dict to store API prefix (e.g. Bearer) self.api_key_prefix = {} + # Username for HTTP basic authentication self.username = "" + # Password for HTTP basic authentication self.password = "" + # Logging Settings self.logging_format = '%(asctime)s %(levelname)s %(message)s' + # Debug file location self.__logging_file = None + # Debug switch self.__debug = False self.init_logger() def init_logger(self): + """ + Initializes logger settings. + """ self.logger = logging.getLogger() formatter = logging.Formatter(self.logging_format) stream_handler = logging.StreamHandler() @@ -82,20 +119,33 @@ class Configuration(object): # setting log level to default `logging.WARNING` self.logger.setLevel(logging.WARNING) - def get_api_key_with_prefix(self, key): - """ Return api key prepend prefix for key """ - if self.api_key.get(key) and self.api_key_prefix.get(key): - return self.api_key_prefix[key] + ' ' + self.api_key[key] - elif self.api_key.get(key): - return self.api_key[key] + def get_api_key_with_prefix(self, identifier): + """ + Gets API key (with prefix if set). + + :param identifier: The identifier of apiKey. + :return: The token for api key authentication. + """ + if self.api_key.get(identifier) and self.api_key_prefix.get(identifier): + return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier] + elif self.api_key.get(identifier): + return self.api_key[identifier] def get_basic_auth_token(self): - """ Return basic auth header string """ + """ + Gets basic auth header string. + + :return: The token for basic HTTP authentication. + """ return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\ .get('authorization') def auth_settings(self): - """ Return Auth Settings for api client """ + """ + Gets Auth Settings dict for api client. + + :return: The Auth Settings information dict. + """ return { {{#authMethods}} {{#isApiKey}} @@ -120,6 +170,11 @@ class Configuration(object): } def to_debug_report(self): + """ + Gets the essential information for debugging. + + :return: The report for debugging. + """ return "Python SDK Debug Report:\n"\ "OS: {env}\n"\ "Python Version: {pyversion}\n"\ diff --git a/modules/swagger-codegen/src/main/resources/python/model.mustache b/modules/swagger-codegen/src/main/resources/python/model.mustache index 7314e9ee9cd..40140ea0aa9 100644 --- a/modules/swagger-codegen/src/main/resources/python/model.mustache +++ b/modules/swagger-codegen/src/main/resources/python/model.mustache @@ -1,4 +1,3 @@ -#!/usr/bin/env python # coding: utf-8 """ @@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software See the License for the specific language governing permissions and limitations under the License. """ + {{#models}} {{#model}} from pprint import pformat diff --git a/modules/swagger-codegen/src/main/resources/python/rest.mustache b/modules/swagger-codegen/src/main/resources/python/rest.mustache index fab813a4cc9..f6161a6d60c 100644 --- a/modules/swagger-codegen/src/main/resources/python/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/rest.mustache @@ -1,6 +1,20 @@ # coding: utf-8 """ +Copyright 2015 SmartBear Software + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + Credit: this file (rest.py) is modified based on rest.py in Dropbox Python SDK: https://www.dropbox.com/developers/core/sdks/python """ diff --git a/modules/swagger-codegen/src/main/resources/python/setup.mustache b/modules/swagger-codegen/src/main/resources/python/setup.mustache index 9c19e413e9c..a939ce01958 100644 --- a/modules/swagger-codegen/src/main/resources/python/setup.mustache +++ b/modules/swagger-codegen/src/main/resources/python/setup.mustache @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# coding: utf-8 + import sys from setuptools import setup, find_packages @@ -34,11 +35,3 @@ setup( ) {{/hasMore}}{{/apis}}{{/apiInfo}} - - - - - - - - diff --git a/samples/client/petstore/python/setup.py b/samples/client/petstore/python/setup.py index ffc6f6a3ad2..e66e9689343 100644 --- a/samples/client/petstore/python/setup.py +++ b/samples/client/petstore/python/setup.py @@ -1,3 +1,5 @@ +# coding: utf-8 + import sys from setuptools import setup, find_packages @@ -33,11 +35,3 @@ setup( ) - - - - - - - - diff --git a/samples/client/petstore/python/swagger_client/api_client.py b/samples/client/petstore/python/swagger_client/api_client.py index 37bf1be69c0..24b1e52ff3e 100644 --- a/samples/client/petstore/python/swagger_client/api_client.py +++ b/samples/client/petstore/python/swagger_client/api_client.py @@ -1,10 +1,20 @@ -#!/usr/bin/env python # coding: utf-8 -"""Swagger generic API client. This client handles the client- -server communication, and is invariant across implementations. Specifics of -the methods and models for each application are generated from the Swagger -templates.""" +""" +Copyright 2015 SmartBear Software + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" from __future__ import absolute_import from . import models @@ -38,29 +48,47 @@ from .configuration import Configuration class ApiClient(object): """ - Generic API client for Swagger client library builds + Generic API client for Swagger client library builds. - :param host: The base path for the server to call - :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 + Swagger generic API client. This client handles the client- + server communication, and is invariant across implementations. Specifics of + the methods and models for each application are generated from the Swagger + templates. + + NOTE: This class is auto generated by the swagger code generator program. + https://github.com/swagger-api/swagger-codegen + Do not edit the class manually. + + :param host: The base path for the server to call. + :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=Configuration().host, - header_name=None, header_value=None): + header_name=None, header_value=None, cookie=None): + """ + Constructor of the class. + """ self.default_headers = {} if header_name is not None: self.default_headers[header_name] = header_value self.host = host - self.cookie = None + self.cookie = cookie # Set default User-Agent. self.user_agent = 'Python-Swagger' @property def user_agent(self): + """ + Gets user agent. + """ return self.default_headers['User-Agent'] @user_agent.setter def user_agent(self, value): + """ + Sets user agent. + """ self.default_headers['User-Agent'] = value def set_default_header(self, header_name, header_value): @@ -129,11 +157,12 @@ class ApiClient(object): def to_path_value(self, obj): """ - Convert a string or object to a path-friendly value + Takes value and turn it into a string suitable for inclusion in + the path, by url-encoding. - :param obj: object or string value + :param obj: object or string value. - :return string: quoted value + :return string: quoted value. """ if type(obj) == list: return ','.join(obj) @@ -142,7 +171,7 @@ class ApiClient(object): def sanitize_for_serialization(self, obj): """ - Sanitize an object for Request. + Builds a JSON POST object. If obj is None, return None. If obj is str, int, float, bool, return directly. @@ -151,6 +180,9 @@ class ApiClient(object): If obj is list, santize each element in the list. If obj is dict, return the dict. If obj is swagger model, return the properties dict. + + :param obj: The data to serialize. + :return: The serialized form of data. """ if isinstance(obj, type(None)): return None @@ -181,13 +213,13 @@ class ApiClient(object): def deserialize(self, response, response_type): """ - Derialize response into an object. + Deserializes response into an object. - :param response: RESTResponse object to be deserialized + :param response: RESTResponse object to be deserialized. :param response_type: class literal for - deserialzied object, or string of class name + deserialzied object, or string of class name. - :return: deserialized object + :return: deserialized object. """ # handle file downloading # save response body into a tmp file and return the instance @@ -204,10 +236,12 @@ class ApiClient(object): def __deserialize(self, data, klass): """ - :param data: dict, list or str - :param klass: class literal, or string of class name + Deserializes dict, list, str into an object. - :return: object + :param data: dict, list or str. + :param klass: class literal, or string of class name. + + :return: object. """ if data is None: return None @@ -219,7 +253,7 @@ class ApiClient(object): for sub_data in data] if 'dict(' in klass: - sub_kls = re.match('dict\((.*), (.*)\)', klass).group(2) + sub_kls = re.match('dict\(([^,]*), (.*)\)', klass).group(2) return {k: self.__deserialize(v, sub_kls) for k, v in iteritems(data)} @@ -248,8 +282,7 @@ class ApiClient(object): body=None, post_params=None, files=None, response_type=None, auth_settings=None, callback=None): """ - Perform http request and return deserialized data - + Makes the HTTP request and return the deserialized data. :param resource_path: Path to method endpoint. :param method: Method to call. @@ -293,7 +326,7 @@ class ApiClient(object): def request(self, method, url, query_params=None, headers=None, post_params=None, body=None): """ - Perform http request using RESTClient. + Makes the HTTP request using RESTClient. """ if method == "GET": return RESTClient.GET(url, @@ -329,6 +362,13 @@ class ApiClient(object): ) def prepare_post_parameters(self, post_params=None, files=None): + """ + Builds form parameters. + + :param post_params: Normal form parameters. + :param files: File parameters. + :return: Form parameters with files. + """ params = {} if post_params: @@ -350,7 +390,10 @@ class ApiClient(object): def select_header_accept(self, accepts): """ - Return `Accept` based on an array of accepts provided + Returns `Accept` based on an array of accepts provided. + + :param accepts: List of headers. + :return: Accept (e.g. application/json). """ if not accepts: return @@ -364,7 +407,10 @@ class ApiClient(object): def select_header_content_type(self, content_types): """ - Return `Content-Type` baseed on an array of content_types provided + Returns `Content-Type` based on an array of content_types provided. + + :param content_types: List of content-types. + :return: Content-Type (e.g. application/json). """ if not content_types: return 'application/json' @@ -378,7 +424,11 @@ class ApiClient(object): def update_params_for_auth(self, headers, querys, auth_settings): """ - Update header and query params based on authentication setting + Updates header and query params based on authentication setting. + + :param headers: Header parameters dict to be updated. + :param querys: Query parameters dict to be updated. + :param auth_settings: Authentication setting identifiers list. """ config = Configuration() @@ -399,12 +449,12 @@ class ApiClient(object): def __deserialize_file(self, response): """ - Save response body into a file in (the defined) temporary folder, + Saves response body into a file in (the defined) temporary folder, using the filename from the `Content-Disposition` header if provided, otherwise a random filename. - :param response: RESTResponse - :return: file path + :param response: RESTResponse. + :return: file path. """ config = Configuration() @@ -426,12 +476,12 @@ class ApiClient(object): def __deserialize_primitive(self, data, klass): """ - Deserialize string to primitive type + Deserializes string to primitive type. - :param data: str - :param klass: class literal + :param data: str. + :param klass: class literal. - :return: int, float, str, bool + :return: int, float, str, bool. """ try: value = klass(data) @@ -443,16 +493,18 @@ class ApiClient(object): def __deserialize_object(self): """ - Deserialize empty object + Deserializes empty object. + + :return: object. """ return object() def __deserialize_date(self, string): """ - Deserialize string to date + Deserializes string to date. - :param string: str - :return: date + :param string: str. + :return: date. """ try: from dateutil.parser import parse @@ -468,12 +520,12 @@ class ApiClient(object): def __deserialize_datatime(self, string): """ - Deserialize string to datetime. + Deserializes string to datetime. The string should be in iso8601 datetime format. - :param string: str - :return: datetime + :param string: str. + :return: datetime. """ try: from dateutil.parser import parse @@ -489,10 +541,11 @@ class ApiClient(object): def __deserialize_model(self, data, klass): """ - Deserialize list or dict to model + Deserializes list or dict to model. - :param data: dict, list - :param klass: class literal + :param data: dict, list. + :param klass: class literal. + :return: model object. """ instance = klass() diff --git a/samples/client/petstore/python/swagger_client/apis/pet_api.py b/samples/client/petstore/python/swagger_client/apis/pet_api.py index 3f3e523a15a..1c34da118c1 100644 --- a/samples/client/petstore/python/swagger_client/apis/pet_api.py +++ b/samples/client/petstore/python/swagger_client/apis/pet_api.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # coding: utf-8 """ @@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - -NOTE: This class is auto generated by the swagger code generator program. - Do not edit the class manually. """ + from __future__ import absolute_import import sys @@ -33,6 +30,10 @@ from ..api_client import ApiClient class PetApi(object): + """ + NOTE: This class is auto generated by the swagger code generator program. + Do not edit the class manually. + """ def __init__(self, api_client=None): config = Configuration() diff --git a/samples/client/petstore/python/swagger_client/apis/store_api.py b/samples/client/petstore/python/swagger_client/apis/store_api.py index ac465f792ec..4dca0af85e2 100644 --- a/samples/client/petstore/python/swagger_client/apis/store_api.py +++ b/samples/client/petstore/python/swagger_client/apis/store_api.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # coding: utf-8 """ @@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - -NOTE: This class is auto generated by the swagger code generator program. - Do not edit the class manually. """ + from __future__ import absolute_import import sys @@ -33,6 +30,10 @@ from ..api_client import ApiClient class StoreApi(object): + """ + NOTE: This class is auto generated by the swagger code generator program. + Do not edit the class manually. + """ def __init__(self, api_client=None): config = Configuration() diff --git a/samples/client/petstore/python/swagger_client/apis/user_api.py b/samples/client/petstore/python/swagger_client/apis/user_api.py index 0469e83ae2f..4897abe8801 100644 --- a/samples/client/petstore/python/swagger_client/apis/user_api.py +++ b/samples/client/petstore/python/swagger_client/apis/user_api.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # coding: utf-8 """ @@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - -NOTE: This class is auto generated by the swagger code generator program. - Do not edit the class manually. """ + from __future__ import absolute_import import sys @@ -33,6 +30,10 @@ from ..api_client import ApiClient class UserApi(object): + """ + NOTE: This class is auto generated by the swagger code generator program. + Do not edit the class manually. + """ def __init__(self, api_client=None): config = Configuration() diff --git a/samples/client/petstore/python/swagger_client/configuration.py b/samples/client/petstore/python/swagger_client/configuration.py index 0fe945bee1b..a175303a222 100644 --- a/samples/client/petstore/python/swagger_client/configuration.py +++ b/samples/client/petstore/python/swagger_client/configuration.py @@ -1,3 +1,21 @@ +# coding: utf-8 + +""" +Copyright 2015 SmartBear Software + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" + from __future__ import absolute_import import base64 import urllib3 @@ -18,26 +36,45 @@ def singleton(cls, *args, **kw): @singleton class Configuration(object): + """ + NOTE: This class is auto generated by the swagger code generator program. + https://github.com/swagger-api/swagger-codegen + Do not edit the class manually. + """ def __init__(self): + """ + Constructor + """ # Default Base url self.host = "http://petstore.swagger.io/v2" # Default api client self.api_client = None - # Temp file folder + # Temp file folder for download self.temp_folder_path = None + # Authentication Settings + # dict to store API key(s) self.api_key = {} + # dict to store API prefix (e.g. Bearer) self.api_key_prefix = {} + # Username for HTTP basic authentication self.username = "" + # Password for HTTP basic authentication self.password = "" + # Logging Settings self.logging_format = '%(asctime)s %(levelname)s %(message)s' + # Debug file location self.__logging_file = None + # Debug switch self.__debug = False self.init_logger() def init_logger(self): + """ + Initializes logger settings. + """ self.logger = logging.getLogger() formatter = logging.Formatter(self.logging_format) stream_handler = logging.StreamHandler() @@ -82,20 +119,33 @@ class Configuration(object): # setting log level to default `logging.WARNING` self.logger.setLevel(logging.WARNING) - def get_api_key_with_prefix(self, key): - """ Return api key prepend prefix for key """ - if self.api_key.get(key) and self.api_key_prefix.get(key): - return self.api_key_prefix[key] + ' ' + self.api_key[key] - elif self.api_key.get(key): - return self.api_key[key] + def get_api_key_with_prefix(self, identifier): + """ + Gets API key (with prefix if set). + + :param identifier: The identifier of apiKey. + :return: The token for api key authentication. + """ + if self.api_key.get(identifier) and self.api_key_prefix.get(identifier): + return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier] + elif self.api_key.get(identifier): + return self.api_key[identifier] def get_basic_auth_token(self): - """ Return basic auth header string """ + """ + Gets basic auth header string. + + :return: The token for basic HTTP authentication. + """ return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\ .get('authorization') def auth_settings(self): - """ Return Auth Settings for api client """ + """ + Gets Auth Settings dict for api client. + + :return: The Auth Settings information dict. + """ return { 'api_key': { @@ -107,6 +157,11 @@ class Configuration(object): } def to_debug_report(self): + """ + Gets the essential information for debugging. + + :return: The report for debugging. + """ return "Python SDK Debug Report:\n"\ "OS: {env}\n"\ "Python Version: {pyversion}\n"\ diff --git a/samples/client/petstore/python/swagger_client/models/category.py b/samples/client/petstore/python/swagger_client/models/category.py index ae03bb7ec78..cba8855b1ba 100644 --- a/samples/client/petstore/python/swagger_client/models/category.py +++ b/samples/client/petstore/python/swagger_client/models/category.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # coding: utf-8 """ @@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software See the License for the specific language governing permissions and limitations under the License. """ + from pprint import pformat from six import iteritems diff --git a/samples/client/petstore/python/swagger_client/models/order.py b/samples/client/petstore/python/swagger_client/models/order.py index 7498561372e..0e75af96779 100644 --- a/samples/client/petstore/python/swagger_client/models/order.py +++ b/samples/client/petstore/python/swagger_client/models/order.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # coding: utf-8 """ @@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software See the License for the specific language governing permissions and limitations under the License. """ + from pprint import pformat from six import iteritems diff --git a/samples/client/petstore/python/swagger_client/models/pet.py b/samples/client/petstore/python/swagger_client/models/pet.py index 62f7bea7fd2..8c210525d3a 100644 --- a/samples/client/petstore/python/swagger_client/models/pet.py +++ b/samples/client/petstore/python/swagger_client/models/pet.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # coding: utf-8 """ @@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software See the License for the specific language governing permissions and limitations under the License. """ + from pprint import pformat from six import iteritems diff --git a/samples/client/petstore/python/swagger_client/models/tag.py b/samples/client/petstore/python/swagger_client/models/tag.py index ea07acacfdb..4f8ca6036e1 100644 --- a/samples/client/petstore/python/swagger_client/models/tag.py +++ b/samples/client/petstore/python/swagger_client/models/tag.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # coding: utf-8 """ @@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software See the License for the specific language governing permissions and limitations under the License. """ + from pprint import pformat from six import iteritems diff --git a/samples/client/petstore/python/swagger_client/models/user.py b/samples/client/petstore/python/swagger_client/models/user.py index d81a73318e7..4994ba691dc 100644 --- a/samples/client/petstore/python/swagger_client/models/user.py +++ b/samples/client/petstore/python/swagger_client/models/user.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # coding: utf-8 """ @@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software See the License for the specific language governing permissions and limitations under the License. """ + from pprint import pformat from six import iteritems diff --git a/samples/client/petstore/python/swagger_client/rest.py b/samples/client/petstore/python/swagger_client/rest.py index fab813a4cc9..f6161a6d60c 100644 --- a/samples/client/petstore/python/swagger_client/rest.py +++ b/samples/client/petstore/python/swagger_client/rest.py @@ -1,6 +1,20 @@ # coding: utf-8 """ +Copyright 2015 SmartBear Software + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + Credit: this file (rest.py) is modified based on rest.py in Dropbox Python SDK: https://www.dropbox.com/developers/core/sdks/python """ diff --git a/samples/client/petstore/python/tests/test_deserialization.py b/samples/client/petstore/python/tests/test_deserialization.py index 1121558adca..1eae045ff76 100644 --- a/samples/client/petstore/python/tests/test_deserialization.py +++ b/samples/client/petstore/python/tests/test_deserialization.py @@ -150,6 +150,28 @@ class DeserializationTests(unittest.TestCase): self.assertEqual(deserialized[0].name, "doggie0") self.assertEqual(deserialized[1].name, "doggie1") + def test_deserialize_nested_dict(self): + """ deserialize dict(str, dict(str, int)) """ + data = { + "foo": { + "bar": 1 + } + } + + deserialized = self.deserialize(data, "dict(str, dict(str, int))") + self.assertTrue(isinstance(deserialized, dict)) + self.assertTrue(isinstance(deserialized["foo"], dict)) + self.assertTrue(isinstance(deserialized["foo"]["bar"], int)) + + def test_deserialize_nested_list(self): + """ deserialize list[list[str]] """ + data = [["foo"]] + + deserialized = self.deserialize(data, "list[list[str]]") + self.assertTrue(isinstance(deserialized, list)) + self.assertTrue(isinstance(deserialized[0], list)) + self.assertTrue(isinstance(deserialized[0][0], str)) + def test_deserialize_none(self): """ deserialize None """ deserialized = self.deserialize(None, "datetime")