Define complex data templates for loopback models
- Install in you loopback project:
npm install --save loopback-component-templates
-
Create a component-config.json file in your server folder (if you don't already have one)
-
Configure options inside
component-config.json
. (see configuration section)
{
"loopback-component-templates": true
}
-
Define a template config on a Model._templates property.
-
Define the templates that generate dummy data. In this example we add a remote method called
_template_basic
to the Product model.
const faker = require('faker/locale/en')
Product._templates = () => ({
basic: () => ({
name: faker.commerce.productName(),
description: faker.lorem.sentence(),
}),
})
- Add way to create related/deep structures
- Add option to Validate template generators