Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/2do2go/ajg
Ajg: Another JSON Schema Generator
https://github.com/2do2go/ajg
Last synced: about 1 month ago
JSON representation
Ajg: Another JSON Schema Generator
- Host: GitHub
- URL: https://github.com/2do2go/ajg
- Owner: 2do2go
- License: mit
- Created: 2017-07-14T13:26:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-15T16:37:20.000Z (over 7 years ago)
- Last Synced: 2024-11-10T19:20:24.681Z (2 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ajg: Another JSON Schema Generator
[![Build Status](https://travis-ci.org/2do2go/ajg.svg?branch=master)](https://travis-ci.org/2do2go/ajg)
Write your JSON-schemas in simple chainable manner. No plain JSON - no pain.
## Quick Start
Install it with NPM or add it to your package.json:
``` bash
$ npm install ajg
```## API
### ajg.schema
Getter property that creates empty JSON-schema.
This schema could be modified by rules in chainable manner:``` js
ajg.schema.required.array.items(ajg.schema.integer)
```Produces:
``` js
{
required: true,
type: 'array',
items: {
type: 'integer'
}
}
```### Rules
Currently Ajg supports only draft-03 rules and fully compatible with [conform.js](https://github.com/okv/conform.js/).
### required
`ajg.schema.required` -> `{ required: true }`
### any
`ajg.schema.any` -> `{ type: 'any' }`
### array
`ajg.schema.array` -> `{ type: 'array' }`
### object
`ajg.schema.object` -> `{ type: 'object' }`
### boolean
`ajg.schema.boolean` -> `{ type: 'boolean' }`
### number
`ajg.schema.number` -> `{ type: 'number' }`
### integer
`ajg.schema.integer` -> `{ type: 'integer' }`
### string
`ajg.schema.string` -> `{ type: 'string' }`
### null
`ajg.schema.null` -> `{ type: 'null' }`
### type(type)
`ajg.schema.type('array')` -> `{ type: 'array' }`
### message(message)
`ajg.schema.message('hello')` -> `{ message: 'hello' }`
### messages(messages)
`ajg.schema.messages({ required: 'hello' })` -> `{ messages: { required: 'hello' } }`
### description(description)
`ajg.schema.description('hello')` -> `{ description: 'hello' }`
### set(key, value)
`ajg.schema.set('a', 'b')` -> `{ a: 'b' }`
### extend(obj1, obj2, ...)
`ajg.schema.extend({a: 'b'})` -> `{ a: 'b' }`
### reset(key1, key2, ...)
`ajg.schema.required.reset('required')` -> `{}`
### reset()
`ajg.schema.required.reset()` -> `{}`
...
## Tests
Clone repository from github, `cd` into cloned dir and install dev dependencies:
``` bash
$ npm install
```Then run tests with command:
``` bash
$ npm test
```## License
[MIT](./LICENSE)