From b87e8b019f7dc69ba3ba4d94634d2b834c6cdef9 Mon Sep 17 00:00:00 2001 From: 3went2 Date: Tue, 30 Jan 2018 18:41:04 +0800 Subject: [PATCH] update README.md --- README.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/README.md b/README.md index c3316a4..93d4067 100755 --- a/README.md +++ b/README.md @@ -5,6 +5,20 @@ [WIP] JSON Schema Draft 6 plugin for [Skeeler](https://github.com/Cap32/skeeler) +## Table of Contents + + + +* [Simple Example](#simple-example) + * [Equals to JSON Schema Draft 6](#equals-to-json-schema-draft-6) +* [Options](#options) +* [Related projects](#related-projects) +* [License](#license) + + + + + ## Simple Example ```js @@ -29,10 +43,13 @@ const mySkeeler = new Skeeler({ export default mySkeeler.export('json'); ``` + + ### Equals to JSON Schema Draft 6 ```js export default { + type: 'object', properties: { foo: { type: 'string', @@ -70,10 +87,68 @@ export default { }; ``` + + +## Options + +By default, all the schema definitions will be compiled to `properties` in JSON schema, and the root type is `object`. + +#### `other` option + +If you want to pass some attributes outside `properties`, you may use `other` option. + +###### Example + +```js +const skeeler = new Skeeler({}); +const options = { other: { title: 'awesome' } }; +skeeler.export('json', options); + +/** + * output + * + * { type: 'object', properties: {}, title: 'awesome' } + */ +``` + +#### `strict` option + +If you want to writing in native JSON Schema way, you may use `strict` option. + +###### Example + +```js +const skeeler = new Skeeler({ + properties: { + foo: types.string, + bar: types.number, + }, + required(['foo', 'bar']), +}); +const options = { strict: true }; +skeeler.export('json', options); + +/** + * output + * + * { + * properties: { + * foo: { type: 'string' }, + * bar: { type: 'number' }, + * }, + * required: ['foo', 'bar'], + * } + */ +``` + + + ## Related projects * [Skeeler](https://github.com/Cap32/skeeler) + + ## License MIT