如何在 Loopback 资源管理器中隐藏 'id' 属性?
How can I hide the 'id' attribute in Loopback explorer?
是否可以在Strongloop Loopback explorer生成的swagger-ui方法中隐藏id属性?
我不希望用户创建新资源并发送 id 属性。我知道如果用户发送 id 它可以被忽略但我想将它隐藏在资源管理器中。
为了隐藏'id'属性,you need declare this field as hidden.
在 YOUR_MODEL.json 文件中:
{
"name": "YOUR_MODEL",
.
.
.
"properties": {
// your custom properties
},
"hidden": ["id"], // this attribute specifies which attributes need to be hidden
.
.
.
}
当 属性 声明为隐藏时请注意:
- 不向用户公开
- 虽然是隐藏的,但如果用户发送了一个带有此 属性 的值,默认情况下 属性 不会被忽略,并将使用提供的值进行处理。因此,需要手动忽略。
例如,如果我们有如下 'User' 模型:
{
"name": "User",
.
.
.
"properties": {
"id": "string",
"name": "string",
"password": "string",
},
"hidden": ["id", "password"],
.
.
}
/api/User
GET 请求将提供 只有 'name' 属性
的用户列表
但是, /api/User
POST 正文:
{
"user" : "USER",
"password": "PASS",
"id" : "USER_PROVIDED_ID"
}
正文中提供的用户将与其中的值一起保存。
是否可以在Strongloop Loopback explorer生成的swagger-ui方法中隐藏id属性? 我不希望用户创建新资源并发送 id 属性。我知道如果用户发送 id 它可以被忽略但我想将它隐藏在资源管理器中。
为了隐藏'id'属性,you need declare this field as hidden.
在 YOUR_MODEL.json 文件中:
{
"name": "YOUR_MODEL",
.
.
.
"properties": {
// your custom properties
},
"hidden": ["id"], // this attribute specifies which attributes need to be hidden
.
.
.
}
当 属性 声明为隐藏时请注意:
- 不向用户公开
- 虽然是隐藏的,但如果用户发送了一个带有此 属性 的值,默认情况下 属性 不会被忽略,并将使用提供的值进行处理。因此,需要手动忽略。
例如,如果我们有如下 'User' 模型:
{
"name": "User",
.
.
.
"properties": {
"id": "string",
"name": "string",
"password": "string",
},
"hidden": ["id", "password"],
.
.
}
/api/User
GET 请求将提供 只有 'name' 属性
但是, /api/User
POST 正文:
{
"user" : "USER",
"password": "PASS",
"id" : "USER_PROVIDED_ID"
}
正文中提供的用户将与其中的值一起保存。