How can I hide the id attribute in the loopback explorer?

Is it possible to hide id attribute in swagger-ui method generated by explorer in Loopback Strongloop? I do not want the user to create a new resource and send the id attribute. I know that if a user sends an identifier, it can be ignored, but I want to hide it in Explorer.

+3
javascript loopbackjs swagger strongloop
source share
1 answer

To hide the id attribute, you need to declare this field hidden.

In the file YOUR_MODEL.json:

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

Remember when a property is declared as hidden:

  • It is not displayed to the user.
  • Although hidden, if the user submits, assigns a value to this property, the property will not be ignored by default and will be processed with the provided values . therefore, you must ignore it manually.

For example, if we have a User model as follows:

 { "name": "User", . . . "properties": { "id": "string", "name": "string", "password": "string", }, "hidden": ["id", "password"], . . } 

/api/User GET request will provide a list of users with attribute only

BUT, /api/User POST with the body:

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

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

+9
source share

All Articles