Skip to content

Commit b27bdf0

Browse files
authored
Merge pull request #3 from openapi-json-schema-tools/oajs_count_analysis
Updates python client + line count details
2 parents d7e1b8b + a34f4dc commit b27bdf0

File tree

129 files changed

+96
-536
lines changed

Some content is hidden

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

129 files changed

+96
-536
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ via vscode code counter tool
2929

3030

3131
### openapi_json_schema_generator_python breakdown
32-
- 7.8k src/openapi_client/paths
32+
- 5.7k src/openapi_client/paths
33+
- ~ 50% of this is in operation.py
34+
- 3.3k 7 files in src/openapi_client
35+
- api_client.py + schemas.py are big
3336
- most of this comes from the 3x operation typing overloads
3437

3538
Reasons for the openapi json scheme generator difference

petstore/openapi_json_schema_generator_python/.openapi-generator/FILES

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.gitignore
22
.gitlab-ci.yml
3+
.openapi-generator-ignore
34
.travis.yml
45
README.md
56
docs/apis/tags/pet_api.md
@@ -365,6 +366,12 @@ test-requirements.txt
365366
test/__init__.py
366367
test/components/__init__.py
367368
test/components/schema/__init__.py
369+
test/components/schema/test_api_response.py
370+
test/components/schema/test_category.py
371+
test/components/schema/test_order.py
372+
test/components/schema/test_pet.py
373+
test/components/schema/test_tag.py
374+
test/components/schema/test_user.py
368375
test/test_paths/__init__.py
369376
test/test_paths/__init__.py
370377
test/test_paths/__init__.py

petstore/openapi_json_schema_generator_python/src/openapi_client/api_client.py

Lines changed: 65 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import frozendict
3030

3131
from openapi_client import exceptions, rest, schemas, security_schemes
32-
from openapi_client.configurations import schema_configuration, api_configuration
32+
from openapi_client.configurations import api_configuration, schema_configuration as schema_configuration_
3333

3434

3535
class RequestField(fields.RequestField):
@@ -81,18 +81,16 @@ class ParameterStyle(enum.Enum):
8181
DEEP_OBJECT = 'deepObject'
8282

8383

84+
@dataclasses.dataclass
8485
class PrefixSeparatorIterator:
8586
# A class to store prefixes and separators for rfc6570 expansions
87+
prefix: str
88+
separator: str
89+
first: bool = True
90+
item_separator: str = dataclasses.field(init=False)
8691

87-
def __init__(self, prefix: str, separator: str):
88-
self.prefix = prefix
89-
self.separator = separator
90-
self.first = True
91-
if separator in {'.', '|', '%20'}:
92-
item_separator = separator
93-
else:
94-
item_separator = ','
95-
self.item_separator = item_separator
92+
def __post_init__(self):
93+
self.item_separator = self.separator if self.separator in {'.', '|', '%20'} else ','
9694

9795
def __iter__(self):
9896
return self
@@ -335,20 +333,13 @@ def _content_type_is_json(cls, content_type: str) -> bool:
335333
return False
336334

337335

336+
@dataclasses.dataclass
338337
class Encoding:
339-
def __init__(
340-
self,
341-
content_type: str,
342-
headers: typing.Optional[typing.Dict[str, 'HeaderParameter']] = None,
343-
style: typing.Optional[ParameterStyle] = None,
344-
explode: bool = False,
345-
allow_reserved: bool = False,
346-
):
347-
self.content_type = content_type
348-
self.headers = headers
349-
self.style = style
350-
self.explode = explode
351-
self.allow_reserved = allow_reserved
338+
content_type: str
339+
headers: typing.Optional[typing.Dict[str, 'HeaderParameter']] = None
340+
style: typing.Optional[ParameterStyle] = None
341+
explode: bool = False
342+
allow_reserved: bool = False
352343

353344

354345
@dataclasses.dataclass
@@ -734,19 +725,6 @@ class ApiResponse:
734725
body: typing.Union[schemas.Unset, schemas.Schema] = schemas.unset
735726
headers: typing.Union[schemas.Unset, typing.Dict[str, schemas.Schema]] = schemas.unset
736727

737-
def __init__(
738-
self,
739-
response: urllib3.HTTPResponse,
740-
body: typing.Union[schemas.Unset, schemas.Schema] = schemas.unset,
741-
headers: typing.Union[schemas.Unset, typing.Dict[str, schemas.Schema]] = schemas.unset
742-
):
743-
"""
744-
pycharm needs this to prevent 'Unexpected argument' warnings
745-
"""
746-
self.response = response
747-
self.body = body
748-
self.headers = headers
749-
750728

751729
@dataclasses.dataclass
752730
class ApiResponseWithoutDeserialization(ApiResponse):
@@ -887,7 +865,7 @@ def __deserialize_multipart_form_data(
887865
}
888866

889867
@classmethod
890-
def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_configuration.SchemaConfiguration) -> T:
868+
def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_configuration_.SchemaConfiguration) -> T:
891869
content_type = response.headers.get('content-type')
892870
deserialized_body = schemas.unset
893871
streamed = response.supports_chunked_reads()
@@ -939,6 +917,7 @@ def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_confi
939917
)
940918

941919

920+
@dataclasses.dataclass
942921
class ApiClient:
943922
"""Generic API client for OpenAPI client library builds.
944923
@@ -952,37 +931,25 @@ class ApiClient:
952931
Do not edit the class manually.
953932
954933
:param configuration: api_configuration.ApiConfiguration object for this client
955-
:param schema_configuration: schema_configuration.SchemaConfiguration object for this client
956-
:param header_name: a header to pass when making calls to the API.
957-
:param header_value: a header value to pass when making calls to
958-
the API.
959-
:param cookie: a cookie to include in the header when making calls
960-
to the API
934+
:param schema_configuration: schema_configuration_.SchemaConfiguration object for this client
935+
:param default_headers: any default headers to include when making calls to the API.
961936
:param pool_threads: The number of threads to use for async requests
962937
to the API. More threads means more concurrent API requests.
963938
"""
964-
965-
_pool = None
966-
967-
def __init__(
968-
self,
969-
configuration: typing.Optional[api_configuration.ApiConfiguration] = None,
970-
schema_config: typing.Optional[schema_configuration.SchemaConfiguration] = None,
971-
header_name: typing.Optional[str] = None,
972-
header_value: typing.Optional[str] = None,
973-
cookie: typing.Optional[str] = None,
974-
pool_threads: int = 1
975-
):
976-
self.configuration: api_configuration.ApiConfiguration = configuration or api_configuration.ApiConfiguration()
977-
self.schema_configuration: schema_configuration.SchemaConfiguration = schema_config or schema_configuration.SchemaConfiguration()
978-
self.pool_threads = pool_threads
979-
self.rest_client = rest.RESTClientObject(self.configuration)
980-
self.default_headers = _collections.HTTPHeaderDict()
981-
if header_name is not None:
982-
self.default_headers[header_name] = header_value
983-
self.cookie = cookie
984-
# Set default User-Agent.
939+
configuration: api_configuration.ApiConfiguration = dataclasses.field(
940+
default_factory=lambda: api_configuration.ApiConfiguration())
941+
schema_configuration: schema_configuration_.SchemaConfiguration = dataclasses.field(
942+
default_factory=lambda: schema_configuration_.SchemaConfiguration())
943+
default_headers: _collections.HTTPHeaderDict = dataclasses.field(
944+
default_factory=lambda: _collections.HTTPHeaderDict())
945+
pool_threads: int = 1
946+
user_agent: str = dataclasses.field(init=False)
947+
rest_client: rest.RESTClientObject = dataclasses.field(init=False)
948+
949+
def __post_init__(self):
950+
self._pool = None
985951
self.user_agent = 'OpenAPI-JSON-Schema-Generator/1.0.0/python'
952+
self.rest_client = rest.RESTClientObject(self.configuration)
986953

987954
def __enter__(self):
988955
return self
@@ -1020,23 +987,46 @@ def user_agent(self, value):
1020987
def set_default_header(self, header_name, header_value):
1021988
self.default_headers[header_name] = header_value
1022989

1023-
def __call_api(
990+
def call_api(
1024991
self,
1025992
resource_path: str,
1026993
method: str,
1027994
host: str,
1028995
headers: typing.Optional[_collections.HTTPHeaderDict] = None,
1029-
body: typing.Optional[typing.Union[str, bytes]] = None,
996+
body: typing.Union[str, bytes, None] = None,
1030997
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
1031998
security_requirement_object: typing.Optional[security_schemes.SecurityRequirementObject] = None,
1032999
stream: bool = False,
1033-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
1000+
timeout: typing.Union[int, typing.Tuple, None] = None,
10341001
) -> urllib3.HTTPResponse:
1002+
"""Makes the HTTP request (synchronous) and returns deserialized data.
10351003
1004+
:param resource_path: Path to method endpoint.
1005+
:param method: Method to call.
1006+
:param headers: Header parameters to be
1007+
placed in the request header.
1008+
:param body: Request body.
1009+
:param fields: Request post form parameters,
1010+
for `application/x-www-form-urlencoded`, `multipart/form-data`
1011+
:param security_requirement_object: The security requirement object, used to apply auth when making the call
1012+
:param async_req: execute request asynchronously
1013+
:param stream: if True, the urllib3.HTTPResponse object will
1014+
be returned without reading/decoding response
1015+
data. Also when True, if the openapi spec describes a file download,
1016+
the data will be written to a local filesystem file and the schemas.BinarySchema
1017+
instance will also inherit from FileSchema and schemas.FileIO
1018+
Default is False.
1019+
:type stream: bool, optional
1020+
:param timeout: timeout setting for this request. If one
1021+
number provided, it will be total request
1022+
timeout. It can also be a pair (tuple) of
1023+
(connection, read) timeouts.
1024+
:param host: api endpoint host
1025+
:return:
1026+
the method will return the response directly.
1027+
"""
10361028
# header parameters
10371029
used_headers = _collections.HTTPHeaderDict(self.default_headers)
1038-
if self.cookie:
1039-
headers['Cookie'] = self.cookie
10401030

10411031
# auth setting
10421032
self.update_params_for_auth(
@@ -1047,7 +1037,7 @@ def __call_api(
10471037
body
10481038
)
10491039

1050-
# must happen after cookie setting and auth setting in case user is overriding those
1040+
# must happen after auth setting in case user is overriding those
10511041
if headers:
10521042
used_headers.update(headers)
10531043

@@ -1066,91 +1056,15 @@ def __call_api(
10661056
)
10671057
return response
10681058

1069-
def call_api(
1070-
self,
1071-
resource_path: str,
1072-
method: str,
1073-
host: str,
1074-
headers: typing.Optional[_collections.HTTPHeaderDict] = None,
1075-
body: typing.Optional[typing.Union[str, bytes]] = None,
1076-
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
1077-
security_requirement_object: typing.Optional[security_schemes.SecurityRequirementObject] = None,
1078-
async_req: typing.Optional[bool] = None,
1079-
stream: bool = False,
1080-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
1081-
) -> urllib3.HTTPResponse:
1082-
"""Makes the HTTP request (synchronous) and returns deserialized data.
1083-
1084-
To make an async_req request, set the async_req parameter.
1085-
1086-
:param resource_path: Path to method endpoint.
1087-
:param method: Method to call.
1088-
:param headers: Header parameters to be
1089-
placed in the request header.
1090-
:param body: Request body.
1091-
:param fields: Request post form parameters,
1092-
for `application/x-www-form-urlencoded`, `multipart/form-data`
1093-
:param security_requirement_object: The security requirement object, used to apply auth when making the call
1094-
:param async_req: execute request asynchronously
1095-
:type async_req: bool, optional TODO remove, unused
1096-
:param stream: if True, the urllib3.HTTPResponse object will
1097-
be returned without reading/decoding response
1098-
data. Also when True, if the openapi spec describes a file download,
1099-
the data will be written to a local filesystem file and the schemas.BinarySchema
1100-
instance will also inherit from FileSchema and schemas.FileIO
1101-
Default is False.
1102-
:type stream: bool, optional
1103-
:param timeout: timeout setting for this request. If one
1104-
number provided, it will be total request
1105-
timeout. It can also be a pair (tuple) of
1106-
(connection, read) timeouts.
1107-
:param host: api endpoint host
1108-
:return:
1109-
If async_req parameter is True,
1110-
the request will be called asynchronously.
1111-
The method will return the request thread.
1112-
If parameter async_req is False or missing,
1113-
then the method will return the response directly.
1114-
"""
1115-
1116-
if not async_req:
1117-
return self.__call_api(
1118-
resource_path,
1119-
method,
1120-
host,
1121-
headers,
1122-
body,
1123-
fields,
1124-
security_requirement_object,
1125-
stream,
1126-
timeout,
1127-
)
1128-
1129-
return self.pool.apply_async(
1130-
self.__call_api,
1131-
(
1132-
resource_path,
1133-
method,
1134-
host,
1135-
headers,
1136-
body,
1137-
json,
1138-
fields,
1139-
security_requirement_object,
1140-
stream,
1141-
timeout,
1142-
)
1143-
)
1144-
11451059
def request(
11461060
self,
11471061
method: str,
11481062
url: str,
11491063
headers: typing.Optional[_collections.HTTPHeaderDict] = None,
11501064
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
1151-
body: typing.Optional[typing.Union[str, bytes]] = None,
1065+
body: typing.Union[str, bytes, None] = None,
11521066
stream: bool = False,
1153-
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
1067+
timeout: typing.Union[int, typing.Tuple, None] = None,
11541068
) -> urllib3.HTTPResponse:
11551069
"""Makes the HTTP request using RESTClient."""
11561070
if method == "get":
@@ -1209,7 +1123,7 @@ def update_params_for_auth(
12091123
security_requirement_object: typing.Optional[security_schemes.SecurityRequirementObject],
12101124
resource_path: str,
12111125
method: str,
1212-
body: typing.Optional[typing.Union[str, bytes]] = None
1126+
body: typing.Union[str, bytes, None] = None
12131127
):
12141128
"""Updates header and query params based on authentication setting.
12151129
@@ -1233,16 +1147,14 @@ def update_params_for_auth(
12331147
scope_names
12341148
)
12351149

1236-
1150+
@dataclasses.dataclass
12371151
class Api(TypedDictInputVerifier):
12381152
"""NOTE: This class is auto generated by OpenAPI JSON Schema Generator
12391153
Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
12401154
12411155
Do not edit the class manually.
12421156
"""
1243-
1244-
def __init__(self, api_client: typing.Optional[ApiClient] = None):
1245-
self.api_client: ApiClient = api_client or ApiClient()
1157+
api_client: ApiClient = dataclasses.field(default_factory=lambda: ApiClient())
12461158

12471159

12481160
class SerializedRequestBody(typing_extensions.TypedDict, total=False):

petstore/openapi_json_schema_generator_python/src/openapi_client/components/request_bodies/request_body_user_array/content/application_json/schema.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import datetime # noqa: F401
1313
import decimal # noqa: F401
14-
import functools # noqa: F401
1514
import io # noqa: F401
1615
import re # noqa: F401
1716
import typing # noqa: F401

petstore/openapi_json_schema_generator_python/src/openapi_client/components/schema/api_response.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import datetime # noqa: F401
1313
import decimal # noqa: F401
14-
import functools # noqa: F401
1514
import io # noqa: F401
1615
import re # noqa: F401
1716
import typing # noqa: F401

petstore/openapi_json_schema_generator_python/src/openapi_client/components/schema/category.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import datetime # noqa: F401
1313
import decimal # noqa: F401
14-
import functools # noqa: F401
1514
import io # noqa: F401
1615
import re # noqa: F401
1716
import typing # noqa: F401

petstore/openapi_json_schema_generator_python/src/openapi_client/components/schema/order.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import datetime # noqa: F401
1313
import decimal # noqa: F401
14-
import functools # noqa: F401
1514
import io # noqa: F401
1615
import re # noqa: F401
1716
import typing # noqa: F401

0 commit comments

Comments
 (0)