fix(plugin.configure): auto inject default values (#565)

This commit is contained in:
Julien Fontanet 2017-06-02 14:48:15 +02:00 committed by GitHub
parent c49d68e457
commit 8c7d254244
3 changed files with 17 additions and 15 deletions

View File

@ -36,6 +36,7 @@
"dependencies": {
"@marsaud/smb2-promise": "^0.2.1",
"@nraynaud/struct-fu": "^1.0.1",
"ajv": "^5.1.5",
"app-conf": "^0.4.1",
"archiver": "^1.3.0",
"arp-a": "^0.5.1",
@ -70,7 +71,6 @@
"http-request-plus": "^0.1.5",
"http-server-plus": "^0.8.0",
"human-format": "^0.8.0",
"is-my-json-valid": "^2.16.0",
"is-redirect": "^1.0.0",
"js-yaml": "^3.8.4",
"json-rpc-peer": "^0.13.1",

View File

@ -1,4 +1,4 @@
import createJsonSchemaValidator from 'is-my-json-valid'
import Ajv from 'ajv'
import { PluginsMetadata } from '../models/plugin-metadata'
import {
@ -15,6 +15,9 @@ import {
export default class {
constructor (xo) {
this._ajv = new Ajv({
useDefaults: true
})
this._plugins = createRawObject()
this._pluginsMetadata = new PluginsMetadata({
@ -153,15 +156,7 @@ export default class {
throw invalidParameters('plugin not configurable')
}
// See: https://github.com/mafintosh/is-my-json-valid/issues/116
if (configuration == null) {
throw invalidParameters([{
field: 'data',
message: 'is the wrong type'
}])
}
const validate = createJsonSchemaValidator(configurationSchema)
const validate = this._ajv.compile(configurationSchema)
if (!validate(configuration)) {
throw invalidParameters(validate.errors)
}
@ -249,7 +244,7 @@ export default class {
}])
}
const validate = createJsonSchemaValidator(testSchema)
const validate = this._ajv.compile(testSchema)
if (!validate(data)) {
throw invalidParameters(validate.errors)
}

View File

@ -119,6 +119,13 @@ ajv@^4.7.0, ajv@^4.9.1:
co "^4.6.0"
json-stable-stringify "^1.0.1"
ajv@^5.1.5:
version "5.1.5"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.1.5.tgz#8734931b601f00d4feef7c65738d77d1b65d1f68"
dependencies:
co "^4.6.0"
json-stable-stringify "^1.0.1"
align-text@^0.1.1, align-text@^0.1.3:
version "0.1.4"
resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117"
@ -3464,7 +3471,7 @@ is-glob@^3.1.0:
dependencies:
is-extglob "^2.1.0"
is-my-json-valid@^2.10.0, is-my-json-valid@^2.16.0:
is-my-json-valid@^2.10.0:
version "2.16.0"
resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.16.0.tgz#f079dd9bfdae65ee2038aae8acbc86ab109e3693"
dependencies:
@ -4427,11 +4434,11 @@ ltgt@^2.1.2, ltgt@~2.1.1:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ltgt/-/ltgt-2.1.3.tgz#10851a06d9964b971178441c23c9e52698eece34"
make-error@^1, make-error@^1.0.2, make-error@^1.2.1, make-error@^1.2.3:
make-error@^1, make-error@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.2.3.tgz#6c4402df732e0977ac6faf754a5074b3d2b1d19d"
make-error@^1.2.0, make-error@^1.2.2, make-error@^1.3.0:
make-error@^1.0.2, make-error@^1.2.0, make-error@^1.2.1, make-error@^1.2.2, make-error@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.0.tgz#52ad3a339ccf10ce62b4040b708fe707244b8b96"