我在我的控制器上使用swagger和typescript开发的nodejs应用程序看起来像
const q_mapping = require('../../config/q_mapping');
import { amqpMessenger } from '../tools/amqp';
const survey = {
surveyServiceCheck : (req,res) =>{
amqpMessenger({serviceCheck : true},res, q_mapping.survey);
}
}
export {survey}
和swagger抱怨
无法解析配置的swagger-router处理程序: survey_surveyServiceCheck
当我看到生成的js文件时,它会导出类似
的内容"use strict";
var q_mapping = require('../../config/q_mapping');
var amqp_1 = require("../tools/amqp");
var survey = (function () {
function survey() {
}
survey.prototype.surveyServiceCheck = function (req, res) {
amqp_1.amqpMessenger({ serviceCheck: true }, res, q_mapping.survey);
};
return survey;
}());
exports.survey = survey;
当我手动更改为exports.survey = survey;
行到module.exports = survey;
时,摇摇晃晃地击中控制器。
我需要更改我的打字稿以生成上面的输出或者当我写控制器时我做错了什么? 我的招摇定义如
/survey:
# binds a127 app logic to a route
x-swagger-router-controller: survey
get:
description: Check whether the survey service is up or not
# used as the method name of the controller
operationId: surveyServiceCheck
responses:
"200":
description: Success
schema:
# a pointer to a definition
$ref: "#/definitions/defaultResponse"
# responses may fall through to errors
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
答案 0 :(得分:0)
首先,我认为survey
不是const
而是class
。否则,TypeScript编译器不会将函数对象创建为survey
的值。除此之外,您应该使用export =
(documentation)
const q_mapping = require('../../config/q_mapping');
import { amqpMessenger } from '../tools/amqp';
class survey {
surveyServiceCheck(req,res) {
amqpMessenger({serviceCheck : true},res, q_mapping.survey);
}
}
export = survey
生成的JavaScript文件如下所示:
"use strict";
var q_mapping = require('../../config/q_mapping');
var amqp_1 = require("../tools/amqp");
var survey = (function () {
function survey() {
}
survey.prototype.surveyServiceCheck = function (req, res) {
amqp_1.amqpMessenger({ serviceCheck: true }, res, q_mapping.survey);
};
return survey;
}());
module.exports = survey;
这相当于您提交的生成文件,包括您必须手动执行的修复。