【发布时间】:2017-02-11 01:15:31
【问题描述】:
我正在使用 POST 动词创建一个 API 端点,它需要一个文件。我声明我的端点如下:
consumes:
- application/json
- multipart/form-data
# format of the responses to the client (Accepts)
produces:
- application/json
...
/importfile:
x-swagger-router-controller: import_file
post:
description: Sends the uploaded file to deliveries microservice to be processed.
consumes:
- multipart/form-data
produces:
- application/json
operationId: importcsv
parameters:
- name: file
in: formData
description: file to upload
required: true
type: file
我在 import_file.js 中有以下内容
const util = require('util');
function importcsv(req, res) {
console.log(req);
const message = util.format('hi there!');
// this sends back a JSON response which is a single string
return res.json(message);
}
module.exports = {
importcsv,
};
几个问题:
- 永远不会打印路由器控制器中的日志。这让我觉得这个函数没有被调用。怎么了?
-
即使返回成功响应,我也会看到:
HTTP/1.1
内容类型:文本/html;字符集=utf-8 缓存控制:无缓存
多部分:未找到边界
这是为什么呢?
我是 Swagger 的新手。提前致谢。
【问题讨论】:
-
res.json 看起来不正确,您如何声明与处理程序关联的路由配置?
标签: node.js hapijs swagger-2.0