rand0m86 rand0m86 - 4 months ago 84
JSON Question

Swagger POST with json body

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?

Answer

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