是否使用swaggerize hapi和node.js上传文件?
我正在用POST-verb创建一个API端点,它需要一个文件。我声明我的端点如下:是否使用swaggerize hapi和node.js上传文件?,node.js,hapijs,swagger-2.0,Node.js,Hapijs,Swagger 2.0,我正在用POST-verb创建一个API端点,它需要一个文件。我声明我的端点如下: consumes: - application/json - multipart/form-data # format of the responses to the client (Accepts) produces: - application/json ... /importfile: x-swagger-router-controller
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,
};
两个问题:
const describe = require('ava-spec').describe;
const request = require('supertest-as-promised');
const server = require('../../../../app');
describe('controllers', () => {
describe('import_file', () => {
describe('POST /importfile', (it) => {
it('should accept a file parameter', async (t) => {
const res = await request(server)
.post('/importfile')
.attach('file', 'test/data/A.csv' )
.expect(200);
t.is(res.body, 'file uploaded');
});
});
});
});
res.json看起来不对,您如何声明处理程序关联的路由配置?