mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
8 years ago
|
'use strict';
|
||
|
|
||
|
const Joi = require('joi');
|
||
|
|
||
|
// Schema Configuration
|
||
|
// required:
|
||
|
// * api.version (string)
|
||
|
// * api.indexName (string)
|
||
|
// * api.host (string)
|
||
|
// * esclient (object - positive integer requestTimeout)
|
||
|
//
|
||
|
// optional:
|
||
|
// * api.accessLog (string)
|
||
|
// * api.relativeScores (boolean)
|
||
|
// * api.legacyUrl (string)
|
||
|
// * api.localization (flipNumberAndStreetCountries is array of 3 character strings)
|
||
|
const schema = Joi.object().keys({
|
||
|
api: Joi.object().keys({
|
||
|
version: Joi.string(),
|
||
|
indexName: Joi.string(),
|
||
|
host: Joi.string(),
|
||
|
legacyUrl: Joi.string(),
|
||
|
accessLog: Joi.string(),
|
||
|
relativeScores: Joi.boolean(),
|
||
|
localization: Joi.object().keys({
|
||
|
flipNumberAndStreetCountries: Joi.array().items(Joi.string().regex(/^[A-Z]{3}$/))
|
||
|
}).unknown(false)
|
||
|
|
||
|
}).requiredKeys('version', 'indexName', 'host').unknown(true),
|
||
|
esclient: Joi.object().keys({
|
||
|
requestTimeout: Joi.number().integer().min(0)
|
||
|
}).unknown(true)
|
||
|
}).requiredKeys('api', 'esclient').unknown(true);
|
||
|
|
||
|
module.exports = {
|
||
|
validate: function validate(config) {
|
||
|
Joi.validate(config, schema, (err) => {
|
||
|
if (err) {
|
||
|
throw new Error(err.details[0].message);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
};
|