[英]swagger php pass parameters as json
所以我在我的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中,當我嘗試執行它時,出現了以下錯誤:
TypeError:無法獲取
root-injects.js:95 TypeError:e.get(...)。entrySeq不是t.default(curl.jsx:17)的t.default(curlify.js:23)的函數(t.render( u._renderValidatedComponentWithoutOwnerOrContext(ReactCompositeComponent.js:796)處的root-injects.js:93)u._performComponentUpdate(ReactCompositeComponent.ReactCompositeComponent.ReactCompositeComponent.ReactCompositeComponent.ReactCompositeComponent。 721)在Object.receiveComponent(ReactReconciler.js:122)的u.receiveComponent(ReactCompositeComponent.js:544)的updateComponent(ReactCompositeComponent.js:642)處
那我該怎么做才能解決這個問題呢?
將in="body",
更改為in="formData",
瞧。
從Swagger參數中刪除默認屬性,而是在swagger模式中進行設置。
@SWG\Schema(
@SWG\Property(property="username", type="string", example="abc@abc.com"),
@SWG\Property(property="password", type="string", example="12345678")
)
否則,如果您希望使用swagger定義,請在定義中如上所述設置swagger屬性。
通過組合@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")
)
),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.