https://github.com/chrisandrews7/loopback-jsonschema-generator
Generate JSON schema endpoints for your LoopBack models
https://github.com/chrisandrews7/loopback-jsonschema-generator
json json-schema loopback loopback-component loopback-models nodejs
Last synced: 4 months ago
JSON representation
Generate JSON schema endpoints for your LoopBack models
- Host: GitHub
- URL: https://github.com/chrisandrews7/loopback-jsonschema-generator
- Owner: chrisandrews7
- Created: 2016-12-01T19:16:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-11T18:07:54.000Z (about 7 years ago)
- Last Synced: 2025-02-14T01:07:54.570Z (4 months ago)
- Topics: json, json-schema, loopback, loopback-component, loopback-models, nodejs
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/loopback-jsonschema-generator
- Size: 13.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Loopback JSON Schema Generator
[](https://travis-ci.org/chrisandrews7/loopback-jsonschema-generator) [](https://coveralls.io/github/chrisandrews7/loopback-jsonschema-generator?branch=master) [](https://www.npmjs.com/package/loopback-jsonschema-generator)
Generates JSON schemas for your [LoopBack](https://github.com/strongloop/loopback) models
## Installing
```
npm install loopback-jsonschema-generator
```## Setup
### Initialising
Add the following configuration to `component-config.js` inside your loopback project
```json
{
"loopback-jsonschema-generator": {},
"..."
}
```### Configuration options
- **schema** - JSON Schema specification
- **url** - Url to access each JSON schema endpoint, defaults to 'json-schema'```json
{
"loopback-jsonschema-generator": {
"schema": "http://json-schema.org/draft-04/schema",
"url": "json-schema"
},
"..."
}
```## Using
### Define a model inside loopback as normal
```json
# 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`
```json
{
"$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`
```js
// Model file
module.exports = function(Products) {
const jsonSchema = Products.jsonSchema;
//...
};
```## References
http://json-schema.org/