LOOPBACK 4自动生成的模型,具有所需的ID失败验证

发布于 2025-01-26 17:50:48 字数 1487 浏览 3 评论 0原文

我正在使用使用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"
        }
      }
    ]
  }
}

I'm using an automated script that runs an auto-generation model using lb4 cli.
Looks like validation expects id to be provided, but swagger missing it in its schema. Why I can't see the id property in swagger?

PLEASE NOTE! I don't want to modify manually my models

lb4 model activity --dataSource DS --table activity

Created model:

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;
...
}

When I run the swagger tool and try to POST new activity, it missing the id field and returns the following error:

{
  "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"
        ]
      }
    }
  }
}

If I add a property id manually, then it throws a validation error:

{
  "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"
        }
      }
    ]
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

更改您的@model() by @model({settings:{strict:false:false}})并添加此行[prop:string:string]:any; any; ny; <<< /代码>进入您的模型

@model({settings: {strict: false}})
[prop: string]: any;

Change your @model() by @model({settings: {strict: false}}) and add this line [prop: string]: any; into your model

@model({settings: {strict: false}})
[prop: string]: any;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文