Seeking assistance in grasping the working of models in loopback4. Here's a model I defined:
@model()
export class ProductViewConfig extends BaseConfig {
@property({
type: 'string',
id: true,
generated: true,
})
_id?: string;
@property({
type: 'array',
itemType: 'object',
})
tiles: Array<TileOptions>;
constructor(data?: Partial<ProductViewConfig>) {
super(data);
}
}
export interface ProductViewConfigRelations {
// describe navigational properties here
}
export type ProductViewConfigWithRelations = ProductViewConfig & ProductViewConfigRelations;
The baseConfig class that it extends from has this structure:
@model({
settings: {
strict: true
}
})
export class BaseConfig extends Entity {
@property({
type: 'object',
required: true,
})
configMetadata: ConfigMetadata;
@property({
type: 'array',
itemType: 'object',
})
sharedUsers: Array<SharedUsers>;
@property({
type: 'array',
itemType: 'object',
})
sharedRoles: Array<SharedRoles>;
constructor(data?: Partial<BaseConfig>) {
super(data);
}
}
export interface BaseConfigRelations {
// describe navigational properties here
}
export type BaseConfigWithRelations = BaseConfig & BaseConfigRelations;
My ConfigMetadata Model is as follows:
@model({ settings: { strict: true } })
export class ConfigMetadata extends Entity {
@property({
type: 'string',
required: true,
})
name: string;
@property({
type: 'string',
required: true,
})
description: string;
@property({
type: 'date',
required: true,
})
dateCreated: string;
@property({
type: 'date',
required: true,
})
lastUpdatedOn: string;
@property({
type: 'string',
required: true,
})
creatorId: string;
@property({
type: 'string',
required: true,
})
creatorName: string;
constructor(data?: Partial<ConfigMetadata>) {
super(data);
}
}
....
In my controller, there's a post endpoint with a request body using getModelSchemaRef(myObj)
@post('/product-view-configs')
@response(200, {
description: 'ProductViewConfig model instance',
content: { 'application/json': { schema: getModelSchemaRef(ProductViewConfig) } },
})
async create(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(ProductViewConfig,
{
title: 'NewProductViewConfig',
}),
},
},
})
productViewConfig: ProductViewConfig,
): Promise<ProductViewConfig> {
return this.productViewConfigRepository.create(productViewConfig);
}
Here's my question:
Why does the request body not match the expected object structure?
https://i.stack.imgur.com/jlM93.png
I expect the request body to look like this:
{
"_id" : "string",
"configMetadata" : {
"name" : "string",
"description" : "string",
"createdOn" : "date",
"lastUpdatedBy" : "date",
"creatorId" : "string",
"creatorName" : "string"
},
"sharedUsers" : [
{...}
],
"sharedRoles" : [
{...}
],
"tiles" : [
{...}
]
}
So, why aren't the properties from baseConfig showing up? Any guidance would be appreciated as I couldn't find the answer in the loopback4 documentation! Thank you!