An open API service indexing awesome lists of open source software.

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

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 generator

USAGE

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 command

GLOBAL 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