Swagger 用Post提交in="body"怎么获取不到值?

为何打印post task_require_content字段获取不到值?

注:用in="body"不行,但用in="formData"可以获取到的。

图1:

clipboard.png

如图2:这个编辑普通会员接口,我点击Try it out 的时候,怎么根据某个用户id,输出用户的昵称,手机号?现在每个字段都是空的,有些字段不想改但还得把原来的值输一遍,很麻烦。

图片描述

Swg生成文档的代码:

/**
     * @SWG\Post(path="/v1/user/user/updateuser?id={id}&access-token={access-token}&sign={sign}",
     *   tags={"会员管理"},
     *   summary="",
     *   description="编辑普通会员接口",
     *   operationId="v1/user/user/updateuser",
     *   produces={"application/xml", "application/json"},
     *   @SWG\Parameter(
     *     name="id",
     *     in="path",
     *     description="用户id",
     *     required=true,
     *     type="integer"
     *   ),
     *   @SWG\Parameter(
     *     name="access-token",
     *     in="path",
     *     description="令牌",
     *     required=true,
     *     type="string"
     *   ),
     *   @SWG\Parameter(
     *     name="sign",
     *     in="path",
     *     description="sign字符串",
     *     required=false,
     *     type="string"
     *   ),
     *   @SWG\Parameter(
     *     name="company_id",
     *     in="formData",
     *     description="代理商",
     *     required=false,
     *     type="integer",
     *   ),
     *   @SWG\Parameter(
     *     name="t_nickname",
     *     in="formData",
     *     description="昵称",
     *     required=false,
     *     type="string",
     *   ),
     *   @SWG\Parameter(
     *     name="t_mobile",
     *     in="formData",
     *     description="手机号",
     *     required=false,
     *     type="integer",
     *   ),
     *   @SWG\Parameter(
     *     name="gender",
     *     in="formData",
     *     description="性别",
     *     required=false,
     *     type="integer",
     *   ),
     *   @SWG\Parameter(
     *     name="residecity",
     *     in="formData",
     *     description="城市",
     *     required=false,
     *     type="integer",
     *   ),
     *   @SWG\Parameter(
     *     name="parent_id",
     *     in="formData",
     *     description="所属业务员",
     *     required=false,
     *     type="integer",
     *   ),
     *   @SWG\Parameter(
     *     name="t_password",
     *     in="formData",
     *     description="密码",
     *     required=false,
     *     type="string",
     *   ),
     *
     *   @SWG\Response(response=200, @SWG\Schema(ref="#"), description="successful operation"),
     *   @SWG\Response(response=500,description="Internal Server Error"),
     *   security={
     *     {"Authorization": {}},
     *   }
     * )
     *
     */
阅读 9.4k
2 个回答

由于body和formData都需要指定头部格式化设置,所以同一个请求下不能设置两种不同方式。

原文
Body - The payload that's appended to the HTTP request. Since there can only be one payload, there can only be one body parameter. The name of the body parameter has no effect on the parameter itself and is used for documentation purposes only. Since Form parameters are also in the payload, body and form parameters cannot exist together for the same operation.
https://github.com/OAI/OpenAP...

body里面只能放一个参数, 放多个参数, 是无效的.
看加黑的那行, 说明 body 和 formData 是不能共存的.

Body - The payload that's appended to the HTTP request. Since there can only be one payload, there can only be one body parameter. The name of the body parameter has no effect on the parameter itself and is used for documentation purposes only. Since Form parameters are also in the payload, body and form parameters cannot exist together for the same operation.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题