是否使用swaggerize hapi和node.js上传文件?

是否使用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

我正在用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: 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

    内容类型:text/html;字符集=utf-8 缓存控制:没有缓存

    多部分:未找到边界

  • 为什么呢

    我不太会招摇过市。提前谢谢。

    这篇文章让我觉得边界问题已经解决了。2016年12月29日,它被固定并合并到master branch,但最新版本的Swagger()于2016年12月27日发布

    因此,文件上传目前无法通过Swagger(v1.5.12)实现。这回答了我的两个问题

    我编写了以下单元测试来测试我的控制器是否正常工作:

    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看起来不对,您如何声明处理程序关联的路由配置?