How to use swagger to describe a form with file and filename

I would like to create an http form that contains two input fields: file, fname where file is of file type and fname is text (name of uploaded file.) The form will submit the results to node. In a swagger, something like this:

swagger: '2.0'
info:
  title: Test
  description: Tdesc
  version: "1.0.0"
host: localhost:8080
schemes:
  - http
basePath: /v1
produces:
  - application/json
paths:
  /fileup:
    x-swagger-router-controller: Default
    put:
      operationId: fileupPut
      consumes:
        - multipart/form-data
      parameters:
        - name: fname
          in: formData
          required: false
          type: string
        - name: file
          in: formData
          required: false
          type: file
      responses:
        200:
          description: D
          schema:
            type: string

      

I copied this over to http://editor.swagger.io/#/ and then exported it as a nodejs program and ran the program. Visit http: // localhost: 8080 / docs to use the swagger-generated interface to "put" a file, fname. I put a breakpoint in the generated controller Default.js and noticed that the file and fname are undefined.

 module.exports.fileupPut = function fileupPut (req, res, next) {
   var file = req.swagger.params['file'].value;
   var fname = req.swagger.params['fname'].value;
   ...

      

I understand that file handling code (like busboy) can be used to stream to a file. I don't understand how swagger parsing can be used to get strings for file and fname.

+3


source to share





All Articles