4

in my Zend-Application I am writing a little API for mobile-Applications. To make it easy for the mobile-developers I am using Swagger. Up to now everything works fine except one GET-Request.

When I am calling /user/messages/{sessionToken}?numMessages={numMessages}&pageNr={pageNr} in a browser I get the results I want, but when I try to let Swagger do this request, only the sessionToken is transmitted. I tried this annotations for Swagger:

/**
 * @SWG\Api(path="/user/messages/{sessionToken}?numMessages={numMessages}&pageNr={pageNr}",
 *   @SWG\Operation(
 *     method="GET",
 *     summary="Gets messages paged",
 *     notes="",
 *     type="string",
 *     nickname="getUsermessagesPaged",
 *     authorizations={},
 *     @SWG\Parameter(
 *       name="sessionToken",
 *       description="The token from an active user session",
 *       required=true,
 *       type="string",
 *       paramType="path",
 *       allowMultiple=true
 *     ),
 *     @SWG\Parameter(
 *       name="numMessages",
 *       description="number of messages on page (numMessages & pageNr are ignored if not both are set)",
 *       required=true,
 *       type="string",
 *       paramType="query",
 *       allowMultiple=true
 *     ),
 *     @SWG\Parameter(
 *       name="pageNr",
 *       description="pagenumber (numMessages & pageNr are ignored if not both are set)",
 *       required=true,
 *       type="string",
 *       paramType="query",
 *       allowMultiple=true
 *     ),
 *     @SWG\ResponseMessage(code=200, message="json {messages => 'user_messages'}"),
 *     @SWG\ResponseMessage(code=400, message="json with error 'not logged in'")
 *   )
 * )
 */

Does anybody see my mistake?

Any help is welcome.

Kind regards

rholtermann

Update: As suggested I changed both paramTypes to "query" and changed the path:

@SWG\Api(path="/user/messages/{sessionToken}",

but it didn't work eighter.

xdebug in eclipse PDT shows:

requestURI => /ias/public/user/messages/{sessionToken}

and

- queryParams => Zend\\Stdlib\\Parameters
     - *ArrayObject*storage => Array[0]
        -  => <Uninitialized>

the swagger JSON is:

{
    "apiVersion": "1.0.0",
    "swaggerVersion": "1.2",
    "apis": [
        {
            "path": "\/user",
            "description": "Operations about users"
        }
    ],
    "info": {
        "title": "Mobile access api",
        "description": "This is the xxx mobile access api.",
        "termsOfServiceUrl": null,
        "contact": "xxx",
        "license": null,
        "licenseUrl": null,
        "_partialId": null,
        "_partials": [ ],
        "_context": {
            "comment": "\/**\ * @SWG\\Info(\ * title="Mobile access api",\ * description="This is the xxx mobile access api.",\ * contact="xxx",\ * )\ *\/",
            "line": 3
        }
    }
}

Here is th output of /user:

 {
     "basePath": "http://localhost/ias/public",
     "swaggerVersion": "1.2",
     "apiVersion": "1.0.0",
     "resourcePath": "/user",
     "apis": [
         {
             "path": "/user/balance/{sessionToken}",
             "operations": [
                 {
                     "method": "GET",
                     "summary": "Gets userbalance",
                     "nickname": "getUserdata",
                     "type": "string",
                     "parameters": [
                         {
                             "paramType": "path",
                             "name": "sessionToken",
                             "type": "string",
                             "required": true,
                             "allowMultiple": false,
                             "description": "The token from an active user session"
                         }
                     ],
                     "responseMessages": [
                         {
                             "code": 200,
                             "message": "json {balance => 'user_balance'}"
                         },
                         {
                             "code": 400,
                             "message": "json with error 'not logged in'"
                         }
                     ],
                     "notes": "",
                     "authorizations": {}
                 }
             ]
         },
         {
             "path": "/user/login",
             "operations": [
                 {
                     "method": "POST",
                     "summary": "Logs user into the system",
                     "nickname": "loginUser",
                     "type": "string",
                     "parameters": [
                         {
                             "paramType": "form",
                             "name": "email",
                             "type": "string",
                             "required": true,
                             "allowMultiple": false,
                             "description": "The user email for login"
                         },
                         {
                             "paramType": "form",
                             "name": "password",
                             "type": "string",
                             "required": true,
                             "allowMultiple": false,
                             "description": "The password for login in clear text"
                         }
                     ],
                     "responseMessages": [
                         {
                             "code": 200,
                             "message": "json with session_id, user_id, user_balance"
                         },
                         {
                             "code": 400,
                             "message": "json with error 'no user with given email and password'"
                         },
                         {
                             "code": 400,
                             "message": "json with error 'invalid input'"
                         },
                         {
                             "code": 400,
                             "message": "json with error 'no post request'"
                         }
                     ],
                     "notes": "",
                     "authorizations": {}
                 }
             ]
         },
         {
             "path": "/user/logout",
             "operations": [
                 {
                     "method": "POST",
                     "summary": "Logs user out",
                     "nickname": "logoutUser",
                     "type": "string",
                     "parameters": [
                         {
                             "paramType": "form",
                             "name": "sessionToken",
                             "type": "string",
                             "required": true,
                             "allowMultiple": false,
                             "description": "The token from an active user session"
                         }
                     ],
                     "responseMessages": [
                         {
                             "code": 200,
                             "message": "json {result => 'deleted'}"
                         },
                         {
                             "code": 400,
                             "message": "json with error 'no user_session with given sid'"
                         },
                         {
                             "code": 400,
                             "message": "json with error 'invalid input'"
                         },
                         {
                             "code": 400,
                             "message": "json with error 'no post request'"
                         }
                     ],
                     "notes": "",
                     "authorizations": {}
                 }
             ]
         },
         {
             "path": "/user/messages/{sessionToken}",
             "operations": [
                 {
                     "method": "GET",
                     "summary": "Gets new messages",
                     "nickname": "getUsermessages",
                     "type": "string",
                     "parameters": [
                         {
                             "paramType": "path",
                             "name": "sessionToken",
                             "type": "string",
                             "required": true,
                             "allowMultiple": false,
                             "description": "The token from an active user session"
                         }
                     ],
                     "responseMessages": [
                         {
                             "code": 200,
                             "message": "json {messages => 'user_messages'}"
                         },
                         {
                             "code": 400,
                             "message": "json with error 'not logged in'"
                         }
                     ],
                     "notes": "",
                     "authorizations": {}
                 },
                 {
                     "method": "GET",
                     "summary": "Gets messages paged",
                     "nickname": "getUsermessagesPaged",
                     "type": "string",
                     "parameters": [
                         {
                             "paramType": "path",
                             "name": "sessionToken",
                             "type": "string",
                             "required": true,
                             "description": "The token from an active user session"
                         },
                         {
                             "paramType": "query",
                             "name": "numMessages",
                             "type": "string",
                             "required": true,
                             "description": "number of messages on page (numMessages & pageNr are ignored if not both are set)"
                         },
                         {
                             "paramType": "query",
                             "name": "pageNr",
                             "type": "string",
                             "required": true,
                             "description": "pagenumber (numMessages & pageNr are ignored if not both are set)"
                         }
                     ],
                     "responseMessages": [
                         {
                             "code": 200,
                             "message": "json {messages => 'user_messages'}"
                         },
                         {
                             "code": 400,
                             "message": "json with error 'not logged in'"
                         }
                     ],
                     "notes": "",
                     "authorizations": {}
                 }
             ]
         },
         {
             "path": "/user/userdata",
             "operations": [
                 {
                     "method": "POST",
                     "summary": "Posts userdata",
                     "nickname": "postUserdata",
                     "type": "string",
                     "parameters": [
                         {
                             "paramType": "form",
                             "name": "sessionToken",
                             "type": "string",
                             "required": true,
                             "allowMultiple": false,
                             "description": "The token from an active user session"
                         },
                         {
                             "paramType": "form",
                             "name": "password",
                             "type": "string",
                             "required": false,
                             "allowMultiple": false,
                             "description": "new password"
                         },
                         {
                             "paramType": "form",
                             "name": "address",
                             "type": "string",
                             "required": false,
                             "allowMultiple": false,
                             "description": "new address"
                         },
                         {
                             "paramType": "form",
                             "name": "housenr",
                             "type": "string",
                             "required": false,
                             "allowMultiple": false,
                             "description": "new housenr"
                         },
                         {
                             "paramType": "form",
                             "name": "zip",
                             "type": "string",
                             "required": false,
                             "allowMultiple": false,
                             "description": "new zip"
                         },
                         {
                             "paramType": "form",
                             "name": "city",
                             "type": "string",
                             "required": false,
                             "allowMultiple": false,
                             "description": "new city"
                         },
                         {
                             "paramType": "form",
                             "name": "email",
                             "type": "string",
                             "required": false,
                             "allowMultiple": false,
                             "description": "new email"
                         }
                     ],
                     "responseMessages": [
                         {
                             "code": 200,
                             "message": "json {user => 'userdata'}"
                         },
                         {
                             "code": 400,
                             "message": "json with error 'not logged in'"
                         }
                     ],
                     "notes": "",
                     "authorizations": {}
                 }
             ]
         },
         {
             "path": "/user/userdata/{sessionToken}",
             "operations": [
                 {
                     "method": "GET",
                     "summary": "Gets userdata",
                     "nickname": "getUserdata",
                     "type": "string",
                     "parameters": [
                         {
                             "paramType": "path",
                             "name": "sessionToken",
                             "type": "string",
                             "required": true,
                             "allowMultiple": false,
                             "description": "The token from an active user session"
                         }
                     ],
                     "responseMessages": [
                         {
                             "code": 200,
                             "message": "json {user => 'userdata', user_limit => 'userLimits'}"
                         },
                         {
                             "code": 400,
                             "message": "json with error 'not logged in'"
                         }
                     ],
                     "notes": "",
                     "authorizations": {}
                 }
             ]
         }
     ],
     "produces": [
         "application/json"
     ]
 }

The error seems to be, that my swagger-ui doesn't send out any query-params? Here is an example with only one query-param, the sessionToken: (monitored by FireBug 2.0.6)

GET /ias/public/user/balance HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: application/json
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/json
Referer: http://localhost/ias/swagger/
Cookie: __utma=111872281.581414660.1366700677.1394721873.1394723866.255; uvts=sB5Dda3cZBNdaTk; searchpanel-close=set
Connection: keep-alive

The answer was:

HTTP/1.1 400 Bad Request
Date: Tue, 25 Nov 2014 14:58:20 GMT
Server: Apache/2.4.9 (Win32) PHP/5.5.12
X-Powered-By: PHP/5.5.12
Content-Length: 25
Connection: close
Content-Type: application/json; charset=utf-8

The answer was correct, because no sessionToken was transmitted.

This requests works, but it doesn't come from swagger-ui:

GET /ias/public/user/balance?sessionToken=54275cc6358e42c4b1fb1d8daf850b52 HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Cookie: __utma=111872281.581414660.1366700677.1394721873.1394723866.255; uvts=sB5Dda3cZBNdaTk; searchpanel-close=set
Connection: keep-alive
5
  • One thing that's unclear is when you're observing the problem. Is it when your application starts up? Is it when you're running Swagger-UI operations? Commented Nov 25, 2014 at 11:47
  • When I am running Swagger-UI operations it is not working, when I am using Chrome-Postman to do the request, everything is fine. Commented Nov 25, 2014 at 12:22
  • Okay. The main problem is that there are two GET operations on /user/messages/{sessionToken}. I assume you use swagger-php, which I'm not familiar with, so I can't tell you why it's doing that, unfortunately. Commented Nov 25, 2014 at 12:26
  • Thank you very much. Yes I use swagger-php. For testing I deleted one get-operation but the error was still remaining. I have no idea, what is going wrong. Commented Nov 25, 2014 at 12:50
  • What's the error you see in the UI? If you don't see anything specific, try checking the browser's web console and see the network. Check the request and response, you can even paste those here. Commented Nov 25, 2014 at 12:56

3 Answers 3

2

Change the first line to:

* @SWG\Api(path="/user/messages/{sessionToken}",

Swagger doesn't support query parameters as part of the path itself. They will be added to the request (from the UI) automatically as they are described as query type.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your answer, but it didn't work eighter. I checked the request-params in xdebug and got no params submitted. Do you have any other idea?
Yes. Can you modify your question and add the Swagger JSON you get from the application?
Changed it. But I am a little confused the api-calls are not displayed?
I'll assume you got that from /api-docs. Can you see what output you get from /api-docs/user (or /api-docs/\user)?
I added the output of "/user". I am really thankfull!
0

I think you are missing

paramType="query",

to

paramType="path",

I think this will solve your issue

4 Comments

Thank you for your answer, but that didn't work eighter, I tried that before. I set all three paramTypes to Path, but the params "numMessages" and "pageNr" have not been transmitted in both cases.
did you check this in the console what is passing ?
allowMultiple=true remove this and then try
i had a view on the request in xdebug-session in eclipse PDT. I also removed "allowMultiple=true" -> didn't work eighter.
0

The problem is solved, the solution was to update swagger-ui.

After updating, the query-params had been send to the application and everything works fine.

Thanks to everyone who tried to solve my problem.

Kind regards rholtermann

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.