Loopback explorer内联模型需要Model Schema

时间:2017-02-08 19:52:33

标签: node.js strongloop loopback

我遇到了我的remoteMethods没有在Loopback Explorer中显示默认值。 如果我输入JSON对象,则会创建帖子,但通常会有一个标有“Model Schema”的示例。这里只是说内联模型。

有什么想法吗?

模型定义:

{
  "name": "PicklistModel",
  "plural": "PicklistModels",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "picklistId": {
      "type": "string",
      "id": true,
      "generated": true
    },
    "key": {
      "type": "string",
      "required": false
    },
    "value": {
      "type": "string",
      "required": false
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

远程方法定义:

 Picklist.remoteMethod('create', {
    description: 'Create an PICKLIST',
    http: {
      path: '/',
      verb: 'POST'
    },
    accepts : [{
        description : 'The request to create an PICKLIST',
        arg : 'request',
        type : 'object',
        required : true,
        http : {
          source : 'body'
        },
        default: {
          key: '',
          value: ''
        }
      }
    ],
    returns: RESTResponseStatic.loopbackAdapterCommonRestResponseDefinition()
  });

Loopback Explorer

1 个答案:

答案 0 :(得分:1)

使用参数类型来代替模型类型,参见下面的示例

 accepts: [{
     description : 'The request to create an PICKLIST',
     arg: 'request',
     type: 'Picklist', // *** give model reference here
     required : true,
     http: {
         source : 'body'
     },
     default: {
         key: '',
         value: ''
     }
 }]
相关问题