Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger POST with json body

Tags:

json

swagger

I am trying to write static .json file of server response using swagger. I'm stuck with post body and do not know how to describe it. It looks pretty much similar to Grooveshark api's where you have one page and different post parameters.

So, given grooveshark example (http://developers.grooveshark.com/docs/public_api/v3/)

Page that takes queries:

http://api.grooveshark.com/ws3.php?sig=cd3ccc949251e0ece014d620bbf306e7

POST body:

{
  'method': 'addUserFavoriteSong',
  'parameters': {'songID': 0},
  'header': {
    'wsKey': 'key',
    'sessionID': 'sessionID'
  }
}

How can I describe this with swagger?

like image 268
rand0m86 Avatar asked Nov 10 '13 17:11

rand0m86


1 Answers

without knowing a ton about how this API operates (such as, is "songID" the only parameter type?, I'm guessing you'd want something like this in your models section:

"models": {
  "FavoriteSong": {
    "id": "FavoriteSong",
    "properties": {
      "parameters": {
        "type": "Parameter"
      },
      "header": {
        "type": "Header"
      }
    }
  },
  "Parameter": {
    "id": "Parameter",
      "properties": {
        "songID": {
          "type": "integer",
          "format": "int32"
        }
      }
    }  
  "Header": {
    "id": "Header",
      "properties": {
        "wsKey": {
          "type": "string"
        },
        "sessionID": {
          "type": "string"
        }
      }
    }
  }
}

And the operation would take the type "FavoriteSong" as a body type:

"parameters": [
  {
    "name": "body",
    "description": "object to add",
    "required": true,
    "type": "FavoriteSong",
    "paramType": "body"
  }
]
like image 142
fehguy Avatar answered Nov 03 '22 11:11

fehguy