diff --git a/stone/backends/swift_client.py b/stone/backends/swift_client.py index fe1b673e..f580aa39 100644 --- a/stone/backends/swift_client.py +++ b/stone/backends/swift_client.py @@ -26,6 +26,8 @@ fmt_var, fmt_type, fmt_route_name, + fmt_route_name_namespace, + fmt_func_namespace, fmt_objc_type, mapped_list_info, datatype_has_subtypes, @@ -230,7 +232,7 @@ def _generate_routes(self, namespace): '{}Routes.swift'.format(ns_class)) def _generate_request_boxes(self, api): - background_compatible_routes = self._background_compatible_routes(api) + background_compatible_routes = self._background_compatible_namespace_route_pairs(api) if len(background_compatible_routes) == 0: return @@ -241,6 +243,8 @@ def _generate_request_boxes(self, api): 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 + template_globals['fmt_func_namespace'] = fmt_func_namespace + template_globals['fmt_route_name_namespace'] = fmt_route_name_namespace swift_class_name = '{}RequestBox'.format(self.args.class_name) if self.args.objc: @@ -284,6 +288,8 @@ def _generate_reconnection_helpers(self, api): template = self._jinja_template("SwiftReconnectionHelpers.jinja") template.globals['fmt_route_name'] = fmt_route_name + template.globals['fmt_route_name_namespace'] = fmt_route_name_namespace + template.globals['fmt_func_namespace'] = fmt_func_namespace template.globals['fmt_func'] = fmt_func template.globals['fmt_class'] = fmt_class template.globals['class_name'] = class_name @@ -297,10 +303,6 @@ def _generate_reconnection_helpers(self, api): output_from_parsed_template, '{}.swift'.format(class_name) ) - def _background_compatible_routes(self, api): - background_compatible_pairs = self._background_compatible_namespace_route_pairs(api) - return list(map(lambda arg_data: arg_data[1], background_compatible_pairs)) - def _background_compatible_namespace_route_pairs(self, api): namespaces = api.namespaces.values() background_compatible_routes = [] diff --git a/stone/backends/swift_helpers.py b/stone/backends/swift_helpers.py index ef934289..a6d2499d 100644 --- a/stone/backends/swift_helpers.py +++ b/stone/backends/swift_helpers.py @@ -198,13 +198,17 @@ def fmt_default_value(field): raise TypeError('Can\'t handle default value type %r' % type(field.data_type)) - def fmt_route_name(route): if route.version == 1: return route.name else: return '{}_v{}'.format(route.name, route.version) +def fmt_route_name_namespace(route, namespace_name): + return '{}/{}'.format(namespace_name, fmt_route_name(route)) + +def fmt_func_namespace(name, version, namespace_name): + return '{}_{}'.format(namespace_name, fmt_func(name, version)) def check_route_name_conflict(namespace): """ diff --git a/stone/backends/swift_rsrc/ObjCRequestBox.jinja b/stone/backends/swift_rsrc/ObjCRequestBox.jinja index 46e89f87..4ca3cb32 100644 --- a/stone/backends/swift_rsrc/ObjCRequestBox.jinja +++ b/stone/backends/swift_rsrc/ObjCRequestBox.jinja @@ -14,7 +14,7 @@ extension {{ class_name }} { {% set namespace = route_args_data[0] %} {% set route = route_args_data[1] %} {% set args_data = route_args_data[2] %} - case .{{ fmt_func(route.name, route.version) }}(let swift): + case .{{ fmt_func_namespace(route.name, route.version, namespace.name) }}(let swift): return {{ fmt_route_objc_class(namespace, route, args_data) }}(swift: swift) {% endfor %} {% if include_default_in_switch %} diff --git a/stone/backends/swift_rsrc/SwiftReconnectionHelpers.jinja b/stone/backends/swift_rsrc/SwiftReconnectionHelpers.jinja index e1351a78..83e894f1 100644 --- a/stone/backends/swift_rsrc/SwiftReconnectionHelpers.jinja +++ b/stone/backends/swift_rsrc/SwiftReconnectionHelpers.jinja @@ -4,15 +4,21 @@ import Foundation +// The case string below must match those created by ReconnectionHelpers+Handwritten.swift using +// the route name and namespace as formatted for the generated `Route` object in SwiftTypes.jinja +// Format: "/" e.g., "files/upload_session/append_v2" for Files.uploadSessionAppendV2 enum {{ class_name }}: ReconnectionHelpersShared { static func rebuildRequest(apiRequest: ApiRequest, client: DropboxTransportClientInternal) throws -> {{ return_type }} { let info = try persistedRequestInfo(from: apiRequest) - switch info.routeName { - {% for namespace, route in background_compatible_namespace_route_pairs %} - case "{{ fmt_route_name(route) }}": - return .{{ fmt_func(route.name, route.version) }}( + switch info.namespaceRouteName { + {% for route_args_data in background_compatible_namespace_route_pairs %} + {% set namespace = route_args_data[0] %} + {% set route = route_args_data[1] %} + {% set args_data = route_args_data[2] %} + case "{{ fmt_route_name_namespace(route, namespace.name) }}": + return .{{ fmt_func_namespace(route.name, route.version, namespace.name) }}( rebuildRequest( apiRequest: apiRequest, info: info, diff --git a/stone/backends/swift_rsrc/SwiftRequestBox.jinja b/stone/backends/swift_rsrc/SwiftRequestBox.jinja index 94742f56..a24e68c8 100644 --- a/stone/backends/swift_rsrc/SwiftRequestBox.jinja +++ b/stone/backends/swift_rsrc/SwiftRequestBox.jinja @@ -8,15 +8,19 @@ import Foundation /// Allows for heterogenous collections of typed requests public enum {{ class_name }}: CustomStringConvertible { - {% for route in background_compatible_routes %} - case {{ fmt_func(route.name, route.version) }}({{ request_type_signature(route) }}) + {% for route_namespace_pair in background_compatible_routes %} + {% set namespace = route_namespace_pair[0] %} + {% set route = route_namespace_pair[1] %} + case {{ fmt_func_namespace(route.name, route.version, namespace.name) }}({{ request_type_signature(route) }}) {% endfor %} public var description: String { switch self { - {% for route in background_compatible_routes %} - case .{{ fmt_func(route.name, route.version) }}(_): - return "{{ fmt_func(route.name, route.version) }}" + {% for route_namespace_pair in background_compatible_routes %} + {% set namespace = route_namespace_pair[0] %} + {% set route = route_namespace_pair[1] %} + case .{{ fmt_func_namespace(route.name, route.version, namespace.name) }}: + return "{{ fmt_route_name_namespace(route, namespace.name) }}" {% endfor %} } }