Loopback v4 嵌套对象(n.o。)而不创建 n.o。作为单独的模型

Loopback v4 nested object(n.o.) without creating that n.o. as separate model

一周前我开始使用 Loopback 4。而且,我在一些问题上卡了很久。

我正在尝试构建用户模型

@model()
export class Address {
  @property() addressLine1: string;
  @property() addressLine2: string;
  @property() pin: string;
}

@model()
export class User {
  @property() email: string;
  @property() password: string;
  @property() phone: string;
  @property() address: Address;
}

第 1 期

当我尝试从 API 端点保存模型时,出现以下错误:

Unhandled error in POST /users: 500 Error: can't resolve reference #/components/schemas/Address from id #

我认为环回试图将地址保存为模型。我需要将该地址保存为 dynamoDB 中的 json 字段,而不是创建新模型。

是否有一个 key/property/setting 可以传入模型,通过它我可以忽略它的创建?我浏览了教程和 API 文档,但没有找到任何帮助。

第 2 期

Address 模型仅在添加 @model() 注释时才会出现在 Swagger

有没有更简单的方法可以在没有 @model 的情况下将 Address 放在 swagger 中?

注意:我正在使用 DynamoDB 连接器:lb-dynamodb-connector

我认为下面的内容应该适合你。

@model()
export class Address extends Model {
  @property() addressLine1: string;
  @property() addressLine2: string;
  @property() pin: string;
}

@model()
export class User extends Entity {
  @property() email: string;
  @property() password: string;
  @property() phone: string;
  @property({
    type: 'object',
  }) address: Address;
}

虽然我没有使用过发电机数据库连接器。但这应该按照环回模型运行。