Swagger POST with json body

妖精的绣舞 提交于 2020-01-13 09:01:45

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/19892998/swagger-post-with-json-body

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!