Comparing version 1.1.2 to 1.1.4
@@ -5,13 +5,21 @@ const Ajv = require('ajv'); | ||
function AjvOAI(optsIn) { | ||
const opts = Object.assign({ | ||
schemaId: 'id', | ||
format: 'full', | ||
coerceTypes: true, | ||
unknownFormats: 'ignore', | ||
useDefaults: true, | ||
}, optsIn); | ||
function AjvOAI({ metaSchema = 'json-schema-draft-04', ...optsIn } = {}) { | ||
const opts = Object.assign( | ||
{ | ||
schemaId: 'id', | ||
format: 'full', | ||
coerceTypes: true, | ||
unknownFormats: 'ignore', | ||
useDefaults: true, | ||
}, | ||
optsIn, | ||
); | ||
const ajv = new Ajv(opts); | ||
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); | ||
try { | ||
// eslint-disable-next-line import/no-dynamic-require | ||
ajv.addMetaSchema(require(`ajv/lib/refs/${metaSchema}.json`), metaSchema); | ||
} catch (e) { | ||
throw new Error(`Meta schema ${metaSchema} not supported. ${e.message}`); | ||
} | ||
@@ -18,0 +26,0 @@ ajv.addFormat('int32', { type: 'number', validate: validator.int32 }); |
{ | ||
"name": "ajv-oai", | ||
"version": "1.1.2", | ||
"version": "1.1.4", | ||
"description": "OpenAPI's JsonSchema validator, Powered by Ajv", | ||
"main": "lib/ajv-oai.js", | ||
"typings": "lib/ajv-oai.d.ts", | ||
"scripts": { | ||
@@ -21,3 +22,3 @@ "ci": "npm run lint && npm run test", | ||
"dependencies": { | ||
"decimal.js": "^9.0.1" | ||
"decimal.js": "^10.2.0" | ||
}, | ||
@@ -28,2 +29,3 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"ajv": "6.10.2", | ||
"babel-core": "^6.26.0", | ||
@@ -30,0 +32,0 @@ "babel-jest": "^22.1.0", |
[license-img]: http://img.shields.io/badge/license-MIT-green.svg | ||
[license-url]: http://opensource.org/licenses/MIT | ||
[node-image]: https://img.shields.io/badge/node.js-v6.0.0-blue.svg | ||
[node-url]: http://nodejs.org/download/ | ||
[npm-img]: https://img.shields.io/npm/v/ajv-oai.svg | ||
[npm-url]: https://npmjs.org/package/ajv-oai | ||
[travis-img]: https://travis-ci.org/BiteBit/ajv-oai.svg | ||
[travis-url]: https://travis-ci.org/BiteBit/ajv-oai | ||
[coveralls-img]: https://coveralls.io/repos/github/BiteBit/ajv-oai/badge.svg | ||
[coveralls-url]: https://coveralls.io/github/BiteBit/ajv-oai | ||
[downloads-image]: https://img.shields.io/npm/dm/ajv-oai.svg | ||
[downloads-url]: https://npmjs.org/package/ajv-oai | ||
[david-img]: https://img.shields.io/david/BiteBit/ajv-oai.svg | ||
[david-url]: https://david-dm.org/BiteBit/ajv-oai | ||
[router]: https://github.com/BiteBit/koa-oai-router | ||
@@ -39,2 +32,3 @@ | ||
# Installation | ||
``` | ||
@@ -44,3 +38,18 @@ npm install ajv-oai --save | ||
# Usage | ||
With draft 04 by default: | ||
```js | ||
const ajv = new AjvOAI(); | ||
``` | ||
With a custom meta schema from [AJV lib](https://github.com/epoberezkin/ajv/tree/master/lib/refs) | ||
```js | ||
const ajv = new AjvOAI({ metaSchema: 'json-schema-draft-06' }); | ||
``` | ||
# Example | ||
```js | ||
@@ -93,2 +102,2 @@ const ajv = new AjvOAI(); | ||
> true | ||
``` | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9243
11
158
101
9
2
+ Addeddecimal.js@10.4.3(transitive)
- Removeddecimal.js@9.0.1(transitive)
Updateddecimal.js@^10.2.0