示例#1
0
    def _generate_client_m(self, api):
        """Generates client base implementation file. For each namespace, the client will
        have an object field that encapsulates each route in the particular namespace."""
        self.emit_raw(base_file_comment)

        import_classes = [self.args.module_name]
        import_classes += [
            fmt_routes_class(ns.name, self.args.auth_type)
            for ns in api.namespaces.values()
            if ns.routes and self.namespace_to_has_routes[ns]
        ]
        import_classes.append(
            '{}Protocol'.format(self.args.transport_client_name))
        self._generate_imports_m(import_classes)

        with self.block_m(self.args.class_name):
            client_args = fmt_func_args_declaration(
                [('client',
                  'id<{}>'.format(self.args.transport_client_name))])
            with self.block_func(
                    func='initWithTransportClient',
                    args=client_args,
                    return_type='instancetype'):
                self.emit('self = [super init];')

                with self.block_init():
                    self.emit('_transportClient = client;')
                    for namespace in api.namespaces.values():
                        if namespace.routes and self.namespace_to_has_routes[namespace]:
                            base_string = '_{}Routes = [[{} alloc] init:client];'
                            self.emit(
                                base_string.format(
                                    fmt_var(namespace.name),
                                    fmt_routes_class(namespace.name,
                                                     self.args.auth_type)))
示例#2
0
    def _generate_client_m(self, api):
        """Generates client base implementation file. For each namespace, the client will
        have an object field that encapsulates each route in the particular namespace."""
        self.emit_raw(base_file_comment)

        import_classes = [self.args.module_name]
        import_classes += [
            fmt_routes_class(ns.name) for ns in api.namespaces.values()
            if ns.routes
        ]
        import_classes.append(self.args.transport_client_name)
        self._generate_imports_m(import_classes)

        with self.block_m(self.args.class_name):
            client_args = fmt_func_args_declaration([
                ('client', '{} *'.format(self.args.transport_client_name))
            ])
            with self.block_func(func='initWithTransportClient',
                                 args=client_args,
                                 return_type='instancetype'):
                self.emit('self = [super init];')

                with self.block_init():
                    for namespace in api.namespaces.values():
                        if namespace.routes:
                            self.emit(
                                '_{}Routes = [[{} alloc] init:client];'.format(
                                    fmt_var(namespace.name),
                                    fmt_routes_class(namespace.name)))
示例#3
0
    def _generate_client_h(self, api):
        """Generates client base header file. For each namespace, the client will
        have an object field that encapsulates each route in the particular namespace."""
        self.emit_raw(stone_warning)

        self.emit('#import <Foundation/Foundation.h>')
        self.emit()

        import_classes = [
            fmt_routes_class(ns.name, self.args.auth_type)
            for ns in api.namespaces.values()
            if ns.routes and self.namespace_to_has_routes[ns]
        ]
        self._generate_imports_h(import_classes)
        self.emit()
        self.emit('@protocol {};'.format(self.args.transport_client_name))
        self.emit()

        self.emit(comment_prefix)
        description_str = (
            'Base client object that contains an instance field for '
            'each namespace, each of which contains references to all routes within '
            'that namespace. Fully-implemented API clients will inherit this class.'
        )
        self.emit_wrapped_text(description_str, prefix=comment_prefix)
        self.emit(comment_prefix)
        with self.block_h(self.args.class_name,
                          protected=[('transportClient',
                                      'id<{}> _Nonnull'.format(
                                          self.args.transport_client_name))]):
            self.emit()
            for namespace in api.namespaces.values():
                if namespace.routes and self.namespace_to_has_routes[namespace]:
                    class_doc = 'Routes within the `{}` namespace.'.format(
                        fmt_var(namespace.name))
                    self.emit_wrapped_text(class_doc, prefix=comment_prefix)
                    prop = '{}Routes'.format(fmt_var(namespace.name))
                    typ = '{} * _Nonnull'.format(
                        fmt_routes_class(namespace.name, self.args.auth_type))
                    self.emit(fmt_property_str(prop=prop, typ=typ))
                    self.emit()

            client_args = fmt_func_args_declaration([
                ('client',
                 'id<{}> _Nonnull'.format(self.args.transport_client_name))
            ])

            description_str = (
                'Initializes the `{}` object with a networking client.')
            self.emit_wrapped_text(description_str.format(
                self.args.class_name),
                                   prefix=comment_prefix)
            init_signature = fmt_signature(func='initWithTransportClient',
                                           args=client_args,
                                           return_type='nonnull instancetype')
            self.emit('{};'.format(init_signature))
            self.emit()
示例#4
0
    def generate(self, api):
        for namespace in api.namespaces.values():
            for data_type in namespace.linearize_data_types():
                obj_name_to_namespace[data_type.name] = fmt_class_prefix(
                    data_type)

        for namespace in api.namespaces.values():
            if namespace.routes:
                import_classes = [
                    fmt_routes_class(namespace.name),
                    fmt_route_obj_class(namespace.name),
                    self.args.transport_client_name,
                    'DBStoneBase',
                    'DBErrors',
                ]

                with self.output_to_relative_path('Routes/{}.m'.format(
                        fmt_routes_class(namespace.name))):
                    self.emit_raw(stone_warning)

                    imports_classes_m = import_classes + \
                        self._get_imports_m(
                            self._get_namespace_route_imports(namespace), [])
                    self._generate_imports_m(imports_classes_m)

                    self._generate_routes_m(namespace)

                with self.output_to_relative_path('Routes/{}.h'.format(
                        fmt_routes_class(namespace.name))):
                    self.emit_raw(base_file_comment)
                    self.emit('#import <Foundation/Foundation.h>')
                    self.emit()
                    self.emit(fmt_import('DBTasks'))
                    self.emit()
                    import_classes_h = [
                        self.args.transport_client_name,
                        'DBNilObject',
                    ]
                    import_classes_h = import_classes_h + self._get_imports_h(
                        self._get_namespace_route_imports(
                            namespace,
                            include_route_args=False,
                            include_route_deep_args=True))
                    self._generate_imports_h(import_classes_h)

                    self._generate_routes_h(namespace)

        with self.output_to_relative_path('Client/{}.m'.format(
                self.args.module_name)):
            self._generate_client_m(api)

        with self.output_to_relative_path('Client/{}.h'.format(
                self.args.module_name)):
            self._generate_client_h(api)
示例#5
0
    def generate(self, api):
        for namespace in api.namespaces.values():
            for data_type in namespace.linearize_data_types():
                self.obj_name_to_namespace[
                    data_type.name] = fmt_class_prefix(data_type)

        for namespace in api.namespaces.values():
            if namespace.routes:
                import_classes = [
                    fmt_routes_class(namespace.name),
                    fmt_route_obj_class(namespace.name),
                    '{}Protocol'.format(self.args.transport_client_name),
                    'DBStoneBase',
                    'DBRequestErrors',
                ]

                with self.output_to_relative_path(
                        'Routes/{}.m'.format(fmt_routes_class(namespace.name))):
                    self.emit_raw(stone_warning)

                    imports_classes_m = import_classes + \
                        self._get_imports_m(
                            self._get_namespace_route_imports(namespace), [])
                    self._generate_imports_m(imports_classes_m)

                    self._generate_routes_m(namespace)

                with self.output_to_relative_path(
                        'Routes/{}.h'.format(fmt_routes_class(namespace.name))):
                    self.emit_raw(base_file_comment)
                    self.emit('#import <Foundation/Foundation.h>')
                    self.emit()
                    self.emit(fmt_import('DBTasks'))
                    self.emit()
                    import_classes_h = [
                        'DBNilObject',
                    ]
                    import_classes_h = (import_classes_h +
                        self._get_imports_h(self._get_namespace_route_imports(
                            namespace, include_route_args=False, include_route_deep_args=True)))
                    self._generate_imports_h(import_classes_h)
                    self.emit('@protocol {};'.format(self.args.transport_client_name),)
                    self.emit()
                    self._generate_routes_h(namespace)

        with self.output_to_relative_path('Client/{}.m'.format(self.args.module_name)):
            self._generate_client_m(api)

        with self.output_to_relative_path('Client/{}.h'.format(self.args.module_name)):
            self._generate_client_h(api)
示例#6
0
    def _generate_client_h(self, api):
        """Generates client base header file. For each namespace, the client will
        have an object field that encapsulates each route in the particular namespace."""
        self.emit_raw(stone_warning)

        self.emit('#import <Foundation/Foundation.h>')
        self.emit()

        import_classes = [fmt_routes_class(
            ns.name) for ns in api.namespaces.values() if ns.routes]
        self._generate_imports_h(import_classes)
        self.emit()
        self.emit('@protocol {};'.format(self.args.transport_client_name))
        self.emit()

        self.emit(comment_prefix)
        description_str = ('Base client object that contains an instance field for '
                           'each namespace, each of which contains references to all routes within '
                           'that namespace. Fully-implemented API clients will inherit this class.')
        self.emit_wrapped_text(description_str, prefix=comment_prefix)
        self.emit(comment_prefix)
        with self.block_h(self.args.class_name):
            self.emit(fmt_property_str(
                'transportClient', 'id<{}> _Nonnull'.format(self.args.transport_client_name)))
            self.emit()
            for namespace in api.namespaces.values():
                if namespace.routes:
                    class_doc = 'Routes within the `{}` namespace.'.format(
                        fmt_var(namespace.name))
                    self.emit_wrapped_text(class_doc, prefix=comment_prefix)
                    prop = '{}Routes'.format(fmt_var(namespace.name))
                    typ = '{} * _Nonnull'.format(fmt_routes_class(namespace.name))
                    self.emit(fmt_property_str(prop=prop, typ=typ))
                    self.emit()

            client_args = fmt_func_args_declaration(
                [('client', 'id<{}> _Nonnull'.format(self.args.transport_client_name))])

            description_str = (
                'Initializes the `{}` object with a networking client.')
            self.emit_wrapped_text(description_str.format(
                self.args.class_name), prefix=comment_prefix)
            init_signature = fmt_signature(func='initWithTransportClient',
                                           args=client_args,
                                           return_type='nonnull instancetype')
            self.emit('{};'.format(init_signature))
            self.emit()
示例#7
0
    def _generate_routes_m(self, namespace):
        """Generates implementation file for namespace object that has as methods
        all routes within the namespace."""
        with self.block_m(
                fmt_routes_class(namespace.name, self.args.auth_type)):
            init_args = fmt_func_args_declaration([(
                'client', 'id<{}>'.format(self.args.transport_client_name))])

            with self.block_func(
                    func='init', args=init_args, return_type='instancetype'):
                self.emit('self = [super init];')
                with self.block_init():
                    self.emit('_client = client;')
            self.emit()
            style_to_request = json.loads(self.args.z__style_to_request)

            for route in namespace.routes:
                if (route.attrs.get('auth') != self.args.auth_type
                        and route.attrs.get('auth') != 'noauth'):
                    continue

                route_type = route.attrs.get('style')
                client_args = json.loads(self.args.client_args)

                if route_type in client_args.keys():
                    for args_data in client_args[route_type]:
                        task_type_key, type_data_dict = tuple(args_data)
                        task_type_name = style_to_request[task_type_key]

                        func_suffix = type_data_dict[0]
                        extra_args = [
                            tuple(type_data[:-1])
                            for type_data in type_data_dict[1]
                        ]

                        if (is_struct_type(route.arg_data_type) and
                                self._struct_has_defaults(route.arg_data_type)):
                            route_args, _ = self._get_default_route_args(
                                namespace, route)
                            self._generate_route_m(route, namespace,
                                                   route_args, extra_args,
                                                   task_type_name, func_suffix)

                        route_args, _ = self._get_route_args(namespace, route)
                        self._generate_route_m(route, namespace, route_args,
                                               extra_args, task_type_name,
                                               func_suffix)
                else:
                    task_type_name = style_to_request[route_type]
                    if (is_struct_type(route.arg_data_type) and
                            self._struct_has_defaults(route.arg_data_type)):
                        route_args, _ = self._get_default_route_args(
                            namespace, route)
                        self._generate_route_m(route, namespace, route_args,
                                               [], task_type_name, '')

                    route_args, _ = self._get_route_args(namespace, route)
                    self._generate_route_m(route, namespace, route_args, [],
                                           task_type_name, '')
示例#8
0
    def _generate_routes_h(self, namespace):
        """Generates header file for namespace object that has as methods
        all routes within the namespace."""
        self.emit(comment_prefix)
        self.emit_wrapped_text('Routes for the `{}` namespace'.format(
            fmt_class(namespace.name)),
                               prefix=comment_prefix)
        self.emit(comment_prefix)

        with self.block_h(fmt_routes_class(namespace.name)):
            description_str = (
                'An instance of the networking client that each '
                'route will use to submit a request.')
            self.emit_wrapped_text(description_str, prefix=comment_prefix)
            self.emit(
                fmt_property_str(prop='client',
                                 typ='{} * _Nonnull'.format(
                                     self.args.transport_client_name)))
            self.emit()

            routes_obj_args = fmt_func_args_declaration([
                ('client',
                 '{} * _Nonnull'.format(self.args.transport_client_name))
            ])

            init_signature = fmt_signature(func='init',
                                           args=routes_obj_args,
                                           return_type='nonnull instancetype')
            description_str = (
                'Initializes the `{}` namespace container object '
                'with a networking client.')
            self.emit_wrapped_text(description_str.format(
                fmt_routes_class(namespace.name)),
                                   prefix=comment_prefix)
            self.emit('{};'.format(init_signature))
            self.emit()

            style_to_request = json.loads(self.args.z__style_to_request)

            for route in namespace.routes:
                route_type = route.attrs.get('style')
                client_args = json.loads(self.args.client_args)

                if route_type in client_args.keys():
                    for args_data in client_args[route_type]:
                        task_type_key, type_data_dict = tuple(args_data)
                        task_type_name = style_to_request[task_type_key]

                        func_suffix = type_data_dict[0]
                        extra_args = [
                            tuple(type_data[:-1])
                            for type_data in type_data_dict[1]
                        ]
                        extra_docs = [(type_data[0], type_data[-1])
                                      for type_data in type_data_dict[1]]

                        if is_struct_type(route.arg_data_type
                                          ) and self._struct_has_defaults(
                                              route.arg_data_type):
                            route_args, doc_list = self._get_default_route_args(
                                namespace, route, tag=True)
                            self._generate_route_signature(
                                route, namespace, route_args, extra_args,
                                doc_list + extra_docs, task_type_name,
                                func_suffix)

                        route_args, doc_list = self._get_route_args(namespace,
                                                                    route,
                                                                    tag=True)
                        self._generate_route_signature(route, namespace,
                                                       route_args, extra_args,
                                                       doc_list + extra_docs,
                                                       task_type_name,
                                                       func_suffix)
                else:
                    task_type_name = style_to_request[route_type]
                    if is_struct_type(
                            route.arg_data_type) and self._struct_has_defaults(
                                route.arg_data_type):
                        route_args, doc_list = self._get_default_route_args(
                            namespace, route, tag=True)
                        self._generate_route_signature(route, namespace,
                                                       route_args, [],
                                                       doc_list,
                                                       task_type_name, '')

                    route_args, doc_list = self._get_route_args(namespace,
                                                                route,
                                                                tag=True)
                    self._generate_route_signature(route, namespace,
                                                   route_args, [], doc_list,
                                                   task_type_name, '')
示例#9
0
    def generate(self, api):

        for namespace in api.namespaces.values():
            self.namespace_to_has_routes[namespace] = False
            if namespace.routes:
                for route in namespace.routes:
                    if route.attrs.get(
                            'auth') == self.args.auth_type or route.attrs.get(
                                'auth'
                            ) == 'noauth' and self.args.auth_type == 'user':
                        self.namespace_to_has_routes[namespace] = True
                        break

        for namespace in api.namespaces.values():
            for data_type in namespace.linearize_data_types():
                self.obj_name_to_namespace[data_type.name] = fmt_class_prefix(
                    data_type)

        for namespace in api.namespaces.values():
            if namespace.routes and self.namespace_to_has_routes[namespace]:
                import_classes = [
                    fmt_routes_class(namespace.name, self.args.auth_type),
                    fmt_route_obj_class(namespace.name),
                    '{}Protocol'.format(self.args.transport_client_name),
                    'DBStoneBase',
                    'DBRequestErrors',
                ]

                with self.output_to_relative_path('Routes/{}.m'.format(
                        fmt_routes_class(namespace.name,
                                         self.args.auth_type))):
                    self.emit_raw(stone_warning)

                    imports_classes_m = import_classes + \
                        self._get_imports_m(
                            self._get_namespace_route_imports(namespace), [])
                    self._generate_imports_m(imports_classes_m)

                    self._generate_routes_m(namespace)

                with self.output_to_relative_path('Routes/{}.h'.format(
                        fmt_routes_class(namespace.name,
                                         self.args.auth_type))):
                    self.emit_raw(base_file_comment)
                    self.emit('#import <Foundation/Foundation.h>')
                    self.emit()
                    self.emit(fmt_import('DBTasks'))
                    self.emit()
                    import_classes_h = [
                        'DBNilObject',
                    ]
                    import_classes_h = (import_classes_h + self._get_imports_h(
                        self._get_namespace_route_imports(
                            namespace,
                            include_route_args=False,
                            include_route_deep_args=True)))
                    self._generate_imports_h(import_classes_h)
                    self.emit(
                        '@protocol {};'.format(
                            self.args.transport_client_name), )
                    self.emit()
                    self._generate_routes_h(namespace)

        with self.output_to_relative_path('Client/{}.m'.format(
                self.args.module_name)):
            self._generate_client_m(api)

        with self.output_to_relative_path('Client/{}.h'.format(
                self.args.module_name)):
            self._generate_client_h(api)
示例#10
0
    def _generate_routes_h(self, namespace):
        """Generates header file for namespace object that has as methods
        all routes within the namespace."""
        self.emit(comment_prefix)
        self.emit_wrapped_text(
            'Routes for the `{}` namespace'.format(fmt_class(namespace.name)),
            prefix=comment_prefix)
        self.emit(comment_prefix)

        self.emit()
        self.emit('NS_ASSUME_NONNULL_BEGIN')
        self.emit()

        with self.block_h(
                fmt_routes_class(namespace.name, self.args.auth_type)):
            description_str = (
                'An instance of the networking client that each '
                'route will use to submit a request.')
            self.emit_wrapped_text(description_str, prefix=comment_prefix)
            self.emit(
                fmt_property_str(
                    prop='client',
                    typ='id<{}>'.format(
                        self.args.transport_client_name)))
            self.emit()

            routes_obj_args = fmt_func_args_declaration(
                [('client',
                  'id<{}>'.format(self.args.transport_client_name))])

            init_signature = fmt_signature(
                func='init',
                args=routes_obj_args,
                return_type='instancetype')
            description_str = (
                'Initializes the `{}` namespace container object '
                'with a networking client.')
            self.emit_wrapped_text(
                description_str.format(
                    fmt_routes_class(namespace.name, self.args.auth_type)),
                prefix=comment_prefix)
            self.emit('{};'.format(init_signature))
            self.emit()

            style_to_request = json.loads(self.args.z__style_to_request)

            for route in namespace.routes:
                if (route.attrs.get('auth') != self.args.auth_type
                        and route.attrs.get('auth') != 'noauth'):
                    continue

                route_type = route.attrs.get('style')
                client_args = json.loads(self.args.client_args)

                if route_type in client_args.keys():
                    for args_data in client_args[route_type]:
                        task_type_key, type_data_dict = tuple(args_data)
                        task_type_name = style_to_request[task_type_key]

                        func_suffix = type_data_dict[0]
                        extra_args = [
                            tuple(type_data[:-1])
                            for type_data in type_data_dict[1]
                        ]
                        extra_docs = [(type_data[0], type_data[-1])
                                      for type_data in type_data_dict[1]]

                        if (is_struct_type(route.arg_data_type) and
                                self._struct_has_defaults(route.arg_data_type)):
                            route_args, doc_list = self._get_default_route_args(
                                namespace, route, tag=True)
                            self._generate_route_signature(
                                route, namespace, route_args, extra_args,
                                doc_list + extra_docs, task_type_name,
                                func_suffix)

                        route_args, doc_list = self._get_route_args(
                            namespace, route, tag=True)
                        self._generate_route_signature(
                            route, namespace, route_args, extra_args,
                            doc_list + extra_docs, task_type_name, func_suffix)
                else:
                    task_type_name = style_to_request[route_type]
                    if (is_struct_type(route.arg_data_type) and
                            self._struct_has_defaults(route.arg_data_type)):
                        route_args, doc_list = self._get_default_route_args(
                            namespace, route, tag=True)
                        self._generate_route_signature(
                            route, namespace, route_args, [], doc_list,
                            task_type_name, '')

                    route_args, doc_list = self._get_route_args(
                        namespace, route, tag=True)
                    self._generate_route_signature(route, namespace,
                                                   route_args, [], doc_list,
                                                   task_type_name, '')
        self.emit()
        self.emit('NS_ASSUME_NONNULL_END')
        self.emit()