Generates JSON schemas for your LoopBack models
npm install loopback-jsonschema-generator
Add the following configuration to component-config.js
inside your loopback project
{
"loopback-jsonschema-generator": {},
"..."
}
- 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"
},
"..."
}
# products.json
{
"name": "Products",
"base": "PersistedModel",
"properties": {
"name": {
"type": "string",
"title": "Name",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
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"
]
}
A property is added onto each model under model.jsonSchema
// Model file
module.exports = function(Products) {
const jsonSchema = Products.jsonSchema;
//...
};