From f3a3d1be656c0d536a3507dbf39eb9e83c06a321 Mon Sep 17 00:00:00 2001 From: Alvaro Cabrera <pateketrueke@gmail.com> Date: Tue, 27 Jun 2017 23:56:35 -0500 Subject: [PATCH] Return thunk() within object; fix --- ts/core/run.ts | 14 ++++++++------ ts/core/traverse.ts | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ts/core/run.ts b/ts/core/run.ts index 409003dc..e0af74b4 100644 --- a/ts/core/run.ts +++ b/ts/core/run.ts @@ -53,8 +53,8 @@ function run(refs: any, schema: JsonSchema, container: Container) { var _sub = reduce(subSchema, maxReduceDepth + 1); // call given thunks if present - utils.merge(sub, typeof _sub === 'function' - ? _sub() + utils.merge(sub, typeof _sub.thunk === 'function' + ? _sub.thunk() : _sub); }); } @@ -65,12 +65,14 @@ function run(refs: any, schema: JsonSchema, container: Container) { delete sub.anyOf; delete sub.oneOf; - return () => { - var copy = utils.merge({}, sub); + return { + thunk() { + var copy = utils.merge({}, sub); - utils.merge(copy, random.pick(mix)); + utils.merge(copy, random.pick(mix)); - return copy; + return copy; + }, }; } diff --git a/ts/core/traverse.ts b/ts/core/traverse.ts index 9491d8be..c264847d 100644 --- a/ts/core/traverse.ts +++ b/ts/core/traverse.ts @@ -18,8 +18,8 @@ function traverse(schema: JsonSchema, path: SchemaPath, resolve: Function) { } // thunks can return sub-schemas - if (typeof schema === 'function') { - return traverse(schema(), path, resolve); + if (typeof schema.thunk === 'function') { + return traverse(schema.thunk(), path, resolve); } if (typeof schema.generate === 'function') { -- GitLab