Skip to content

Instantly share code, notes, and snippets.

@dhmlau
Created September 12, 2017 03:02
Show Gist options
  • Save dhmlau/60906df54063fff1ffd61bca5596401f to your computer and use it in GitHub Desktop.
Save dhmlau/60906df54063fff1ffd61bca5596401f to your computer and use it in GitHub Desktop.

Contents

Overview

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

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

Schema for Route Response

	- 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

How they are related to each other

Future Plans

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment