如何在Loopback explorer中隐藏'id'属性? [英] How can I hide the 'id' attribute in Loopback explorer?
问题描述
是否可以在Strongloop Loopback中的资源管理器生成的swagger-ui中隐藏id属性?
我不希望用户创建新资源并发送id属性。我知道如果用户发送id,它可以被忽略,但我想将它隐藏在资源管理器中。
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.
推荐答案
按顺序隐藏'id'属性,您需要将此字段声明为隐藏。
In order to hide the 'id' attribute, you need declare this field as hidden.
在YOUR_MODEL.json文件中:
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:
- 未向用户公开
- 虽然隐藏,但如果用户发送提供此属性的值,属性默认情况下不会被忽略,并将使用提供的值进行处理。因此,需要手动忽略。
- It's not exposed to the user
- 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.
例如,如果我们有'User'模型如下:
For instance, if we have 'User' model as follows:
{
"name": "User",
.
.
.
"properties": {
"id": "string",
"name": "string",
"password": "string",
},
"hidden": ["id", "password"],
.
.
}
/ api / User
GET请求将提供具有仅'name'属性的用户列表
/api/User
GET request will provide list of Users with only 'name' attribute
但 / api / User
POST with body:
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.
这篇关于如何在Loopback explorer中隐藏'id'属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!