I'm currently building a loopback application, which only has a single model named Phone
. Here's my common/models/phone.js
code:
module.exports = function(Phone) {
// Return a random phone's data.
Phone.random = function(callback) {
return callback(null, {
id: '12345',
number: '+18182179222',
name: 'Randall Degges'
});
};
Phone.remoteMethod('random', {
description: 'Return a random phone.',
accepts: [],
returns: [
//{ type: 'object', root: true, description: 'return value' },
{ arg: 'id', type: 'string', description: 'phone id', required: true, root: true },
{ arg: 'number', type: 'string', description: 'phone number', required: true, root: true },
{ arg: 'name', type: 'string', description: 'phone name', required: false, root: true }
],
http: {
verb: 'get', path: '/random',
}
});
};
When I pull up my API explorer on port 3000, and view my newly created random
API call, I see the following:
As you can see above, my "Model Schema" is empty. Booo!
What I'd like to accomplish is something similar to the built-in API methods, which look something like this:
As you can see above, the "Model Schema" shows what the actual output of the API call will look like.
I'm trying to figure out how to accomplish this with my remote endpoint, but so far have had no luck.
Any suggestions are welcome.
BONUS POINTS: Is there a way to simply tell Loopback that my return value is just an already-defined model? In my case all I'm doing is returning an existing Phone model, so it would be nice to just let Loopback know that somehow and have it auto-generate the documentation accordingly.
Thank you!