1

所以我在我的 php 代码中有如下评论,所以基本上我正在尝试生成我的 api 接受的以下类型的请求。

我有如下评论:

/**
* Login API
*
*

*@SWG\Definition(
*   definition="login",    
*   description="Enter your username",
*)

*@SWG\Definition(
*   definition="password",
*   type="string",
*   description="Enter your Password",
*)

* @SWG\Post(
* path="/user/login",
* description="Login API.",
* operationId="Login",
* produces={"application/json"},
* tags={"login"},
* consumes={"application/json"},

*@SWG\Parameter(
*          name="params",
*          in="body",
*          type="string",
*          default="params={""username"":""abc@abc.com"",""password"":""12345678""}",
*          description="Login Detail",
*          required=true,
*          @SWG\Schema(ref="#/definitions/login")
*),
*@SWG\Response(
*   response=200,
*   description="Token overview."
*),
*@SWG\Response(
*   response=401,
*   description="Unauthorized action.",
*),    
* )
*/

预期产出

curl -X POST \
  http://localhost/project/api/web/user/login \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -H 'postman-token: 78219bf9-85a4-420f-7637-55e2f0e51b11' \
  -F 'params={"username":"abc@abc.com","password":"12345678"}'

实际输出

curl -X POST "http://localhost/project/api/web/user/login" -H "accept: application/json" -H "Content-Type: application/json" -d "params={\"username\":\"abc@abc.com\",\"password\":\"12345678\"}"

在 Swagger-ui 中,当我尝试执行它时,它给了我错误:

类型错误:获取失败

我试过的

  1. 更改消耗为“multipart/form-data”(同样的错误)
  2. 如果我将 in="body" 更改为 in="query" 那么它可以工作,但我不能使用它。因为它需要在 POST 方法中传递参数。
  3. 可能不相关,但在控制台中我收到以下错误:

root-injects.js:95 TypeError: e.get(...).entrySeq is not a function at t.default (curlify.js:23) at t.value (curl.jsx:17) at t.render ( root-injects.js:93) 在 u._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:796) 在 u._renderValidatedComponent (ReactCompositeComponent.js:819) 在 u._updateRenderedComponent (ReactCompositeComponent.js:743) 在 u._performComponentUpdate (ReactCompositeComponent.js: 721) 在 updateComponent (ReactCompositeComponent.js:642) 在 u.receiveComponent (ReactCompositeComponent.js:544) 在 Object.receiveComponent (ReactReconciler.js:122)

那么我应该怎么做才能解决这个问题呢?

4

3 回答 3

1

从 Swagger 参数中删除默认属性,而是在 Swagger 模式中设置它们。

@SWG\Schema(
    @SWG\Property(property="username", type="string", example="abc@abc.com"),
    @SWG\Property(property="password", type="string", example="12345678")
)

否则,如果您希望使用 swagger 定义,请在您的定义中设置如上所述的 swagger 属性。

于 2018-07-11T08:03:59.143 回答
1

更改in="body",in="formData",。瞧。

于 2018-07-09T14:56:27.553 回答
0

通过结合@Pusparaj 和@delboy1978uk 提供的答案来解决

基本上我必须将 , 更改in="body"in="formData"

之后,我必须更改我的评论,如下所示:

早些时候

*@SWG\Parameter(
*          name="params",
*          in="body",
*          type="string",
*          default="params={""username"":""abc@abc.com"",""password"":""12345678""}",
*          description="Login Detail",
*          required=true,
*          @SWG\Schema(ref="#/definitions/login")
*),

更新

@SWG\Parameter(
    name="params",
    in="formData",
    type="string",
    default="params={""username"":""abc@abc.com"",""password"":""12345678""}",
    description="Login Detail",
    required=true,
    @SWG\Schema(
        @SWG\Property(property="username", type="string"),
        @SWG\Property(property="password", type="string")
    )
),
于 2018-07-11T12:45:41.870 回答