loopbackjs - 远程方法在资源管理器(Swagger)中没有登录示例
问题描述
据我了解,用户/登录是一种内置的远程方法。在 explorer (swagger) 上,它的外观包含所有需要的细节:
但是在我的远程方法上,我没有所有好的信息,例如示例等等:
我如何为接受对象的方法添加示例值
这是我的json:
"methods": {
"specifyGurdianPhone": {
"accepts": [
{
"arg": "guardianPhone",
"type": "Object",
"required": true,
"description": "{guardianPhone: \"+97255111111\"}",
"http": {
"source": "body"
}
}
],
"returns": [
{
"arg": "success",
"type": "Object",
"root": true
}
],
"description": "",
"http": {
"verb": "post"
}
解决方案
这是因为您的参数和响应具有“对象”类型。Swagger 不知道它长什么样。要获得这样的视图,您需要将模型名称指定为类型或一一描述可能的属性。
示例 1:
{
"specifyGurdianPhone": {
"accepts": [
{
"arg": "guardianPhone",
"type": "string", // !!! Now, swagger know the exact type of "guardianPhone" property
"required": true
"http": {
"source": "form" // !!! Having the "form" here we say that it a property inside an object
// (it allows us to have the "string" type of the "object")
}
}
],
"returns": [
{
"arg": "success",
"type": "GuardianPhone", // !!! For example, let's return the full "GuardianPhone" instance
"root": true
}
],
"description": "",
"http": {
"verb": "post"
}
}
示例 2:
{
"specifyGurdianPhone": {
"accepts": [
{
"arg": "guardianPhone",
"type": "object",
"model": "GuardianPhone" // !!! Another way to let swagger know the type of the body
// (the same will be true, if you make the type "GuardianPhone" instead of "object" and delete "model" property)
"required": true
"http": {
"source": "body"
}
}
],
"returns": [
{
...
]
}
示例 3:
{
"specifyGurdianPhone": {
"accepts": [
{
"arg": "guardianPhone",
"type": "object",
"model": "GuardianPhone" // !!! Another way to let swagger know the type of the body
// (the same will be true, if you make the type "GuardianPhone" instead of "object" and delete "model" property)
"required": true
"http": {
"source": "body"
}
}
],
"returns": [
{
"arg": "success",
// !!! Instead of a model name you can describe properties one by one,
// but this trick will not work with arrays (it's true for "accepts" also)
// !!! WARNING You need strong-remoting v3.15.0 or higher due to https://github.com/strongloop/loopback/issues/3717 for this approach
"type": {
"id": {"type": "string", "description": "An id property"},
"guardianPhone": {"type": "string"}
},
"root": true
}
],
"description": "",
"http": {
"verb": "post"
}
}
推荐阅读
- apache-kafka - 是否有任何 api 或工具可以获取 kafka 主题中的摄取率
- clojure - 为什么我的端点没有在 Clojure 中使用 ring 传递标头/cookie 并按预期响应?
- f# - 如何修复 Giraffe API 返回的空对象通过 SqlDataProvider 从数据库中获取
- hadoop - 为什么我的 hadoop 无法理解 -chmod 命令?
- php - 在 Wordpress 中找不到 style.css
- android - 如何断开WiFi并连接到SSID和密码可用的wifi?
- linux - linux中数百万文件的重命名和更改目录结构
- sql-server - 如果它满足 CASE 中的条件,有没有办法从另一个表中选择一个名称
- botframework - 无法添加使用 AppStudio 构建的自定义团队选项卡
- javascript - 错误:`createNavigationContainer()` 已被删除。改用`createAppContainer()`