代码之家  ›  专栏  ›  技术社区  ›  Valor_ user3379466

收到的swager无效json消息

  •  0
  • Valor_ user3379466  · 技术社区  · 6 年前

    我正在使用第四交响曲和条令,现在我正在实现/添加招摇过市,所以我将有适当的文档来测试我的API。

    这是我的邮递员,有正确的输入表单数据和OK响应。 enter image description here

    这是我“有问题”的招摇过市的标志

     * @Route(
     *     "/request",
     *     name="create",
     *     methods={"POST"}
     * )
     *
     * @SWG\Parameter(
     *     name="domain",
     *     in="formData",
     *     required=true,
     *     type="array",
     *          @SWG\Items(
     *             type="string"
     *          )
     * ),
     *
     * @SWG\Parameter(
     *     name="name",
     *     in="formData",
     *     required=true,
     *     type="string",
     * ),
     *
     * @SWG\Response(
     *     response=200,
     *     description="OK",
     *     @SWG\Schema(
     *          type="array",
     *          @Model(type=App\Entity\Request::class)
     *     )
     * ),
     *
     * @SWG\Response(
     *     response=201,
     *     description="Request created",
     *     @SWG\Schema(
     *          type="array",
     *          @Model(type=App\Entity\Request::class)
     *     )
     * ),
    

    所以现在我通过myurl.com/api/doc打开一个招摇过市器,并尝试执行相同的操作… enter image description here

    所以我的大摇大摆按照curl的要求执行

    curl -X POST "http://certify.test/request" -H "accept: application/json" -H "Content-Type: application/json" -d "domain=antrax.com,www.antrax.com&name=antrax.com%2Cwww.antrax.com"
    

    答案是

    {
      "status": "error",
      "code": 0,
      "message": "Invalid json message received"
    }
    

    伙计们,能不能请你们帮我正确地注释一下我的自大参数,这样我的api文档就可以做出正确的请求了。如果您需要任何其他信息,请告诉我,我会提供。谢谢您!

    1 回复  |  直到 6 年前
        1
  •  3
  •   Nico    6 年前

    我认为 内容类型 招摇过市发送不正确。

    使用邮递员发送 内容类型 标题等于 application/x-www-form-urlencoded 但是,如果大摇大摆,它等于 application/json .

    尝试添加 consumes 输入自大的注释,比如:

     * @SWG\Post(
     *     path="/request",
     *     consumes={"application/x-www-form-urlencoded"},
     * )
    

    你也应该改变 domain 参数到 domain[] 以下内容:

    @SWG\Parameter(
    *     name="domain[]",
    *     in="formData",
    *     description="Array of domains for TSL certificate",
    *     required=true,
    *     type="array",
    *          @SWG\Items(
    *             type="string"
    *          )
    * )