-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cfae84
commit 34f6a54
Showing
8 changed files
with
131 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
const { SchemaValidationError } = require('metaschema').errors; | ||
|
||
const addContext = (context, ms) => { | ||
const errors = []; | ||
const duplicateContext = ms.context.size > 0; | ||
if (duplicateContext) { | ||
errors.push( | ||
new SchemaValidationError('duplicate', context.name, { | ||
type: 'context', | ||
value: context.name, | ||
}) | ||
); | ||
} else { | ||
Object.entries(context.definition).forEach(([name, field]) => | ||
ms.context.set(name, field) | ||
); | ||
} | ||
return errors; | ||
}; | ||
|
||
const postprocessContext = (context, ms) => { | ||
const errors = []; | ||
for (const [fieldName, field] of Object.entries(context.definition)) { | ||
const domain = ms.domains.get(field.domain); | ||
if (domain) { | ||
field.definition = domain; | ||
} else { | ||
errors.push( | ||
new SchemaValidationError( | ||
'unresolved', | ||
`${context.name}.${fieldName}`, | ||
{ type: 'domain', value: field.domain } | ||
) | ||
); | ||
} | ||
} | ||
return errors; | ||
}; | ||
|
||
module.exports = { | ||
addContext, | ||
postprocessContext, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
Nomen: { domain: 'Nomen' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
Nomen: { type: 'string' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
DuplicateNomen: { domain: 'Nomen' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
Nomen: { domain: 'Nomen' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
const metaschema = require('metaschema'); | ||
const metatests = require('metatests'); | ||
|
||
const { options, config } = require('../lib/metaschema-config/config'); | ||
|
||
const { MetaschemaError, SchemaValidationError } = metaschema.errors; | ||
|
||
metatests.test('metaschema context error on duplicated domains', async test => { | ||
await test.rejects( | ||
metaschema.fs.load('test/fixtures/context/duplicate', options, config), | ||
new MetaschemaError([ | ||
new SchemaValidationError('duplicate', 'duplicateDomain', { | ||
type: 'context', | ||
value: 'duplicateDomain', | ||
}), | ||
]) | ||
); | ||
}); | ||
|
||
metatests.test('metaschema context error on unresolved domain', async test => { | ||
await test.rejects( | ||
metaschema.fs.load('test/fixtures/context/unresolved', options, config), | ||
new MetaschemaError([ | ||
new SchemaValidationError('unresolved', 'context.Nomen', { | ||
type: 'domain', | ||
value: 'Nomen', | ||
}), | ||
]) | ||
); | ||
}); |