如何在swagger-express中使用post请求传递输入字段名称

时间:2016-04-29 06:25:01

标签: node.js express swagger

如何在swagger-express中传递带有发布请求的输入字段名称,
我正在使用下面的代码 -

/**
 * @swagger
 * path: /get_city_list
 * operations:
 *   -  httpMethod: POST
 *      summary: provide supplierId and accessToken
 *      notes: Returns a list of city corresponding to its supplierId
 *      responseClass: Supplier
 *      nickname: getCityList
 *      consumes: 
 *        - text/html
 *      parameters:
 *        - name: accessToken
 *          description: Your AccessToken
 *          paramType : body
 *          required: true
 *          dataType: string
 *        - name: supplierId
 *          description: Your SupplierID
 *          paramType : body
 *          required: true
 *          dataType: string
 */

如果我像这样通过,我会收到错误 “消息”:“无效的json”,

1 个答案:

答案 0 :(得分:0)

因此,您的API def应如下所示:

path: /get_city_list
  operations:
    -  httpMethod: POST
       summary: provide supplierId and accessToken
       notes: Returns a list of city corresponding to its supplierId
       responseClass: Supplier
       nickname: getCityList
       consumes: 
         - application/json
       produces:
         - application/json
       parameters:
         - in: body
           description: data to post
           required: true
           name: body
           type: object
           schema:
             $ref: "#/definitions/PostRequest"
definitions:
  PostRequest:
    properties:
      accessToken:
        type: string
      supplierId:
        type: string