带有JSON正文的Swagger POST [英] Swagger POST with json body

查看:954
本文介绍了带有JSON正文的Swagger POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用swagger编写服务器响应的静态.json文件.我受制于邮件正文,不知道如何形容.它看起来与Grooveshark api非常相似,在该API中,您只有一页并且具有不同的post参数.

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.

因此,以grooveshark示例为例( http://developers.grooveshark.com/docs/public_api/v3/)

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

接受查询的页面:

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

POST正文:

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

我该如何用招摇来形容?

How can I describe this with swagger?

推荐答案

而又不了解此API的运行方式(例如,"songID"是唯一的参数类型吗?在您的模型部分:

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

该操作将"FavoriteSong"类型作为主体类型:

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

这篇关于带有JSON正文的Swagger POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆