Loopback: How to modify api description for automatically generated apis on loopback api explorer.

Created on 19 May 2016  路  6Comments  路  Source: strongloop/loopback

Hi,

Firstly, Thanks you all for a fantastic open-source.

I've a question that how to modify apis description for automatically generated apis on loopback api explorer. For example I have an api to create friends (POST /friends/ ) and I want to add some additional description for how to use this api, what are acceptable params, etc ....

Can someone please provide a solution for this ?
Many thanks.

Most helpful comment

@dongmai: To modify description of Friend model-methods, you can do following in your Friend.js file:

module.exports = function(Friend) {
  var create = Friend.sharedClass.find('create', true); // 'create' is the method name, isStatic = true
  create.description = 'Your new awesome description';
};

This will change the description and you can verify it in LB explorer.
You can see which method is connected to what end-point: Predefined remote methods.

Closing this now. should you need any further assistance, please reopoen the issue and mention my GH handle, will be happy to help. Thanks.

All 6 comments

@dongmai: To begin with: Is your endpoint POST /friends/ generated by a remoteMethod, if yes, you can easily provide the description while registering your method as follows:

MyModel.remoteMethod('friends',{
  description: 'say how cool your method is',
  accepts: {...},
  returns: {...},
  http: {  path: '/', verb:'POST'}
});

@gunjpan , Thank for the reply.

But POST /friends/ endpoint is auto-generated when I create friend model.

@bajtos : Hi Miroslav, could you PTAL and advise how we can change the description for our built-in model methods. Thanks.

@dongmai: To modify description of Friend model-methods, you can do following in your Friend.js file:

module.exports = function(Friend) {
  var create = Friend.sharedClass.find('create', true); // 'create' is the method name, isStatic = true
  create.description = 'Your new awesome description';
};

This will change the description and you can verify it in LB explorer.
You can see which method is connected to what end-point: Predefined remote methods.

Closing this now. should you need any further assistance, please reopoen the issue and mention my GH handle, will be happy to help. Thanks.

@gunjpan the solution you provided does not seem to hold for remoteMethods, do you maybe know how to change their descriptions as well?

example:

module.exports = function(Friend) {
  var method = Friend.sharedClass.findMethodByName('prototype.__get__cars');
  method.description = "hello"
}

I tried many different methodNames, but none of them seemed to work

Changing remoting metadata for relation methods is tricky. IIRC, their sharedMethod instances are always re-created and then dropped away, therefore your changes are not persisted. Please open a new issue to track this problem.

Was this page helpful?
0 / 5 - 0 ratings