@wmfs/j2119
Advanced tools
Comparing version
@@ -111,3 +111,3 @@ const oxford = require('./oxford') | ||
// object field without a defined child role | ||
if (fieldName && !childType && type === TYPES.object) { | ||
if (fieldName && !childType && !type && (modal !== 'MUST NOT')) { | ||
this.roles.addGrandchildRole(role, fieldName, fieldName) | ||
@@ -114,0 +114,0 @@ this.allowedFields.setAny(fieldName) |
@@ -143,3 +143,3 @@ const DateTime = require('luxon').DateTime | ||
case TYPES.object: | ||
if (typeof value !== 'object' && !Array.isArray(value)) report('an Object') | ||
if (typeof value !== 'object' || Array.isArray(value)) report('an Object') | ||
break | ||
@@ -146,0 +146,0 @@ case TYPES.array: |
@@ -26,3 +26,3 @@ // Tried use jsonpath to do this, but it couldn't distinguish between | ||
const step = '((' + dotStep + ')|(' + bracketStep + ')|(' + index + '))' + '(' + index + ')?' | ||
const path = '^\\$' + '(' + step + ')+$' | ||
const path = '^\\$' + '(' + step + ')*$' | ||
@@ -32,3 +32,3 @@ const rpDotStep = DOT_SEPARATOR + nameRe | ||
const rpStep = '((' + rpDotStep + ')|(' + bracketStep + '))' + '(' + rpNumIndex + ')?' | ||
const referencePath = '^\\$' + '(' + rpStep + ')+$' | ||
const referencePath = '^\\$' + '(' + rpStep + ')*$' | ||
@@ -35,0 +35,0 @@ const pathRe = new XRegExp(path) |
{ | ||
"name": "@wmfs/j2119", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "A general-purpose validator generator that uses RFC2119-style assertions as input.", | ||
@@ -5,0 +5,0 @@ "author": "West Midlands Fire Service", |
# j2119 | ||
[](https://tymly.io/) [](https://www.npmjs.com/package/@wmfs/j2119) [](https://travis-ci.org/wmfs/j2119) [](https://codecov.io/gh/wmfs/j2119) [](https://dependabot.com/) [](http://commitizen.github.io/cz-cli/) | ||
[](https://tymly.io/) [](https://www.npmjs.com/package/@wmfs/j2119) [](https://travis-ci.com/wmfs/j2119) [](https://codecov.io/gh/wmfs/j2119) [](https://dependabot.com/) [](http://commitizen.github.io/cz-cli/) | ||
[](https://standardjs.com) [](https://github.com/wmfs/tymly/blob/master/packages/j2112/LICENSE) | ||
@@ -4,0 +4,0 @@ |
@@ -10,2 +10,11 @@ /* eslint-env mocha */ | ||
describe('J2119 JsonPathChecker', () => { | ||
describe('should allow default paths', () => { | ||
it('$ path', () => | ||
expect(jsonPathChecker.isPath('$')).to.be.true() | ||
) | ||
it('$ reference path', () => | ||
expect(jsonPathChecker.isReferencePath('$')).to.be.true() | ||
) | ||
}) | ||
describe('should do simple paths', () => { | ||
@@ -12,0 +21,0 @@ const paths = [ |
@@ -19,3 +19,38 @@ /* eslint-env mocha */ | ||
const STATE_MACHINE_WITH_EXTENSION = { | ||
const WITH_ARRAY_RESULT = { | ||
StartAt: 'No-op', | ||
States: { | ||
'No-op': { | ||
Type: 'Pass', | ||
ResultPath: '$.coords', | ||
Result: [ | ||
'foo', | ||
'bar', | ||
{ | ||
bazz: 123 | ||
} | ||
], | ||
End: true | ||
} | ||
} | ||
} | ||
const WITH_OBJECT_RESULT = { | ||
StartAt: 'No-op', | ||
States: { | ||
'No-op': { | ||
Type: 'Pass', | ||
ResultPath: '$.coords', | ||
Result: { | ||
foo: { | ||
'x-datum': 0.381018, | ||
'y-datum': 622.2269926397355 | ||
} | ||
}, | ||
End: true | ||
} | ||
} | ||
} | ||
const STATE_MACHINE_WITH_RESOURCE_CONFIG_OBJECT = { | ||
StartAt: 'x', | ||
@@ -53,2 +88,37 @@ States: { | ||
const STATE_MACHINE_WITH_RESOURCE_CONFIG_ARRAY = { | ||
StartAt: 'x', | ||
States: { | ||
x: { | ||
Type: 'Task', | ||
Resource: 'module:monkeyPunk', | ||
ResourceConfig: [ | ||
'param', | ||
{ | ||
x: 'X', | ||
y: { | ||
down: { | ||
deep: { | ||
and: { | ||
deeper: { | ||
and: { | ||
deeper: { | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
1, | ||
true | ||
], | ||
End: true | ||
} | ||
}, | ||
namespace: 'Test', | ||
name: 'Extension' | ||
} | ||
const SCHEMA = require.resolve('./fixtures/AWL.j2119') | ||
@@ -65,2 +135,14 @@ const EXTENSION = require.resolve('./fixtures/TymlyExtension.j2119') | ||
it('validate state machine with result object', () => { | ||
const v = validator(SCHEMA) | ||
const p = v.validate(WITH_OBJECT_RESULT) | ||
expect(p.length).to.eql(0) | ||
}) | ||
it('validate state machine with result array', () => { | ||
const v = validator(SCHEMA) | ||
const p = v.validate(WITH_ARRAY_RESULT) | ||
expect(p.length).to.eql(0) | ||
}) | ||
it('fail to validate a text string', () => { | ||
@@ -95,4 +177,7 @@ const v = validator(SCHEMA) | ||
const np = v.validate(STATE_MACHINE_WITH_EXTENSION) | ||
const np = v.validate(STATE_MACHINE_WITH_RESOURCE_CONFIG_OBJECT) | ||
expect(np.length).to.eql(0) | ||
const nnp = v.validate(STATE_MACHINE_WITH_RESOURCE_CONFIG_ARRAY) | ||
expect(nnp.length).to.eql(0) | ||
}) | ||
@@ -99,0 +184,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
137271
1.42%2860
3.14%