How can I hide the 'id' attribute in Loopback explorer?

泪湿孤枕 提交于 2019-12-06 03:50:12

In order to hide the 'id' attribute, you need declare this field as hidden.

In YOUR_MODEL.json file:

{
  "name": "YOUR_MODEL",
  .
  .
  .
  "properties": {
     // your custom properties
  },
  "hidden": ["id"], // this attribute specifies which attributes need to be hidden
  .
  .
  .
}

Be aware when a property declared as hidden:

  1. It's not exposed to the user
  2. Although hidden, if user sends provides a value with this property, the property won't be ignored by default, and will be handled with provided values. hence, need to be ignored manually.

For instance, if we have 'User' model as follows:

{
  "name": "User",
  .
  .
  .
  "properties": {
     "id": "string",
     "name": "string",
     "password": "string",

  },
  "hidden": ["id", "password"],
  .
  .
}

/api/User GET request will provide list of Users with only 'name' attribute

BUT, /api/User POST with body:

{
  "user" : "USER",
  "password": "PASS",
  "id" : "USER_PROVIDED_ID"
}

the user provided in the body will be saved with the values in it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!