LoopBack JSON Schema Registry
Example Usage
server.js
:
// Configure the app to not load the built-in models, so that the registry// can be overridden first, allowing to change the way model.json configs are// parsed.const app = // Override app.registry with a JSON Schema Registryappregistry = // Load and register all validators (keywords or formats) from ./validators loadValidators: path // Disable and emulate default LoopBack validations through JSON schema: emulateValidations: true // Define further processing / translation of model JSON properties: { if schemacomputed // Don't include computed properties in LB schema. return false // App-wide rules: const type = schema if type === 'integer' // JSON 'integer' is translated to LB 'number' schematype = 'number' else if type === 'number' && !schemapostgresql // JSON 'number' is used for double precision fields by adding postgresql // specific information schemapostgresql = dataType: 'double precision' }
validators/range.js
:
keyword: 'range' type: 'number' 'integer' metaSchema: type: 'array' items: type: 'number' type: 'number' additionalItems: false { return minimum: config0 maximum: config1 }
models/test.json
:
DEBUG=loopback:contrib:jsonschema-registry yarn start
loopback:contrib:jsonschema-registry LoopBack Schema for Model `Test`:
loopback:contrib:jsonschema-registry JSON Schema for Model `Test`: