Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime # noqa: F401
import decimal # noqa: F401
import functools # noqa: F401
import io # noqa: F401
import re # noqa: F401
import typing # noqa: F401
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import tornado.gen
import frozendict

from {{packageName}} import exceptions, rest, schemas, security_schemes
from {{packageName}}.configurations import schema_configuration, api_configuration
from {{packageName}}.configurations import api_configuration, schema_configuration as schema_configuration_


class RequestField(fields.RequestField):
Expand Down Expand Up @@ -77,18 +77,16 @@ class ParameterStyle(enum.Enum):
DEEP_OBJECT = 'deepObject'


@dataclasses.dataclass
class PrefixSeparatorIterator:
# A class to store prefixes and separators for rfc6570 expansions
prefix: str
separator: str
first: bool = True
item_separator: str = dataclasses.field(init=False)

def __init__(self, prefix: str, separator: str):
self.prefix = prefix
self.separator = separator
self.first = True
if separator in {'.', '|', '%20'}:
item_separator = separator
else:
item_separator = ','
self.item_separator = item_separator
def __post_init__(self):
self.item_separator = self.separator if self.separator in {'.', '|', '%20'} else ','

def __iter__(self):
return self
Expand Down Expand Up @@ -331,20 +329,13 @@ class JSONDetector:
return False


@dataclasses.dataclass
class Encoding:
def __init__(
self,
content_type: str,
headers: typing.Optional[typing.Dict[str, 'HeaderParameter']] = None,
style: typing.Optional[ParameterStyle] = None,
explode: bool = False,
allow_reserved: bool = False,
):
self.content_type = content_type
self.headers = headers
self.style = style
self.explode = explode
self.allow_reserved = allow_reserved
content_type: str
headers: typing.Optional[typing.Dict[str, 'HeaderParameter']] = None
style: typing.Optional[ParameterStyle] = None
explode: bool = False
allow_reserved: bool = False


@dataclasses.dataclass
Expand Down Expand Up @@ -730,19 +721,6 @@ class ApiResponse:
body: typing.Union[schemas.Unset, schemas.Schema] = schemas.unset
headers: typing.Union[schemas.Unset, typing.Dict[str, schemas.Schema]] = schemas.unset

def __init__(
self,
response: urllib3.HTTPResponse,
body: typing.Union[schemas.Unset, schemas.Schema] = schemas.unset,
headers: typing.Union[schemas.Unset, typing.Dict[str, schemas.Schema]] = schemas.unset
):
"""
pycharm needs this to prevent 'Unexpected argument' warnings
"""
self.response = response
self.body = body
self.headers = headers


@dataclasses.dataclass
class ApiResponseWithoutDeserialization(ApiResponse):
Expand Down Expand Up @@ -883,7 +861,7 @@ class OpenApiResponse(JSONDetector, TypedDictInputVerifier, typing.Generic[T]):
}

@classmethod
def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_configuration.SchemaConfiguration) -> T:
def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_configuration_.SchemaConfiguration) -> T:
content_type = response.headers.get('content-type')
deserialized_body = schemas.unset
streamed = response.supports_chunked_reads()
Expand Down Expand Up @@ -935,6 +913,7 @@ class OpenApiResponse(JSONDetector, TypedDictInputVerifier, typing.Generic[T]):
)


@dataclasses.dataclass
class ApiClient:
"""Generic API client for OpenAPI client library builds.

Expand All @@ -948,37 +927,25 @@ class ApiClient:
Do not edit the class manually.

:param configuration: api_configuration.ApiConfiguration object for this client
:param schema_configuration: schema_configuration.SchemaConfiguration object for this client
: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.
:param cookie: a cookie to include in the header when making calls
to the API
:param schema_configuration: schema_configuration_.SchemaConfiguration object for this client
:param default_headers: any default headers to include when making calls to the API.
:param pool_threads: The number of threads to use for async requests
to the API. More threads means more concurrent API requests.
"""

_pool = None

def __init__(
self,
configuration: typing.Optional[api_configuration.ApiConfiguration] = None,
schema_config: typing.Optional[schema_configuration.SchemaConfiguration] = None,
header_name: typing.Optional[str] = None,
header_value: typing.Optional[str] = None,
cookie: typing.Optional[str] = None,
pool_threads: int = 1
):
self.configuration: api_configuration.ApiConfiguration = configuration or api_configuration.ApiConfiguration()
self.schema_configuration: schema_configuration.SchemaConfiguration = schema_config or schema_configuration.SchemaConfiguration()
self.pool_threads = pool_threads
self.rest_client = rest.RESTClientObject(self.configuration)
self.default_headers = _collections.HTTPHeaderDict()
if header_name is not None:
self.default_headers[header_name] = header_value
self.cookie = cookie
# Set default User-Agent.
configuration: api_configuration.ApiConfiguration = dataclasses.field(
default_factory=lambda: api_configuration.ApiConfiguration())
schema_configuration: schema_configuration_.SchemaConfiguration = dataclasses.field(
default_factory=lambda: schema_configuration_.SchemaConfiguration())
default_headers: _collections.HTTPHeaderDict = dataclasses.field(
default_factory=lambda: _collections.HTTPHeaderDict())
pool_threads: int = 1
user_agent: str = dataclasses.field(init=False)
rest_client: rest.RESTClientObject = dataclasses.field(init=False)

def __post_init__(self):
self._pool = None
self.user_agent = '{{#if httpUserAgent}}{{{httpUserAgent}}}{{/if}}{{#unless httpUserAgent}}OpenAPI-JSON-Schema-Generator/{{{packageVersion}}}/python{{/unless}}'
self.rest_client = rest.RESTClientObject(self.configuration)

def __enter__(self):
return self
Expand Down Expand Up @@ -1016,26 +983,46 @@ class ApiClient:
def set_default_header(self, header_name, header_value):
self.default_headers[header_name] = header_value

{{#if tornado}}
@tornado.gen.coroutine
{{/if}}
{{#if asyncio}}async {{/if}}def __call_api(
def call_api(
self,
resource_path: str,
method: str,
host: str,
headers: typing.Optional[_collections.HTTPHeaderDict] = None,
body: typing.Optional[typing.Union[str, bytes]] = None,
body: typing.Union[str, bytes, None] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
security_requirement_object: typing.Optional[security_schemes.SecurityRequirementObject] = None,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
timeout: typing.Union[int, typing.Tuple, None] = None,
) -> urllib3.HTTPResponse:
"""Makes the HTTP request (synchronous) and returns deserialized data.

:param resource_path: Path to method endpoint.
:param method: Method to call.
:param headers: Header parameters to be
placed in the request header.
:param body: Request body.
:param fields: Request post form parameters,
for `application/x-www-form-urlencoded`, `multipart/form-data`
:param security_requirement_object: The security requirement object, used to apply auth when making the call
:param async_req: execute request asynchronously
:param stream: if True, the urllib3.HTTPResponse object will
be returned without reading/decoding response
data. Also when True, if the openapi spec describes a file download,
the data will be written to a local filesystem file and the schemas.BinarySchema
instance will also inherit from FileSchema and schemas.FileIO
Default is False.
:type stream: bool, optional
:param timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:param host: api endpoint host
:return:
the method will return the response directly.
"""
# header parameters
used_headers = _collections.HTTPHeaderDict(self.default_headers)
if self.cookie:
headers['Cookie'] = self.cookie

# auth setting
self.update_params_for_auth(
Expand All @@ -1046,7 +1033,7 @@ class ApiClient:
body
)

# must happen after cookie setting and auth setting in case user is overriding those
# must happen after auth setting in case user is overriding those
if headers:
used_headers.update(headers)

Expand All @@ -1065,91 +1052,15 @@ class ApiClient:
)
return response

def call_api(
self,
resource_path: str,
method: str,
host: str,
headers: typing.Optional[_collections.HTTPHeaderDict] = None,
body: typing.Optional[typing.Union[str, bytes]] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
security_requirement_object: typing.Optional[security_schemes.SecurityRequirementObject] = None,
async_req: typing.Optional[bool] = None,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
) -> urllib3.HTTPResponse:
"""Makes the HTTP request (synchronous) and returns deserialized data.

To make an async_req request, set the async_req parameter.

:param resource_path: Path to method endpoint.
:param method: Method to call.
:param headers: Header parameters to be
placed in the request header.
:param body: Request body.
:param fields: Request post form parameters,
for `application/x-www-form-urlencoded`, `multipart/form-data`
:param security_requirement_object: The security requirement object, used to apply auth when making the call
:param async_req: execute request asynchronously
:type async_req: bool, optional TODO remove, unused
:param stream: if True, the urllib3.HTTPResponse object will
be returned without reading/decoding response
data. Also when True, if the openapi spec describes a file download,
the data will be written to a local filesystem file and the schemas.BinarySchema
instance will also inherit from FileSchema and schemas.FileIO
Default is False.
:type stream: bool, optional
:param timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:param host: api endpoint host
:return:
If async_req parameter is True,
the request will be called asynchronously.
The method will return the request thread.
If parameter async_req is False or missing,
then the method will return the response directly.
"""

if not async_req:
return self.__call_api(
resource_path,
method,
host,
headers,
body,
fields,
security_requirement_object,
stream,
timeout,
)

return self.pool.apply_async(
self.__call_api,
(
resource_path,
method,
host,
headers,
body,
json,
fields,
security_requirement_object,
stream,
timeout,
)
)

def request(
self,
method: str,
url: str,
headers: typing.Optional[_collections.HTTPHeaderDict] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
body: typing.Optional[typing.Union[str, bytes]] = None,
body: typing.Union[str, bytes, None] = None,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
timeout: typing.Union[int, typing.Tuple, None] = None,
) -> urllib3.HTTPResponse:
"""Makes the HTTP request using RESTClient."""
if method == "get":
Expand Down Expand Up @@ -1208,7 +1119,7 @@ class ApiClient:
security_requirement_object: typing.Optional[security_schemes.SecurityRequirementObject],
resource_path: str,
method: str,
body: typing.Optional[typing.Union[str, bytes]] = None
body: typing.Union[str, bytes, None] = None
):
"""Updates header and query params based on authentication setting.

Expand All @@ -1232,16 +1143,14 @@ class ApiClient:
scope_names
)


@dataclasses.dataclass
class Api(TypedDictInputVerifier):
"""NOTE: This class is auto generated by OpenAPI JSON Schema Generator
Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator

Do not edit the class manually.
"""

def __init__(self, api_client: typing.Optional[ApiClient] = None):
self.api_client: ApiClient = api_client or ApiClient()
api_client: ApiClient = dataclasses.field(default_factory=lambda: ApiClient())


class SerializedRequestBody(typing_extensions.TypedDict, total=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
{{> _helper_imports }}
{{jsonPathPiece.camelCase}} = {{refInfo.refModule}}.{{refInfo.refClass}}
{{else}}
{{#if content}}
import typing
import typing_extensions

{{/if}}
from {{packageName}} import api_client
{{#if schema}}
{{#with schema}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
{{> _helper_imports }}
{{jsonPathPiece.camelCase}} = {{refInfo.refModule}}.{{refInfo.refClass}}
{{else}}
{{#if content}}
import typing
import typing_extensions

{{/if}}
from {{packageName}} import api_client

{{#if schema}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@
{{jsonPathPiece.camelCase}} = {{refInfo.refModule}}.{{refInfo.refClass}}
{{else}}
import dataclasses
{{#or content headers}}
{{#if headers}}
import datetime
import decimal
import io
{{/if}}
import typing
{{#if headers}}
import uuid
{{/if}}

{{#if headers}}
import frozendict
{{/if}}
import typing_extensions
{{/or}}
import urllib3

from {{packageName}} import api_client
Expand Down
Loading