Skip to content

Commit

Permalink
Merge pull request #105 from lamchakchan/99-dedup-hoek-reach-invocations
Browse files Browse the repository at this point in the history
Closes #99
  • Loading branch information
WesTyler authored Feb 18, 2017
2 parents a7c1b99 + 0638128 commit ccd1d4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,9 @@ internals.object = function (schema, options) {
Object.keys(schemaDescription.children).forEach((childKey) => {

const childSchema = schemaDescription.children[childKey];
const childIsOptional = Hoek.reach(childSchema, 'flags.presence') === 'optional';
const childIsForbidden = Hoek.reach(childSchema, 'flags.presence') === 'forbidden';
const flagsPresence = Hoek.reach(childSchema, 'flags.presence');
const childIsOptional = flagsPresence === 'optional';
const childIsForbidden = flagsPresence === 'forbidden';
const shouldStrip = Hoek.reach(childSchema, 'flags.strip');

if (shouldStrip || childIsForbidden || (childIsOptional && !(Hoek.reach(options, 'config.includeOptional')))) {
Expand Down
5 changes: 3 additions & 2 deletions lib/joiGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ const generate = function (schemaInput, options) {

childrenKeys.forEach((childKey) => {

const childIsOptional = Hoek.reach(schemaDescription.children[childKey], 'flags.presence') === 'optional';
const childIsForbidden = Hoek.reach(schemaDescription.children[childKey], 'flags.presence') === 'forbidden';
const flagsPresence = Hoek.reach(schemaDescription.children[childKey], 'flags.presence');
const childIsOptional = flagsPresence === 'optional';
const childIsForbidden = flagsPresence === 'forbidden';

if (childIsForbidden || (childIsOptional && !(Hoek.reach(config, 'includeOptional')))) {
return;
Expand Down

0 comments on commit ccd1d4a

Please sign in to comment.