Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
昂首阔步赢了';t生成从yaml发布的正确json_Json_Node.js_Curl_Yaml_Swagger - Fatal编程技术网

昂首阔步赢了';t生成从yaml发布的正确json

昂首阔步赢了';t生成从yaml发布的正确json,json,node.js,curl,yaml,swagger,Json,Node.js,Curl,Yaml,Swagger,我正在使用swagger,希望使用PostAPI。虽然它正确地显示了参数,但它不会生成正确的curl命令来向服务器发送数据 另外:后端在node.js中,通过swagger-jsdoc表达和解析YAML文档 以下是YAML: /** * @swagger * /register: * post: * tags: * - report * description: Returns info for panel api * consumes:

我正在使用swagger,希望使用PostAPI。虽然它正确地显示了参数,但它不会生成正确的curl命令来向服务器发送数据

另外:后端在node.js中,通过swagger-jsdoc表达和解析YAML文档

以下是YAML:

/**
 * @swagger
 * /register:
 *   post:
 *     tags:
 *       - report
 *     description: Returns info for panel api
 *     consumes:
 *       - application/x-www-form-urlencoded
 *     produces:
 *       - application/json
 *     parameters:
 *     -  name: email
 *        in: body
 *        description: Email
 *        required: true
 *        type: string
 *     -  name: password
 *        in: body
 *        description: password
 *        required: true
 *        type: string
 *     -  name: fullName
 *        in: body
 *        description: full name
 *        required: true
 *        type: string
 *     responses:
 *       200:
 *         description: An info for panel api
 *       401:
 *         description: If user didn't authenticate
 */
这是由curl命令生成的:

curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d 'max mcgrey' 'http://localhost:5200/register'
答复如下:

{
  "status": "fail",
  "message": "Validation failed, check your inputs.",
  "errors": [
    {
      "param": "fullName",
      "msg": "Full name is required."
    },
    {
      "param": "fullName",
      "msg": "Full name must be between 1 and 50 characters long."
    },
    {
      "param": "email",
      "msg": "Email is required."
    },
    {
      "param": "email",
      "msg": "Email is required."
    },
    {
      "param": "password",
      "msg": "Password is required."
    }
  ]
}

参数语法错误。如果操作应该使用
application/x-www-form-urlencoded
,则需要使用
in:form
参数,而不是
in:body

 *     consumes:
 *       - application/x-www-form-urlencoded
 *     ...
 *     parameters:
 *     -  name: email
 *        in: form              <-----------
 *        description: Email
 *        required: true
 *        type: string
 *     -  name: password
 *        in: form              <-----------
 *        description: password
 *        required: true
 *        type: string
 *     -  name: fullName
 *        in: form              <-----------
 *        description: full name
 *        required: true
 *        type: string

数据应为JSON格式??是的。但是,当我将消费类型修改为“consumes:-application/json”时,我会得到一个“curl-xpost--header'Content-type:application/json'--header'Accept:text/html'-d'max max'”,这会导致主体响应中出现“SyntaxError:Unexpected token”
 *     consumes:
 *       - application/json
 *     ...
 *     parameters:
 *     -  name: body
 *        in: body
 *        required: true
 *        schema:
 *          type: object
 *          required: [email, password, fullName]
 *          properties:
 *            email:
 *              type: string
 *              format: email
 *              description: Email
 *            password:
 *              type: string
 *              format: password
 *              description: password
 *            fullName:
 *              type: string
 *              description: full name