Comparing version 3.2.1 to 3.2.2
@@ -0,2 +1,5 @@ | ||
### v3.2.2 | ||
* Documentation fixes. | ||
### v3.2.1 | ||
@@ -3,0 +6,0 @@ |
{ | ||
"name": "enjoi", | ||
"version": "3.2.1", | ||
"version": "3.2.2", | ||
"license": "Apache 2.0", | ||
@@ -5,0 +5,0 @@ "description": "Converts json-schema to Joi schema for validation.", |
@@ -28,19 +28,20 @@ [![Build Status](https://travis-ci.org/tlivings/enjoi.png)](https://travis-ci.org/tlivings/enjoi) [![NPM version](https://badge.fury.io/js/enjoi.png)](http://badge.fury.io/js/enjoi) | ||
```javascript | ||
var Joi = require('joi'); | ||
var Enjoi = require('enjoi'); | ||
const Joi = require('joi'); | ||
const Enjoi = require('enjoi'); | ||
var schema = Enjoi({ | ||
'title': 'Example Schema', | ||
'type': 'object', | ||
'properties': { | ||
'firstName': { | ||
'type': 'string' | ||
const schema = Enjoi({ | ||
type: 'object', | ||
properties: { | ||
firstName: { | ||
description: 'First name.', | ||
type: 'string' | ||
}, | ||
'lastName': { | ||
'type': 'string' | ||
lastName: { | ||
description: 'Last name.', | ||
type: 'string' | ||
}, | ||
'age': { | ||
'description': 'Age in years', | ||
'type': 'integer', | ||
'minimum': 0 | ||
age: { | ||
description: 'Age in years', | ||
type: 'integer', | ||
minimum: 1 | ||
} | ||
@@ -66,11 +67,18 @@ }, | ||
Sub-schemas can be provided through the `subSchemas` option for `$ref` values to lookup against. | ||
Example: | ||
```javascript | ||
var schema = Enjoi({ | ||
'title': 'Example Schema', | ||
'type': 'object', | ||
'properties': { | ||
'A': { | ||
'$ref': 'sub#/something' | ||
const schema = Enjoi({ | ||
type: 'object', | ||
properties: { | ||
a: { | ||
$ref: '#/b' // # is root schema | ||
}, | ||
b: { | ||
type: 'string' | ||
}, | ||
c: { | ||
$ref: '#sub/d' // #sub is 'sub' under subSchemas. | ||
} | ||
@@ -80,4 +88,4 @@ } | ||
subSchemas: { | ||
'sub': { | ||
'something': { | ||
sub: { | ||
d: { | ||
'type': 'string' | ||
@@ -92,25 +100,32 @@ } | ||
Custom types can be provided through the `types` option. | ||
```javascript | ||
var schema = Enjoi({ | ||
type: 'file' | ||
const schema = Enjoi({ | ||
type: 'thing' | ||
}, { | ||
types: { | ||
file: Enjoi({ | ||
type: 'object', | ||
properties: { | ||
file: { | ||
type: 'string' | ||
}, | ||
consumes: { | ||
type: 'string', | ||
pattern: /multipart\/form-data/ | ||
} | ||
} | ||
}) | ||
thing: Joi.any() | ||
} | ||
}); | ||
``` | ||
schema.validate({file: 'data', consumes: 'multipart/form-data'}, function (error, value) { | ||
error && console.log(error); | ||
### Refine Type | ||
You can use the refine type function to help refine types based on `type` and `format`. This will allow transforming a type for lookup against the custom `types`. | ||
```javascript | ||
const schema = Enjoi({ | ||
type: 'string', | ||
format: 'email' | ||
}, { | ||
types: { | ||
email: Joi.string().email() | ||
}, | ||
refineType(type, format) { | ||
if (type === 'string' && format === 'email') { | ||
return 'email'; | ||
} | ||
} | ||
}); | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
128
0
18052
7