Is it possible to hide the id attribute in a method in swagger-ui generated by explorer in Strongloop Loopback? I don want the user to create a new resource and send the id attribute. I know that if the user send the id it can be ignored but I want to hide it in the explorer.
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:
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.