Skip to content

Commit

Permalink
fixup! Add support for context
Browse files Browse the repository at this point in the history
  • Loading branch information
o-rumiantsev committed Jun 26, 2019
1 parent 2923984 commit 73fd562
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/metaschema-config/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
20 changes: 6 additions & 14 deletions lib/metaschema-config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit 73fd562

Please sign in to comment.