Converts TS classes into JSON Schemas using TypeScript's reflection API
npm install @loopback/repository-json-schemaConvert a TypeScript class/model to a JSON Schema for users, leveraging
LoopBack4's decorators, metadata, and reflection system.
This package provides modules to easily convert LoopBack4 models that have been
decorated with @model and @property to a matching JSON Schema Definition.
``shell`
$ npm install --save @loopback/repository-json-schema
`ts
import {getJsonSchema} from '@loopback/repository-json-schema';
import {model, property} from '@loopback/repository';
@model()
class MyModel {
@property()
name: string;
}
const jsonSchema = getJsonSchema(MyModel);
`
The value of jsonSchema will be:
`json`
{
"title": "MyModel",
"properties": {
"name": {
"type": "string"
}
}
}
Run npm test` from the root folder.
See
all contributors.
MIT