Naughty Programmer's Madness
Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

loopback-jsonschema-generator

1.1.1 • Public • Published

Loopback JSON Schema Generator

Build Status Coverage Status npm version

Generates JSON schemas for your LoopBack models

Installing

npm install loopback-jsonschema-generator

Setup

Initialising

Add the following configuration to component-config.js inside your loopback project

{
  "loopback-jsonschema-generator": {},
  "..."
}

Configuration options

  • schema - JSON Schema specification
  • url - Url to access each JSON schema endpoint, defaults to 'json-schema'
{
  "loopback-jsonschema-generator": {
    "schema": "http://json-schema.org/draft-04/schema",
    "url": "json-schema"
  },
  "..."
}

Using

Define a model inside loopback as normal

# products.json
{
    "name": "Products",
    "base": "PersistedModel",
    "properties": {
        "name": {
          "type": "string",
          "title": "Name",
          "required": true
        }
    },
    "validations": [],
    "relations": {},
    "acls": [],
    "methods": {}
}

Access the generated JSON schema url

http://yourapi.com/api/products/json-schema

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Products",
    "type": "object",
    "properties": {
      "name": {
        "type": "string",
        "title": "Name"
      }
    },
    "required": [
      "name"
    ]
}

Programmatic access to the json schema

A property is added onto each model under model.jsonSchema

// Model file
module.exports = function(Products) {
  const jsonSchema = Products.jsonSchema;
  //...
};

References

http://json-schema.org/

install

npm i loopback-jsonschema-generator

Downloadsweekly downloads

24

version

1.1.1

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability