【发布时间】:2022-11-11 11:11:45
【问题描述】:
我正在使用一个使用 lb4 cli 运行自动生成模型的自动化脚本。 看起来验证需要提供 id ,但在其架构中大摇大摆地错过了它。为什么我在 swagger 中看不到 id 属性?
请注意!我不想手动修改我的模型
lb4 model activity --dataSource DS --table activity
创建模型:
export class Activity extends Entity {
@property({
type: 'string',
required: true,
id: 1,
postgresql: {
columnName: 'id',
dataType: 'uuid',
dataLength: null,
dataPrecision: null,
dataScale: null,
nullable: 'NO',
},
})
id: string;
...
}
当我运行 swagger 工具并尝试发布新活动时,它缺少 id 字段并返回以下错误:
{
"error": {
"statusCode": 422,
"name": "ValidationError",
"message": "The `Activity` instance is not valid. Details: `id` can't be blank (value: undefined).",
"details": {
"context": "Activity",
"codes": {
"id": [
"presence"
]
},
"messages": {
"id": [
"can't be blank"
]
}
}
}
}
如果我手动添加属性id,则会引发验证错误:
{
"error": {
"statusCode": 422,
"name": "UnprocessableEntityError",
"message": "The request body is invalid. See error object `details` property for more info.",
"code": "VALIDATION_FAILED",
"details": [
{
"path": "",
"code": "additionalProperties",
"message": "must NOT have additional properties",
"info": {
"additionalProperty": "id"
}
}
]
}
}
【问题讨论】:
标签: api rest strongloop loopback4