def _generate_route(self, route_schema, namespace, route): function_name = fmt_func(namespace.name + '_' + route.name, route.version) self.emit() self.emit('/**') if route.doc: self.emit_wrapped_text(self.process_doc(route.doc, self._docf), prefix=' * ') if self.args.class_name: self.emit(' * @function {}#{}'.format(self.args.class_name, function_name)) if route.deprecated: self.emit(' * @deprecated') self.emit(' * @arg {%s} arg - The request parameters.' % fmt_type(route.arg_data_type)) self.emit(' * @returns {Promise.<%s, %s>}' % (fmt_type( route.result_data_type), fmt_error_type(route.error_data_type))) self.emit(' */') self.emit('routes.%s = function (arg) {' % (function_name)) with self.indent(dent=2): url = fmt_url(namespace.name, route.name, route.version) if route_schema.fields: additional_args = [] for field in route_schema.fields: additional_args.append(fmt_obj(route.attrs[field.name])) self.emit("return this.request('{}', arg, {});".format( url, ', '.join(additional_args))) else: self.emit('return this.request("%s", arg);' % url) self.emit('};')
def _generate_route(self, route_schema, namespace, route): function_name = fmt_func(namespace.name + '_' + route.name) self.emit() self.emit('/**') if route.doc: self.emit_wrapped_text(self.process_doc(route.doc, self._docf), prefix=' * ') if self.args.class_name: self.emit(' * @function {}#{}'.format(self.args.class_name, function_name)) if route.deprecated: self.emit(' * @deprecated') self.emit(' * @arg {%s} arg - The request parameters.' % fmt_type(route.arg_data_type)) self.emit(' * @returns {Promise.<%s, %s>}' % (fmt_type(route.result_data_type), fmt_error_type(route.error_data_type))) self.emit(' */') self.emit('routes.%s = function (arg) {' % function_name) with self.indent(dent=2): url = '{}/{}'.format(namespace.name, route.name) if route_schema.fields: additional_args = [] for field in route_schema.fields: additional_args.append(fmt_obj(route.attrs[field.name])) self.emit( "return this.request('{}', arg, {});".format( url, ', '.join(additional_args))) else: self.emit( 'return this.request("%s", arg);' % url) self.emit('};')