From 73fd5622cae6a349dbdaf7e9e7224e034337912a Mon Sep 17 00:00:00 2001 From: Rumiantsev Oleksii Date: Wed, 26 Jun 2019 09:26:54 +0300 Subject: [PATCH] fixup! Add support for context --- lib/metaschema-config/context.js | 4 ++-- lib/metaschema-config/utils.js | 20 ++++++-------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/metaschema-config/context.js b/lib/metaschema-config/context.js index 706a4f75..c55e975e 100644 --- a/lib/metaschema-config/context.js +++ b/lib/metaschema-config/context.js @@ -4,8 +4,8 @@ const { SchemaValidationError } = require('metaschema').errors; const addContext = (context, ms) => { const errors = []; - const duplicateContext = ms.context.size > 0; - if (duplicateContext) { + const isDuplicated = ms.context.size > 0; + if (isDuplicated) { errors.push( new SchemaValidationError('duplicate', context.name, { type: 'context', diff --git a/lib/metaschema-config/utils.js b/lib/metaschema-config/utils.js index d8eebc96..851217bc 100644 --- a/lib/metaschema-config/utils.js +++ b/lib/metaschema-config/utils.js @@ -6,18 +6,9 @@ const { extractDecorator, } = require('metaschema'); -const propToTypes = { - domain: 'domains', - category: 'category', - context: 'context', -}; - -const dataTypes = Object.keys(propToTypes); -const getDefinition = { - domain: domain => domain, - category: category => category.definition, - context: context => context, -}; +const dataTypes = ['domain', 'category', 'context']; +const getDefinition = (type, schema) => + type === 'category' ? schema.definition : schema; const processFields = (ms, category, fields, source) => { const errors = []; @@ -41,14 +32,15 @@ const processFields = (ms, category, fields, source) => { for (const type of dataTypes) { const value = field[type]; if (value) { - const def = ms[propToTypes[type]].get(value); + const path = type === 'domain' ? 'domains' : type; + const def = ms[path].get(value); if (!def) { const info = { type, value }; errors.push( new SchemaValidationError('unresolved', `${source}.${key}`, info) ); } else { - field.definition = getDefinition[type](def); + field.definition = getDefinition(type, def); } } }