# loopback-jsonschema-generator

> Generates JSON schemas for your Loopback models

Latest version **1.1.1** (published 2018-05-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install loopback-jsonschema-generator
pnpm add loopback-jsonschema-generator
yarn add loopback-jsonschema-generator
bun add loopback-jsonschema-generator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2018-05-11 |
| First published | 2016-12-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 33.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Chris Andrews |
| Maintainers | chrisandrews7 |
| Keywords | loopback, json-schema, json, schema, json schema, jsonschema, generator, strongloop, component |

## Links

- npm: https://www.npmjs.com/package/loopback-jsonschema-generator
- Repository: https://github.com/chrisandrews7/loopback-jsonschema-generator
- Homepage: https://github.com/chrisandrews7/loopback-jsonschema-generator#readme
- Issues: https://github.com/chrisandrews7/loopback-jsonschema-generator/issues
- npm.io page: https://npm.io/package/loopback-jsonschema-generator

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.1.1 (latest) — 2018-05-11
- 1.0.1 — 2016-12-03
- 1.0.0 — 2016-12-02

## README

# Loopback JSON Schema Generator

[![Build Status](https://travis-ci.org/chrisandrews7/loopback-jsonschema-generator.svg?branch=master)](https://travis-ci.org/chrisandrews7/loopback-jsonschema-generator) [![Coverage Status](https://coveralls.io/repos/github/chrisandrews7/loopback-jsonschema-generator/badge.svg?branch=master)](https://coveralls.io/github/chrisandrews7/loopback-jsonschema-generator?branch=master) [![npm version](https://img.shields.io/npm/v/loopback-jsonschema-generator.svg?style=flat)](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/

---
_Source: https://npm.io/package/loopback-jsonschema-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
