Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

v3 fixes type errors #175

Merged
merged 41 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
97102d9
Fixes errors in server.py
spacether May 23, 2023
1a3961e
Fixes some errors in server py files
spacether May 23, 2023
43777b9
Fixes schema_config type error
spacether May 23, 2023
3a6ffd2
Fixes errors in api_configuration
spacether May 23, 2023
f860369
Adds type ignoring for enum values, schemas fixed
spacether May 23, 2023
e915f79
Fixes python tests
spacether May 23, 2023
053d305
Moves ApiException back into the exceptions module
spacether May 23, 2023
a1eb6a8
Fixes timeout type and rest client response type
spacether May 23, 2023
818e99f
Adds int input back into timeout, fixes type errors in rest.py
spacether May 23, 2023
9dd464d
Fixes decimal exponent access
spacether May 23, 2023
d766e50
Parameter content storage updated to tuple so code can see length 1
spacether May 23, 2023
8ebf356
Uses content tuple in serialize methods
spacether May 23, 2023
92ea3da
Adds __HeaderParameterBase to fix type error
spacether May 23, 2023
26ac470
Updates urllib3.HTTPResponse -> urllib3_response.BaseHTTPResponse
spacether May 23, 2023
8062cff
Adds _SERIALIZE_TYPES
spacether May 23, 2023
4020c85
Fixes explode type error
spacether May 23, 2023
bf9dd77
Fixes urllib3 response type + header and parameter schema references
spacether May 24, 2023
40671f2
Fixes response type, fixes api_response header type
spacether May 24, 2023
927b1bb
Fixes 2 type errors
spacether May 24, 2023
c147adb
Adds assertion
spacether May 24, 2023
111e0c5
Adds assertion
spacether May 24, 2023
1ef9a13
Adds from_tuples method and needed types
spacether May 24, 2023
1c41376
Fixes return type of __serialize_application_octet_stream
spacether May 24, 2023
9be7cd7
Fixes __serialize_json
spacether May 24, 2023
9f80a1b
Fixes __serialize_text_plain
spacether May 24, 2023
facc6c7
Fixes __serialize_application_x_www_form_data
spacether May 24, 2023
21edbe7
Fixes type error
spacether May 24, 2023
faccbda
Fixes __serialize_multipart_form_data
spacether May 24, 2023
95092d4
Fixes FieldValue types
spacether May 24, 2023
cc21551
Fixes uer agent type error
spacether May 24, 2023
42816a9
Fixes another type error
spacether May 24, 2023
d40ebcf
Fixes type error
spacether May 24, 2023
88e7aa5
Fixes type errors in security_schemes
spacether May 24, 2023
49de3c4
Fixes errors in two tests
spacether May 24, 2023
8b6a89d
Fixes more type errors
spacether May 24, 2023
59d525d
Fixes error in get_server_url invocation
spacether May 24, 2023
bb2adb5
Fixes parameter and header serialization/deserialization
spacether May 24, 2023
b2d89e0
Fixes content references
spacether May 24, 2023
f977a12
Fixes parameter tests
spacether May 24, 2023
42a20ae
Fixes last python test errors
spacether May 24, 2023
cb60906
Samples regen
spacether May 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ public void processOpts() {
}

supportingFiles.add(new SupportingFile("api_client.hbs", packagePath(), "api_client.py"));
supportingFiles.add(new SupportingFile("api_response.hbs", packagePath(), "api_response.py"));
supportingFiles.add(new SupportingFile("rest.hbs", packagePath(), "rest.py"));
supportingFiles.add(new SupportingFile("schemas.hbs", packagePath(), "schemas.py"));
supportingFiles.add(new SupportingFile("security_schemes.hbs", packagePath(), "security_schemes.py"));
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# coding: utf-8
{{> _helper_header }}

import dataclasses
import typing

import typing_extensions
import urllib3

from {{packageName}} import schemas


@dataclasses.dataclass
class ApiResponse:
response: urllib3.HTTPResponse
body: typing.Union[schemas.Unset, schemas.Schema] = schemas.unset
headers: typing.Union[schemas.Unset, typing_extensions.TypedDict] = schemas.unset


@dataclasses.dataclass
class ApiResponseWithoutDeserialization(ApiResponse):
response: urllib3.HTTPResponse
body: typing.Union[schemas.Unset, schemas.Schema] = schemas.unset
headers: typing.Union[schemas.Unset, typing_extensions.TypedDict] = schemas.unset
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,17 @@ class {{jsonPathPiece.camelCase}}(api_client.{{#if noName}}Header{{/if}}{{#eq in
{{/with}}
{{/with}}
{{/each}}
{{#each content}}
Content = typing_extensions.TypedDict(
'Content',
{
{{#each content}}
'{{{@key.original}}}': typing.Type[{{@key.camelCase}}MediaType],
{{/each}}
}
)
content: Content = {
{{#each content}}
'{{{@key.original}}}': {{@key.camelCase}}MediaType,
{{/each}}
}
{{/each}}
{{/if}}
{{#if required}}
required = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from .headers import {{jsonPathPiece.snakeCase}}


@dataclasses.dataclass
class Api{{jsonPathPiece.camelCase}}(api_client.ApiResponse):
class Api{{jsonPathPiece.camelCase}}(api_response.ApiResponse):
response: urllib3.HTTPResponse
{{#and headers content}}
{{#if hasContentSchema}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
@schemas.classproperty
def {{this}}(cls):
{{#eq @key.type "string"}}
return cls("{{{@key.value}}}")
return cls("{{{@key.value}}}") # type: ignore
{{/eq}}
{{#eq @key.type "number"}}
return cls({{{@key.value}}})
return cls({{{@key.value}}}) # type: ignore
{{/eq}}
{{#eq @key.type "integer"}}
return cls({{{@key.value}}})
return cls({{{@key.value}}}) # type: ignore
{{/eq}}
{{#eq @key.type "boolean"}}
{{#if @key.value}}
return cls(True)
return cls(True) # type: ignore
{{else}}
return cls(False)
return cls(False) # type: ignore
{{/if}}
{{/eq}}
{{#eq @key.type "null"}}
return cls(None)
return cls(None) # type: ignore
{{/eq}}
{{/each}}
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class ApiConfiguration(object):
used_index = self.server_index_info[key_prefix]
except KeyError:
# fallback and use the default index
used_index = self.server_index_info["servers"]
used_index = self.server_index_info.get("servers", 0)
server = self.server_info[f"{key_prefix}/{used_index}"]
return server.url
{{#if securitySchemes}}
Expand All @@ -431,6 +431,6 @@ class ApiConfiguration(object):
used_index = self.security_index_info[key_prefix]
except KeyError:
# fallback and use the default index
used_index = self.security_index_info["security"]
used_index = self.security_index_info.get("security", 0)
return security_requirement_objects[used_index]
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SchemaConfiguration:

def __init__(
self,
disabled_json_schema_keywords = frozenset(),
disabled_json_schema_keywords = set(),
):
"""Constructor
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
# coding: utf-8

{{> _helper_header }}

import dataclasses
import typing

from urllib3._collections import HTTPHeaderDict
from {{packageName}} import api_response


class OpenApiException(Exception):
"""The base exception class for all OpenAPIExceptions"""

def render_path(path_to_item):
"""Returns a string representation of a path"""
result = ""
for pth in path_to_item:
if isinstance(pth, int):
result += "[{0}]".format(pth)
else:
result += "['{0}']".format(pth)
return result


class ApiTypeError(OpenApiException, TypeError):
def __init__(self, msg, path_to_item=None, valid_classes=None,
Expand Down Expand Up @@ -93,14 +104,13 @@ class ApiKeyError(OpenApiException, KeyError):
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
super(ApiKeyError, self).__init__(full_msg)


T = typing.TypeVar("T")
T = typing.TypeVar('T', bound=api_response.ApiResponse)


@dataclasses.dataclass
class ApiException(OpenApiException, typing.Generic[T]):
status: int
reason: str
reason: typing.Optional[str] = None
api_response: typing.Optional[T] = None

def __str__(self):
Expand All @@ -115,14 +125,3 @@ class ApiException(OpenApiException, typing.Generic[T]):
error_message += "HTTP response body: {0}\n".format(self.api_response.response.data)

return error_message


def render_path(path_to_item):
"""Returns a string representation of a path"""
result = ""
for pth in path_to_item:
if isinstance(pth, int):
result += "[{0}]".format(pth)
else:
result += "['{0}']".format(pth)
return result
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
cookie_params: RequestCookieParameters.Params = frozendict.frozendict(),
{{/if}}
{{#if produces}}
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
{{/if}}
{{#neq security null}}
{{#gt security.size 0}}
Expand All @@ -36,7 +36,7 @@
{{/neq}}
server_index: typing.Optional[int] = None,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
{{#if isOverload}}
{{#eq skipDeserialization "False"}}
skip_deserialization: typing_extensions.Literal[False] = ...,
Expand All @@ -48,10 +48,10 @@
skip_deserialization: bool = False,
{{/if}}
{{#eq skipDeserialization "True"}}
) -> api_client.ApiResponseWithoutDeserialization: ...
) -> api_response.ApiResponseWithoutDeserialization: ...
{{/eq}}
{{#eq skipDeserialization "False"}}
) -> {{#if getAllResponsesAreErrors}}api_client.ApiResponseWithoutDeserialization: ...{{else}}{{#gt getNonErrorResponses.size 1}}typing.Union[
) -> {{#if getAllResponsesAreErrors}}api_response.ApiResponseWithoutDeserialization: ...{{else}}{{#gt getNonErrorResponses.size 1}}typing.Union[
{{> paths/path/verb/_helper_operation_response_type_hint multiple=true }}
]{{else}}{{> paths/path/verb/_helper_operation_response_type_hint multiple=false }}{{/gt}}: ...
{{/if}}
Expand All @@ -60,7 +60,7 @@
{{#if isOverload}}
) -> typing.Union[
{{> paths/path/verb/_helper_operation_response_type_hint multiple=true }}
api_client.ApiResponseWithoutDeserialization,
api_response.ApiResponseWithoutDeserialization,
]: ...
{{else}}
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class BaseApi(api_client.Api):
{{else}}
{{#if pathItem.servers}}
host = self.api_client.configuration.get_server_url(
'paths/' + path + '/' + '/servers', server_index
'paths/' + path + '/servers', server_index
)
{{else}}
host = self.api_client.configuration.get_server_url(
Expand Down Expand Up @@ -281,7 +281,7 @@ class BaseApi(api_client.Api):
{{/neq}}
{{/neq}}

response = self.api_client.call_api(
raw_response = self.api_client.call_api(
resource_path=used_path,
method='{{httpMethod.original}}',
host=host,
Expand All @@ -308,10 +308,10 @@ class BaseApi(api_client.Api):
)

if skip_deserialization:
api_response = api_client.ApiResponseWithoutDeserialization(response=response)
response = api_response.ApiResponseWithoutDeserialization(response=raw_response)
else:
{{#if nonDefaultResponses}}
status = str(response.status)
status = str(raw_response.status)
{{#if wildcardCodeResponses}}
ranged_response_status_code = status[0]
{{/if}}
Expand All @@ -322,17 +322,17 @@ class BaseApi(api_client.Api):
'{{@key}}',
{{/each}}
]
api_response = _status_code_to_response[status].deserialize(
response, self.api_client.schema_configuration)
response = _status_code_to_response[status].deserialize(
raw_response, self.api_client.schema_configuration)
{{#if wildcardCodeResponses}}
elif ranged_response_status_code in _ranged_status_code_to_response:
ranged_response_status_code: typing_extensions.Literal[
{{#each wildcardCodeResponses}}
'{{@key}}',
{{/each}}
]
api_response = _ranged_status_code_to_response[ranged_response_status_code].deserialize(
response, self.api_client.schema_configuration)
response = _ranged_status_code_to_response[ranged_response_status_code].deserialize(
raw_response, self.api_client.schema_configuration)
{{/if}}
{{else}}
if ranged_response_status_code in _ranged_status_code_to_response:
Expand All @@ -341,26 +341,26 @@ class BaseApi(api_client.Api):
'{{@key}}',
{{/each}}
]
api_response = _ranged_status_code_to_response[ranged_response_status_code].deserialize(
response, self.api_client.schema_configuration)
response = _ranged_status_code_to_response[ranged_response_status_code].deserialize(
raw_response, self.api_client.schema_configuration)
{{/if}}
else:
{{#if defaultResponse}}
api_response = default_response.deserialize(response, self.api_client.schema_configuration)
response = default_response.deserialize(raw_response, self.api_client.schema_configuration)
{{else}}
api_response = api_client.ApiResponseWithoutDeserialization(response=response)
response = api_response.ApiResponseWithoutDeserialization(response=raw_response)
{{/if}}
{{else}}
{{#if defaultResponse}}
api_response = default_response.deserialize(response, self.api_client.schema_configuration)
response = default_response.deserialize(raw_response, self.api_client.schema_configuration)
{{else}}
api_response = api_client.ApiResponseWithoutDeserialization(response=response)
response = api_response.ApiResponseWithoutDeserialization(response=raw_response)
{{/if}}
{{/if}}

self._verify_response_status(api_response)
self._verify_response_status(response)

return api_response
return response


class {{operationId.camelCase}}(BaseApi):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ accept_content_types | typing.Tuple[str] | default is ({{#each produces}}"{{{.}}
server_index | typing.Optional[int] | default is None | Allows one to select a different server
stream | bool | default is False | if True then the response.content will be streamed and loaded from a file like object. When downloading a file, set this to True to force the code to deserialize the content to a FileSchema file
timeout | typing.Optional[typing.Union[int, typing.Tuple]] | default is None | the timeout used by the rest client
skip_deserialization | bool | default is False | when True, headers and body will be unset and an instance of api_client.ApiResponseWithoutDeserialization will be returned
skip_deserialization | bool | default is False | when True, headers and body will be unset and an instance of api_response.ApiResponseWithoutDeserialization will be returned
{{#if requestBody}}
{{#unless requestBody.refInfo}}

Expand All @@ -118,7 +118,7 @@ skip_deserialization | bool | default is False | when True, headers and body wil

HTTP Status Code | Class | Description
------------- | ------------- | -------------
n/a | api_client.ApiResponseWithoutDeserialization | When skip_deserialization is True this response is returned
n/a | api_response.ApiResponseWithoutDeserialization | When skip_deserialization is True this response is returned
{{#if defaultResponse}}
{{#with defaultResponse}}
{{#if refInfo}}
Expand Down
Loading