def _generate_client(self, namespace):
        file_name = os.path.join(self.target_folder_path, namespace.name,
                                 'client.go')
        with self.output_to_relative_path(file_name):
            self.emit_raw(HEADER)
            self.emit()
            self.emit('package %s' % namespace.name)
            self.emit()

            self.emit(
                '// Client interface describes all routes in this namespace')
            with self.block('type Client interface'):
                for route in namespace.routes:
                    generate_doc(self, route)
                    self.emit(self._generate_route_signature(namespace, route))
            self.emit()

            self.emit('type apiImpl dropbox.Context')
            for route in namespace.routes:
                self._generate_route(namespace, route)
            self.emit(
                '// New returns a Client implementation for this namespace')
            with self.block('func New(c dropbox.Config) Client'):
                self.emit('ctx := apiImpl(dropbox.NewContext(c))')
                self.emit('return &ctx')
Exemplo n.º 2
0
 def _generate_field(self, field, union_field=False, namespace=None, raw=False):
     generate_doc(self, field)
     field_name = fmt_var(field.name)
     type_name = fmt_type(field.data_type, namespace, use_interface=True, raw=raw)
     json_tag = '`json:"%s"`' % field.name
     if is_nullable_type(field.data_type) or union_field:
         json_tag = '`json:"%s,omitempty"`' % field.name
     self.emit('%s %s %s' % (field_name, type_name, json_tag))
 def _generate_data_type(self, data_type):
     generate_doc(self, data_type)
     if is_struct_type(data_type):
         self._generate_struct(data_type)
         if data_type.has_enumerated_subtypes():
             self._generate_base_type(data_type)
     elif is_union_type(data_type):
         self._generate_union(data_type)
     else:
         self.logger.info("Unhandled data type", data_type)
 def _generate_data_type(self, data_type):
     generate_doc(self, data_type)
     if is_struct_type(data_type):
         self._generate_struct(data_type)
         if data_type.has_enumerated_subtypes():
             self._generate_base_type(data_type)
     elif is_union_type(data_type):
         self._generate_union(data_type)
     else:
         self.logger.info("Unhandled data type", data_type)
 def _generate_field(self, field, union_field=False, namespace=None, raw=False):
     generate_doc(self, field)
     field_name = fmt_var(field.name)
     type_name = fmt_type(field.data_type, namespace, use_interface=True)
     json_tag = '`json:"%s"`' % field.name
     if is_nullable_type(field.data_type) or union_field:
         json_tag = '`json:"%s,omitempty"`' % field.name
     if raw:
         self.emit('%s json.RawMessage %s' % (field_name, json_tag))
     else:
         self.emit('%s %s %s' % (field_name, type_name, json_tag))
    def _generate_namespace(self, namespace):
        file_name = os.path.join(self.target_folder_path, namespace.name,
                                 'types.go')
        with self.output_to_relative_path(file_name):
            self.emit_raw(HEADER)
            self.emit()
            generate_doc(self, namespace)
            self.emit('package %s' % namespace.name)
            self.emit()

            for data_type in namespace.linearize_data_types():
                self._generate_data_type(data_type)
    def _generate_namespace(self, namespace):
        file_name = os.path.join(self.target_folder_path, namespace.name,
                                 'types.go')
        with self.output_to_relative_path(file_name):
            self.emit_raw(HEADER)
            self.emit()
            generate_doc(self, namespace)
            self.emit('package %s' % namespace.name)
            self.emit()

            for data_type in namespace.linearize_data_types():
                self._generate_data_type(data_type)
    def _generate_client(self, namespace):
        file_name = os.path.join(self.target_folder_path, namespace.name,
                                 'client.go')
        with self.output_to_relative_path(file_name):
            self.emit_raw(HEADER)
            self.emit()
            self.emit('package %s' % namespace.name)
            self.emit()

            self.emit('// Client interface describes all routes in this namespace')
            with self.block('type Client interface'):
                for route in namespace.routes:
                    generate_doc(self, route)
                    self.emit(self._generate_route_signature(namespace, route))
            self.emit()

            self.emit('type apiImpl dropbox.Context')
            for route in namespace.routes:
                self._generate_route(namespace, route)
            self.emit('// New returns a Client implementation for this namespace')
            with self.block('func New(c dropbox.Config) *apiImpl'):
                self.emit('ctx := apiImpl(dropbox.NewContext(c))')
                self.emit('return &ctx')