https://github.com/goliatone/waterline-to-json-schema
Convert Waterline model definition to JSON schema
https://github.com/goliatone/waterline-to-json-schema
Last synced: 3 months ago
JSON representation
Convert Waterline model definition to JSON schema
- Host: GitHub
- URL: https://github.com/goliatone/waterline-to-json-schema
- Owner: goliatone
- Created: 2017-02-21T02:14:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-03-17T03:48:56.000Z (over 3 years ago)
- Last Synced: 2024-04-24T21:21:50.656Z (about 1 year ago)
- Language: JavaScript
- Size: 71.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## WaterlineJS to JSON schema converter
Convert Waterline model definitions to [JSON schema][js]. You can then use this generated JSON with tools such as [core.io-cli-view-generator][core.io-cli-view-generator].
### CLI
This library provides a cli utility, `waterline-schema`, with two commands:* `collect `
* `generate````
waterline-schema 0.2.1 - WaterlineJS to JSON schema generatorUSAGE
waterline-schema [options]
COMMANDS
collect [source] [output] Collect metadata from waterline models and generates a JSON schema file
generate [source] [output] Generate schema from model data
help Display help for a specific commandGLOBAL OPTIONS
-h, --help Display help
-V, --version Display version
--no-color Disable colors
--quiet Quiet mode - only displays warn and error messages
-v, --verbose Verbose mode - will also output debug messages
```#### Collect
Collect will go over all files in a given directory and generate a JSON file with all the model definitions. Note that for now, the command relies on the models exposing an `schema` object.
```js
const schema = {
identity: 'user',
attributes: {
id: {
type: 'text',
primaryKey: true
},
name: {
type: 'string',
label: 'Name'
}
}
};const Model = Waterline.Collection.extend(schema);
module.exports = Model;
module.exports.schema = schema;
```#### Generate
The generate command will take a JSON file with definitions of Waterline models, turn it into a valid JSON schema object, and save it to a file.
### TODO
- [ ] Do swagger output from schema?
- [ ] Remove `"required": []` if empty.
- [ ] Identify primary key
- [ ] if not pk show warning.
- [ ] generate report with:
- [ ] errors
- [ ] warnings
- [ ] Filter out fields or mark them as private?
- password field, we don't want to show in GUI but want to have in Swagger
- [ ] _inputs_
- [ ] form:
- [ ] ensure we have a default for items or provide one[js]:http://json-schema.org/
[core.io-cli-view-generator]:https://github.com/goliatone/core.io-cli-view-generator