Contents
A schema
represents the definition of a model. There are two flavors of schemas used in LoopBack: schema for juggler models and OpenAPI schema for route response.
Schema for juggler models are the metadata applied within the decorators that can be used with legacy juggler for persistence.
Here is an example:
@model()
export class Product extends Entity {
@property({
type: 'number',
id: true,
description: 'The unique identifier for a product',
})
id: number;
@property({type: 'string'})
name: string;
@property({type: 'string'})
slug: string;
constructor(data?: Partial<Product>) {
super(data);
}
}
The @model
decorator is used for model definition, where the @property
decorator is used for property definition. The complete list of attributes in property definition can be found in here: https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#properties
- For routing when building REST API
§ Code Snippet: https://github.com/strongloop/loopback-next/blob/661fa363ce9d16b71f1b3bcefa861c609eba4b8f/packages/core/test/acceptance/routing/feature.md
§ How to define a schema for a route response
We are intended to unify these two schemas and possibly adding tooling support to make it easier to keep them in sync.
work in progress