Loopback remote method: check parameters

Is there a form to make loopback automatically check input parameters in a remote method?

Suppose we have the following definition of a remote method:

WebuserModel.remoteMethod('overLogin', { description: "Performs a Webuser 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'} } 

I would expect loopback to check the input parameter for each request and raise an error if the passed object does not match a specific scheme (required object with two required properties).

This does not seem to be happening. Any clue?

+5
source share
1 answer

Disclaimer: I am the main developer of LoopBack and author of checking arguments in the file strong-remoting@3.x.

LoopBack does not support checking properties of nested objects provided by clients when calling remote methods. Right now, we are only checking that the value is an object, see lib / types / object.js in strong delete.

In the upcoming version of LoopBack 4, we plan to support full OpenAPI and / or JSON Schema validation for input arguments, see https://github.com/strongloop/loopback-next/issues/118

Based on the comments on this GitHub issue, it should be relatively easy to add JSONSchema-based validations to LoopBack 3.x too.

+1
source

Source: https://habr.com/ru/post/1260342/


All Articles