From ae0c8bc232e70178307376abe74d8dc5d05912f2 Mon Sep 17 00:00:00 2001
From: Alvaro Cabrera <pateketrueke@gmail.com>
Date: Fri, 25 Nov 2016 02:41:36 -0600
Subject: [PATCH] Apply requiredOnly option; fixes #81

---
 lib/class/OptionRegistry.js | Bin 1020 -> 1064 bytes
 lib/types/object.js         | Bin 3777 -> 4063 bytes
 ts/class/OptionRegistry.ts  |   1 +
 ts/types/object.ts          |  10 ++++++++++
 4 files changed, 11 insertions(+)

diff --git a/lib/class/OptionRegistry.js b/lib/class/OptionRegistry.js
index 5736c386c65fbfe2794bad7d5815cc0b3fc2291d..3ab371a173438a9d4eef963c21b773d5fccdd83c 100644
GIT binary patch
delta 25
gcmeyvzJg=Jc_yBs)WXutqSO@syqwC->zRBR0f}!3_5c6?

delta 12
TcmZ3%@rQlGd8W<3nRFQeC0qp)

diff --git a/lib/types/object.js b/lib/types/object.js
index c64b062589d7f6bf2bcc99cf09ef63bd23074448..07726e069d5aad679c375a32a1566c59d691ee64 100644
GIT binary patch
delta 84
zcmX>odtZKo6{~t?nu11tK}lwQo`!l+YGG++QEG~RUQVUDrh=`ltwKprX{x3|HP_@s
pHtEUX?240@va3(#<>i`uiCtlGDG&eTTweCc;e1}34Ok~~0syRn8kGP5

delta 12
TcmcaFe^7RV73<~*wsuYcA)o|p

diff --git a/ts/class/OptionRegistry.ts b/ts/class/OptionRegistry.ts
index 3af4e746..e1dd9f87 100644
--- a/ts/class/OptionRegistry.ts
+++ b/ts/class/OptionRegistry.ts
@@ -12,6 +12,7 @@ class OptionRegistry extends Registry<Option> {
     this.data['failOnInvalidTypes'] = true;
     this.data['defaultInvalidTypeProduct'] = null;
     this.data['useDefaultValue'] = false;
+    this.data['requiredOnly'] = false;
     this.data['maxItems'] = null;
     this.data['maxLength'] = null;
     this.data['defaultMinItems'] = 0;
diff --git a/ts/types/object.ts b/ts/types/object.ts
index 26747d59..ffac5507 100644
--- a/ts/types/object.ts
+++ b/ts/types/object.ts
@@ -35,6 +35,16 @@ var objectType: FTypeGenerator = function objectType(value: IObjectSchema, path,
         throw new ParseError('missing properties for:\n' + JSON.stringify(value, null, '  '), path);
     }
 
+    if (option('requiredOnly') === true) {
+        requiredProperties.forEach(function(key) {
+            if (properties[key]) {
+                props[key] = properties[key];
+            }
+        });
+
+        return traverseCallback(props, path.concat(['properties']), resolve);
+    }
+
     var min = Math.max(value.minProperties || 0, requiredProperties.length);
     var max = Math.max(value.maxProperties || random.number(min, min + 5));
 
-- 
GitLab