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, 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 _docf(self, tag, val): """ Callback used as the handler argument to process_docs(). This converts Stone doc references to JSDoc-friendly annotations. """ # TODO(kelkabany): We're currently just dropping all doc ref tags ... # NOTE(praneshp): ... except for versioned routes if tag == 'route': if ':' in val: val, version = val.split(':', 1) version = int(version) else: version = 1 url = fmt_url(self.cur_namespace.name, val, version) # NOTE: In js, for comments, we drop the namespace name and the '/' when # documenting URLs return url[(len(self.cur_namespace.name) + 1):] return val