Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix objc wrapper request box default inclusion #322

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stone/backends/swift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
self._generate_client(api)
self._generate_request_boxes(api)
if not self.args.objc:
self._generate_reconnection_helpers(api)

Check warning on line 145 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L145

Added line #L145 was not covered by tests

def _generate_client(self, api):
template_globals = {}
Expand All @@ -168,7 +168,7 @@
namespace_fields = []
for namespace in api.namespaces.values():
if self._namespace_contains_valid_routes_for_auth_type(namespace):
namespace_fields.append((fmt_var(namespace.name),

Check warning on line 171 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L171

Added line #L171 was not covered by tests
fmt_class(self._class_name(namespace.name))))

return namespace_fields
Expand Down Expand Up @@ -206,7 +206,7 @@
template_globals['objc_init_args_to_swift'] = self._objc_init_args_to_swift
template_globals['objc_result_from_swift'] = self._objc_result_from_swift
template_globals['objc_no_defualts_func_args'] = self._objc_no_defualts_func_args
template_globals['objc_app_auth_route_wrapper_already_defined'] = \

Check warning on line 209 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L209

Added line #L209 was not covered by tests
self._objc_app_auth_route_wrapper_already_defined

ns_class = self._class_name(fmt_class(namespace.name))
Expand Down Expand Up @@ -240,17 +240,17 @@
template_globals['request_type_signature'] = self._request_type_signature
template_globals['fmt_func'] = fmt_func
template_globals['fmt_route_objc_class'] = self._fmt_route_objc_class
swift_class_name = '{}RequestBox'.format(self.args.class_name)

Check warning on line 243 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L243

Added line #L243 was not covered by tests

if self.args.objc:
template = self._jinja_template("ObjCRequestBox.jinja")
template.globals = template_globals

# don't include the default case in the generated switch statement if it's unreachable
include_default_in_switch = \
len(background_objc_routes) < len(background_compatible_routes)
include_default_in_switch = True

Check warning on line 250 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L250

Added line #L250 was not covered by tests
# TODO(jlocke): implement this to eliminate the unreachable code warning

output = template.render(

Check warning on line 253 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L253

Added line #L253 was not covered by tests
background_compatible_routes=background_compatible_routes,
background_objc_routes=background_objc_routes,
class_name=swift_class_name,
Expand All @@ -276,22 +276,22 @@
if len(background_compatible_pairs) == 0:
return

is_app_auth_client = self.args.auth_type == 'app'
class_name_prefix = 'AppAuth' if is_app_auth_client else ''
class_name = '{}ReconnectionHelpers'.format(class_name_prefix)
return_type = '{}RequestBox'.format(self.args.class_name)

Check warning on line 282 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L279-L282

Added lines #L279 - L282 were not covered by tests

template = self._jinja_template("SwiftReconnectionHelpers.jinja")
template.globals['fmt_func'] = fmt_func
template.globals['fmt_class'] = fmt_class
template.globals['class_name'] = class_name
template.globals['return_type'] = return_type

Check warning on line 288 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L287-L288

Added lines #L287 - L288 were not covered by tests

output_from_parsed_template = template.render(
background_compatible_namespace_route_pairs=background_compatible_pairs
)

self._write_output_in_target_folder(

Check warning on line 294 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L294

Added line #L294 was not covered by tests
output_from_parsed_template, '{}.swift'.format(class_name)
)

Expand Down Expand Up @@ -340,23 +340,23 @@
# if building the user or team client, include routes of all auth types except
# app auth exclusive routes

is_app_auth_only_route = route_auth_type == 'app'
route_auth_types_include_app = 'app' in route_auth_type

Check warning on line 344 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L343-L344

Added lines #L343 - L344 were not covered by tests

if client_auth_type == 'app':
return is_app_auth_only_route or route_auth_types_include_app

Check warning on line 347 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L347

Added line #L347 was not covered by tests
else:
return not is_app_auth_only_route

Check warning on line 349 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L349

Added line #L349 was not covered by tests

# The objc compatibility wrapper generates a class to wrap each route providing properly
# typed completion handlers without generics. User and App clients are generated in separate
# passes, and if the wrapper is already defined for the user client, we must skip generating
# a second definition of it for the app client.
def _objc_app_auth_route_wrapper_already_defined(self, route):
client_auth_type = self.args.auth_type
is_app_auth_client = client_auth_type == 'app'

Check warning on line 357 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L355-L357

Added lines #L355 - L357 were not covered by tests

return is_app_auth_client and route.attrs.get('auth') != 'app'

Check warning on line 359 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L359

Added line #L359 was not covered by tests

def _namespace_contains_valid_routes_for_auth_type(self, namespace):
valid_count = 0
Expand Down Expand Up @@ -565,7 +565,7 @@
objc_class_to_route = {}
for namespace in namespaces:
for route in namespace.routes:
bg_route_style = self._background_session_route_style(route)

Check warning on line 568 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L568

Added line #L568 was not covered by tests
if bg_route_style is not None and self._valid_route_for_auth_type(route):
args_data = self._route_client_args(route)[0]
objc_class = self._fmt_route_objc_class(namespace, route, args_data)
Expand Down Expand Up @@ -603,7 +603,7 @@
if is_user_defined_type(list_data_type):
objc_type = fmt_objc_type(list_data_type, False)
factory_func = '.factory' if is_union_type(list_data_type) else ''
factory_func = '.wrapPreservingSubtypes' if datatype_has_subtypes(data_type) \

Check warning on line 606 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L606

Added line #L606 was not covered by tests
else factory_func
value = '{}.map {}{{ {}{}(swift: $0) }}'.format(value,
prefix,
Expand All @@ -624,7 +624,7 @@
else:
objc_data_type = fmt_objc_type(data_type)
factory_func = '.factory' if is_union_type(data_type) else ''
factory_func = '.wrapPreservingSubtypes' if datatype_has_subtypes(data_type) \

Check warning on line 627 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L627

Added line #L627 was not covered by tests
else factory_func
return '{}{}(swift: {})'.format(objc_data_type,
factory_func,
Expand Down
Loading