Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
fix(compiler): fix validator expression for type path
Browse files Browse the repository at this point in the history
Use the correct type (`path`) and a key existence check.
  • Loading branch information
pheekus committed Sep 4, 2019
1 parent 2e4365e commit cc54553
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/compile/compile-type/compile-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import cel from '../cel';

export default function(schema: JSONSchema7, ref: string): string {
const map = cel.calc(ref, 'is', 'map');
const withPath = cel.calc(cel.ref(ref, 'path'), 'is', 'string');
const hasOnly = cel.call(cel.ref(cel.call(cel.ref(ref, 'keys')), 'hasOnly'), cel.val(['path']));
const withPath = cel.calc(cel.ref(ref, 'path'), 'is', 'path')

return cel.calc(map, '&&', withPath);
return cel.calc(map, '&&', cel.calc(hasOnly, '&&', withPath));
}
2 changes: 1 addition & 1 deletion test/compile-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('type compilers', () => {
assert.equal(compilePath({
definitions: { Path: {}},
$ref: '#/definitions/Path'
}, 'ref'), '((ref is map)&&(ref.path is string))');
}, 'ref'), `((ref is map)&&(ref.keys().hasOnly(["path"])&&(ref.path is path)))`);
});
});

Expand Down

0 comments on commit cc54553

Please sign in to comment.