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

Commit 3db1b61

Browse files
committed
v3 fixes type errors (#175)
* Fixes errors in server.py * Fixes some errors in server py files * Fixes schema_config type error * Fixes errors in api_configuration * Adds type ignoring for enum values, schemas fixed * Fixes python tests * Moves ApiException back into the exceptions module * Fixes timeout type and rest client response type * Adds int input back into timeout, fixes type errors in rest.py * Fixes decimal exponent access * Parameter content storage updated to tuple so code can see length 1 * Uses content tuple in serialize methods * Adds __HeaderParameterBase to fix type error * Updates urllib3.HTTPResponse -> urllib3_response.BaseHTTPResponse * Adds _SERIALIZE_TYPES * Fixes explode type error * Fixes urllib3 response type + header and parameter schema references * Fixes response type, fixes api_response header type * Fixes 2 type errors * Adds assertion * Adds assertion * Adds from_tuples method and needed types * Fixes return type of __serialize_application_octet_stream * Fixes __serialize_json * Fixes __serialize_text_plain * Fixes __serialize_application_x_www_form_data * Fixes type error * Fixes __serialize_multipart_form_data * Fixes FieldValue types * Fixes uer agent type error * Fixes another type error * Fixes type error * Fixes type errors in security_schemes * Fixes errors in two tests * Fixes more type errors * Fixes error in get_server_url invocation * Fixes parameter and header serialization/deserialization * Fixes content references * Fixes parameter tests * Fixes last python test errors * Samples regen
1 parent 3eff13f commit 3db1b61

856 files changed

Lines changed: 6269 additions & 5864 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/languages/PythonClientCodegen.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ public void processOpts() {
720720
}
721721

722722
supportingFiles.add(new SupportingFile("api_client.hbs", packagePath(), "api_client.py"));
723+
supportingFiles.add(new SupportingFile("api_response.hbs", packagePath(), "api_response.py"));
723724
supportingFiles.add(new SupportingFile("rest.hbs", packagePath(), "rest.py"));
724725
supportingFiles.add(new SupportingFile("schemas.hbs", packagePath(), "schemas.py"));
725726
supportingFiles.add(new SupportingFile("security_schemes.hbs", packagePath(), "security_schemes.py"));

modules/openapi-json-schema-generator/src/main/resources/python/api_client.hbs

Lines changed: 169 additions & 129 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# coding: utf-8
2+
{{> _helper_header }}
3+
4+
import dataclasses
5+
import typing
6+
7+
import typing_extensions
8+
import urllib3
9+
10+
from {{packageName}} import schemas
11+
12+
13+
@dataclasses.dataclass
14+
class ApiResponse:
15+
response: urllib3.HTTPResponse
16+
body: typing.Union[schemas.Unset, schemas.Schema] = schemas.unset
17+
headers: typing.Union[schemas.Unset, typing_extensions.TypedDict] = schemas.unset
18+
19+
20+
@dataclasses.dataclass
21+
class ApiResponseWithoutDeserialization(ApiResponse):
22+
response: urllib3.HTTPResponse
23+
body: typing.Union[schemas.Unset, schemas.Schema] = schemas.unset
24+
headers: typing.Union[schemas.Unset, typing_extensions.TypedDict] = schemas.unset

modules/openapi-json-schema-generator/src/main/resources/python/components/_helper_param_or_header_instance.hbs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,17 @@ class {{jsonPathPiece.camelCase}}(api_client.{{#if noName}}Header{{/if}}{{#eq in
4141
{{/with}}
4242
{{/with}}
4343
{{/each}}
44+
{{#each content}}
4445
Content = typing_extensions.TypedDict(
4546
'Content',
4647
{
47-
{{#each content}}
4848
'{{{@key.original}}}': typing.Type[{{@key.camelCase}}MediaType],
49-
{{/each}}
5049
}
5150
)
5251
content: Content = {
53-
{{#each content}}
5452
'{{{@key.original}}}': {{@key.camelCase}}MediaType,
55-
{{/each}}
5653
}
54+
{{/each}}
5755
{{/if}}
5856
{{#if required}}
5957
required = True

modules/openapi-json-schema-generator/src/main/resources/python/components/responses/response.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ from .headers import {{jsonPathPiece.snakeCase}}
3131

3232

3333
@dataclasses.dataclass
34-
class Api{{jsonPathPiece.camelCase}}(api_client.ApiResponse):
34+
class Api{{jsonPathPiece.camelCase}}(api_response.ApiResponse):
3535
response: urllib3.HTTPResponse
3636
{{#and headers content}}
3737
{{#if hasContentSchema}}

modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_enums.hbs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
@schemas.classproperty
55
def {{this}}(cls):
66
{{#eq @key.type "string"}}
7-
return cls("{{{@key.value}}}")
7+
return cls("{{{@key.value}}}") # type: ignore
88
{{/eq}}
99
{{#eq @key.type "number"}}
10-
return cls({{{@key.value}}})
10+
return cls({{{@key.value}}}) # type: ignore
1111
{{/eq}}
1212
{{#eq @key.type "integer"}}
13-
return cls({{{@key.value}}})
13+
return cls({{{@key.value}}}) # type: ignore
1414
{{/eq}}
1515
{{#eq @key.type "boolean"}}
1616
{{#if @key.value}}
17-
return cls(True)
17+
return cls(True) # type: ignore
1818
{{else}}
19-
return cls(False)
19+
return cls(False) # type: ignore
2020
{{/if}}
2121
{{/eq}}
2222
{{#eq @key.type "null"}}
23-
return cls(None)
23+
return cls(None) # type: ignore
2424
{{/eq}}
2525
{{/each}}
2626
{{/if}}

modules/openapi-json-schema-generator/src/main/resources/python/configurations/api_configuration.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ class ApiConfiguration(object):
421421
used_index = self.server_index_info[key_prefix]
422422
except KeyError:
423423
# fallback and use the default index
424-
used_index = self.server_index_info["servers"]
424+
used_index = self.server_index_info.get("servers", 0)
425425
server = self.server_info[f"{key_prefix}/{used_index}"]
426426
return server.url
427427
{{#if securitySchemes}}
@@ -443,6 +443,6 @@ class ApiConfiguration(object):
443443
used_index = self.security_index_info[key_prefix]
444444
except KeyError:
445445
# fallback and use the default index
446-
used_index = self.security_index_info["security"]
446+
used_index = self.security_index_info.get("security", 0)
447447
return security_requirement_objects[used_index]
448448
{{/if}}

modules/openapi-json-schema-generator/src/main/resources/python/configurations/schema_configuration.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class SchemaConfiguration:
6262

6363
def __init__(
6464
self,
65-
disabled_json_schema_keywords = frozenset(),
65+
disabled_json_schema_keywords = set(),
6666
):
6767
"""Constructor
6868
"""

modules/openapi-json-schema-generator/src/main/resources/python/exceptions.hbs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
# coding: utf-8
22

33
{{> _helper_header }}
4+
45
import dataclasses
56
import typing
67

7-
from urllib3._collections import HTTPHeaderDict
8+
from {{packageName}} import api_response
89

910

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

14+
def render_path(path_to_item):
15+
"""Returns a string representation of a path"""
16+
result = ""
17+
for pth in path_to_item:
18+
if isinstance(pth, int):
19+
result += "[{0}]".format(pth)
20+
else:
21+
result += "['{0}']".format(pth)
22+
return result
23+
1324

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

96-
97-
T = typing.TypeVar("T")
107+
T = typing.TypeVar('T', bound=api_response.ApiResponse)
98108

99109

100110
@dataclasses.dataclass
101111
class ApiException(OpenApiException, typing.Generic[T]):
102112
status: int
103-
reason: str
113+
reason: typing.Optional[str] = None
104114
api_response: typing.Optional[T] = None
105115

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

117127
return error_message
118-
119-
120-
def render_path(path_to_item):
121-
"""Returns a string representation of a path"""
122-
result = ""
123-
for pth in path_to_item:
124-
if isinstance(pth, int):
125-
result += "[{0}]".format(pth)
126-
else:
127-
result += "['{0}']".format(pth)
128-
return result

modules/openapi-json-schema-generator/src/main/resources/python/paths/path/verb/_helper_operation_args.hbs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
cookie_params: RequestCookieParameters.Params = frozendict.frozendict(),
2222
{{/if}}
2323
{{#if produces}}
24-
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
24+
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
2525
{{/if}}
2626
{{#neq security null}}
2727
{{#gt security.size 0}}
@@ -36,7 +36,7 @@
3636
{{/neq}}
3737
server_index: typing.Optional[int] = None,
3838
stream: bool = False,
39-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
39+
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
4040
{{#if isOverload}}
4141
{{#eq skipDeserialization "False"}}
4242
skip_deserialization: typing_extensions.Literal[False] = ...,
@@ -48,10 +48,10 @@
4848
skip_deserialization: bool = False,
4949
{{/if}}
5050
{{#eq skipDeserialization "True"}}
51-
) -> api_client.ApiResponseWithoutDeserialization: ...
51+
) -> api_response.ApiResponseWithoutDeserialization: ...
5252
{{/eq}}
5353
{{#eq skipDeserialization "False"}}
54-
) -> {{#if getAllResponsesAreErrors}}api_client.ApiResponseWithoutDeserialization: ...{{else}}{{#gt getNonErrorResponses.size 1}}typing.Union[
54+
) -> {{#if getAllResponsesAreErrors}}api_response.ApiResponseWithoutDeserialization: ...{{else}}{{#gt getNonErrorResponses.size 1}}typing.Union[
5555
{{> paths/path/verb/_helper_operation_response_type_hint multiple=true }}
5656
]{{else}}{{> paths/path/verb/_helper_operation_response_type_hint multiple=false }}{{/gt}}: ...
5757
{{/if}}
@@ -60,7 +60,7 @@
6060
{{#if isOverload}}
6161
) -> typing.Union[
6262
{{> paths/path/verb/_helper_operation_response_type_hint multiple=true }}
63-
api_client.ApiResponseWithoutDeserialization,
63+
api_response.ApiResponseWithoutDeserialization,
6464
]: ...
6565
{{else}}
6666
):

0 commit comments

Comments
 (0)