2016-11-25 62 views
5

有没有一种形式可以让回送自动验证远程方法中的输入参数?环回远程方法:参数验证

假设我们有一个远程方法的定义如下:

WebuserModel.remoteMethod('overLogin', { 
     description: "Performs a Webuser's login to the system", 
     accepts: [ 
     { 
      arg: 'credentials', type: { 
      "username": { type: "string", required:true }, 
      "password": { type: "string", required: true } 
      }, 
      http: {source: 'body'}, 
      required: true 
     }, 
     ], 
     returns: {arg: 'accesToken', type: "object", root: true}, 
     http: {path: '/login', verb: 'post'} 
    } 

我会在这里从环回期望对每个请求执行输入参数的验证,如果传递的对象不会引发错误遵守定义的模式(具有两个强制性属性的强制对象)。

显然它没有发生。 任何线索?

+0

好问题,我不确定它是否在嵌套对象上,请求一些澄清[这里](https://github.com/strongloop/strong-remoting/issues/387) – Overdrivr

回答

1

声明:我是LoopBack的核心开发人员,也是[email protected]中参数验证的作者。

LoopBack不支持在调用远程方法时验证客户端提供的嵌套对象属性。现在,我们只检查该值是否是一个对象,参见lib/types/object.js强烈的远程处理。

在即将到来的环回4版,我们正计划支持输入参数完全OpenAPI的和/或JSON模式验证,看https://github.com/strongloop/loopback-next/issues/118

基于在GitHub上的问题的意见,应该是比较容易添加也基于JSONSchema验证到LoopBack 3.x。