From 3e33ec423831ec337d474bac52ce84988b045a71 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alvaro=20Cabrera=20Dur=C3=A1n?= <pateketrueke@gmail.com>
Date: Wed, 9 Oct 2019 23:07:28 -0500
Subject: [PATCH] Handle oneOf.required props; fixes #529

---
 src/core/run.js                         | 6 +++++-
 tests/schema/core/issues/issue-329.json | 1 +
 tests/schema/core/issues/issue-529.json | 7 +++----
 tests/schema/main.spec.js               | 2 ++
 tests/schema/validator.js               | 2 +-
 5 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/core/run.js b/src/core/run.js
index 082ccfcf..68244643 100644
--- a/src/core/run.js
+++ b/src/core/run.js
@@ -203,13 +203,17 @@ function run(refs, schema, container) {
           thunk() {
             const copy = utils.omitProps(sub, ['anyOf', 'oneOf']);
             const fixed = random.pick(mix);
+
             utils.merge(copy, fixed);
 
             if (sub.oneOf && copy.properties) {
               mix.forEach(omit => {
                 if (omit !== fixed && omit.required) {
                   omit.required.forEach(key => {
-                    delete copy.properties[key];
+                    // remove additional properties from merged schemas
+                    if (!copy.required.includes(key)) {
+                      delete copy.properties[key];
+                    }
                   });
                 }
               });
diff --git a/tests/schema/core/issues/issue-329.json b/tests/schema/core/issues/issue-329.json
index a6238a57..af9c521c 100644
--- a/tests/schema/core/issues/issue-329.json
+++ b/tests/schema/core/issues/issue-329.json
@@ -5,6 +5,7 @@
       {
         "description": "should resolve the schema (without $refs)",
         "timeout": 30000,
+        "online": true,
         "schema": {
           "$schema": "http://redfish.dmtf.org/schemas/v1/redfish-schema.v1_2_0.json",
           "title": "#AccountService.v1_2_1.AccountService",
diff --git a/tests/schema/core/issues/issue-529.json b/tests/schema/core/issues/issue-529.json
index 3d4ab191..53fdff19 100644
--- a/tests/schema/core/issues/issue-529.json
+++ b/tests/schema/core/issues/issue-529.json
@@ -1,9 +1,10 @@
 {
-  "description": "...",
+  "description": "repeated properties between oneOf sub schemas",
   "tests": [
     {
-      "description": "should ...",
+      "description": "should not skip required properties",
       "schema": {
+        "$schema": "http://json-schema.org/draft-06/schema#",
         "type": "object",
         "required": [
           "filters"
@@ -23,7 +24,6 @@
             }
           }
         },
-        "$schema": "http://json-schema.org/draft-06/schema#",
         "definitions": {
           "FilterAgc": {
             "type": "object",
@@ -77,7 +77,6 @@
           }
         }
       },
-      "skip": true,
       "valid": true
     }
   ]
diff --git a/tests/schema/main.spec.js b/tests/schema/main.spec.js
index f1415467..1a70d517 100644
--- a/tests/schema/main.spec.js
+++ b/tests/schema/main.spec.js
@@ -17,6 +17,8 @@ function seed() {
 (only.length ? only : all).forEach(suite => {
   describe(`${suite.description} (${suite.file.replace(`${process.cwd()}/`, '')})`, () => {
     suite.tests.forEach(test => {
+      if (!process.env.CI && test.online) return;
+
       it(test.description, () => {
         jsf.option(jsf.option.getDefaults());
 
diff --git a/tests/schema/validator.js b/tests/schema/validator.js
index abbd2946..fb3bab99 100644
--- a/tests/schema/validator.js
+++ b/tests/schema/validator.js
@@ -72,7 +72,7 @@ export function checkSchema(sample, schema, refs) {
 
   // z-schema
   const validator = new ZSchema({
-    ignoreUnresolvableReferences: false,
+    ignoreUnresolvableReferences: true,
   });
 
   Object.keys(fixed).forEach(k => {
-- 
GitLab