mirror of https://github.com/Seich/Beau.git
Config files are now validated against the json schema.
This commit is contained in:
parent
5029a09b41
commit
a39f3b5977
|
|
@ -4,6 +4,10 @@ const fs = require('fs')
|
|||
const path = require('path')
|
||||
const dotenv = require('dotenv')
|
||||
const Beau = require('../../src/beau')
|
||||
const Ajv = require('ajv').default
|
||||
|
||||
const ajv = new Ajv()
|
||||
const validate = ajv.compile(require('../../schema.json'))
|
||||
|
||||
class Base extends Command {
|
||||
openConfigFile(configFile) {
|
||||
|
|
@ -13,6 +17,13 @@ class Base extends Command {
|
|||
|
||||
let config
|
||||
yaml.safeLoadAll(fs.readFileSync(configFile, 'utf-8'), (doc) => {
|
||||
const valid = validate(doc)
|
||||
|
||||
if (!valid) {
|
||||
this.log(validate.errors)
|
||||
this.error(`The configuration file is not valid.`)
|
||||
}
|
||||
|
||||
if (typeof config === 'undefined') {
|
||||
config = doc
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ environment:
|
|||
name: David
|
||||
|
||||
GET /anything:
|
||||
alias: anything
|
||||
payload:
|
||||
name: $env.params.name
|
||||
- alias: anything
|
||||
payload:
|
||||
name: $env.params.name
|
||||
- alias: anything2
|
||||
|
||||
GET /cookies/set:
|
||||
alias: set-cookies
|
||||
|
|
|
|||
90
schema.json
90
schema.json
|
|
@ -9,50 +9,54 @@
|
|||
{ "type": "string" },
|
||||
{
|
||||
"type": "object",
|
||||
"required": ["alias"],
|
||||
"properties": {
|
||||
"alias": {
|
||||
"type": "string",
|
||||
"description": "The name of this request."
|
||||
},
|
||||
"headers": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Headers that are part of this request."
|
||||
},
|
||||
"params": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Query String parameters to add to this request."
|
||||
},
|
||||
"payload": {
|
||||
"description": "This request's body. It is converted to json automatically if given an object. It's sent as a string otherwise.",
|
||||
"oneOf": [
|
||||
{ "type": "string" },
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"form": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "This request's body. Sets the content-type to application/x-www-form-urlencoded."
|
||||
},
|
||||
"formdata": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "This request's body. Sets the content-type to multipart/form-data."
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
{ "not": { "required": ["payload", "form"] } },
|
||||
{ "not": { "required": ["payload", "formdata"] } },
|
||||
{ "not": { "required": ["formdata", "form"] } }
|
||||
]
|
||||
"$ref": "#/definitions/requestObject",
|
||||
"required": ["alias"]
|
||||
}
|
||||
]
|
||||
},
|
||||
"requestObject": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alias": {
|
||||
"type": "string",
|
||||
"description": "The name of this request."
|
||||
},
|
||||
"headers": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Headers that are part of this request."
|
||||
},
|
||||
"params": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Query String parameters to add to this request."
|
||||
},
|
||||
"payload": {
|
||||
"description": "This request's body. It is converted to json automatically if given an object. It's sent as a string otherwise.",
|
||||
"oneOf": [
|
||||
{ "type": "string" },
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"form": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "This request's body. Sets the content-type to application/x-www-form-urlencoded."
|
||||
},
|
||||
"formdata": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "This request's body. Sets the content-type to multipart/form-data."
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
{ "not": { "required": ["payload", "form"] } },
|
||||
{ "not": { "required": ["payload", "formdata"] } },
|
||||
{ "not": { "required": ["formdata", "form"] } }
|
||||
]
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
|
|
@ -68,7 +72,7 @@
|
|||
"type": "boolean"
|
||||
},
|
||||
"defaults": {
|
||||
"$ref": "#/definitions/request"
|
||||
"$ref": "#/definitions/requestObject"
|
||||
},
|
||||
"plugins": {
|
||||
"type": "array",
|
||||
|
|
|
|||
Loading…
Reference in New Issue