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

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

问题描述

我正在尝试使用 swagger 编写服务器响应的静态 .json 文件.我被帖子正文卡住了,不知道如何描述它.它看起来与 Grooveshark api 非常相似,您只有一个页面和不同的帖子参数.

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天全站免登陆