Search code examples
phpswaggerswagger-uiswagger-php

swagger php pass parameters as json


So i have comment like below in my php code, so basically i am trying to generate below kind of request which my api is accepting.

I have comments like below:

/**
* 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.",
*),    
* )
*/

Expected Output

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"}'

Actual Output

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\"}"

In Swagger-ui when i am trying to execute it it gives me the error:

TypeError: Failed to fetch

What i have tried

  1. Change consumes to "multipart/form-data" (Same error)
  2. If i change in="body" to in="query" then its working, but i can't use that. As its required to pass params in POST method.
  3. Might not be related, but in console i am getting below error:

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) at u._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:796) at u._renderValidatedComponent (ReactCompositeComponent.js:819) at u._updateRenderedComponent (ReactCompositeComponent.js:743) at u._performComponentUpdate (ReactCompositeComponent.js:721) at updateComponent (ReactCompositeComponent.js:642) at u.receiveComponent (ReactCompositeComponent.js:544) at Object.receiveComponent (ReactReconciler.js:122)

So what should i do to fix this issue?


Solution

  • Change in="body", to in="formData",. Voila.