Loopback: Remote methods 'default' property for 'accepts' option does not work when arg name is 'data'

Created on 7 Sep 2016  路  9Comments  路  Source: strongloop/loopback

for example:

...
'accepts': [
{
'arg': 'data',
'description': 'An object...',
'type': 'object',
'default': '{"count": 1}',
'required': true,
'http': { 'source': 'body' },
},
],
...

that example does not show the default data in explorer.

bug stale team-apex

Most helpful comment

@reyalpsirc just tested and the same is happening to me now with Loopback 3, the explorer is not displaying the box in the Data Type column when naming the argument different than data, in my case if I name the arg as data it does show that box but it still ignores the default field.

accepts: [
  {
    arg: 'data',
    type: 'object',
    required: true,
    default: '{"arg": "1"}',
    http: {source: 'body'},
  },
  {
    arg: 'info',
    type: 'object',
    required: true,
    default: '{"arg": "1"}',
    http: {source: 'body'},
  },
],

screen shot 2017-05-26 at 11 15 16 am

All 9 comments

@arielmcm I believe it will not show in explorer no matter which name you use. Please check our doc for details:
https://docs.strongloop.com/display/public/LB/Remote+methods#Remotemethods-Argumentdescriptions

Default value that will be used to populate loopback-explorer input fields and swagger documentation. Note: This value will not be passed into remote methods function if argument is not present.

So if you build your own UI and want to show the default value of an input, you can get the value from res, but explorer doesn't have it.
Example UI:

data: <input type="text" name="data" value="value_get_from_res"><br>

@jannyHou Actually it does, it shows the text you assign to the default property into the input in the explorer when it is in the path or query, but for the body it shows that text in the right side so you can click on it to display that text in the input... The only thing, at least for me, is that it does not work when the arg name is 'data'.

@arielmcm Thank you I see the problem after setting http source as body, here is a screenshot of the bug:
screen shot 2016-09-11 at 7 07 59 pm

The default value for data should be { "count": 1 }

And my config of remote method:

 "methods": {
    "myremote": {
      "isStatic": true,
      "accepts": [
        {
          "arg": "data",
          "type": "object",
          "required": false,
          "default": {"count": 1},
          "description": "myarg",
          "http": { "source": "body" }
        },
        {
          "arg": "myarg",
          "type": "object",
          "required": false,
          "default": {"count": 2},
          "description": "myarg2",
          "http": { "source": "body" }
        }
      ],
      "returns": [
        {
          "arg": "result",
          "type": "object",
          "root": true,
          "description": ""
        }
      ],
      "description": "test",
      "http": [
        {
          "path": "/myremote",
          "verb": "get"
        }
      ]
    }
  }

Any news on this?
Because on my case I'm getting this result:

captura de ecra 2017-05-26 as 12 46 02

And the remote method as the args declared like this:

[...]
accepts: [
          {arg: 'info', type: 'object',
            default: {
              'provider': 'string',
              'kind': 'string',
              'resource_id': 'string',
            },
            http: {source: 'body'},
          },
        ],
[...]

@reyalpsirc just tested and the same is happening to me now with Loopback 3, the explorer is not displaying the box in the Data Type column when naming the argument different than data, in my case if I name the arg as data it does show that box but it still ignores the default field.

accepts: [
  {
    arg: 'data',
    type: 'object',
    required: true,
    default: '{"arg": "1"}',
    http: {source: 'body'},
  },
  {
    arg: 'info',
    type: 'object',
    required: true,
    default: '{"arg": "1"}',
    http: {source: 'body'},
  },
],

screen shot 2017-05-26 at 11 15 16 am

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

any update on this?

I can confirm I also have this same problem on Loopback 3

Was this page helpful?
0 / 5 - 0 ratings