Repository: json-schema-faker/json-schema-faker
Pull request #795 (2024-01-11 20:32:37)

dev sync


Patch:
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index ce95c94..44951ce 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -30,3 +30,5 @@ jobs:
           tags: true
       - name: Publish version
         run: npm publish
+      - name: Update website
+        run: make clean web deploy
diff --git a/Makefile b/Makefile
index ea2d000..4acacce 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ endif
 .EXPORT_ALL_VARIABLES:
 
 # targets
-.PHONY: ? deps purge all clean deploy
+.PHONY: ? deps purge web clean deploy
 
 # utils
 define iif
@@ -53,7 +53,7 @@ build: deps ## Build scripts for dist
 watch: deps ## Build scripts for dist
 	@npm run build -- -xweb --watch
 
-all: deps ## Build artifact for production envs
+web: deps ## Build artifact for production envs
 	@(git worktree remove $(src) --force > /dev/null 2>&1) || true
 	@git worktree add $(src) $(target)
 	@cd $(src) && rm -rf *
diff --git a/package.json b/package.json
index 2786b21..8f09cd9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "json-schema-faker",
-  "version": "0.5.4",
+  "version": "0.5.3",
   "description": "JSON-Schema + fake data generators",
   "homepage": "http://json-schema-faker.js.org",
   "types": "index.d.ts",
@@ -39,7 +39,7 @@
     "_graphviz": "madge src --dot > structure.gv",
     "mortero": "mortero -Ddist -spublic -X{_base,lib} -ecss.less",
     "watch": "npm run mortero -- --platform browser -dw",
-    "build": "NODE_ENV=production npm run mortero -- -fS --no-minify",
+    "build": "NODE_ENV=production npm run mortero -- -fS --no-minify --platform browser",
     "pretest": "npm run lint && npm run build -- -ymain -yshared",
     "copy:vendor": "concat -o dist/vendor.js node_modules/json-schema-ref-parser/dist/ref-parser.min.js node_modules/jsonpath-plus/dist/index-browser-umd.min.cjs",
     "copy:bundle": "concat -o dist/bundle.js dist/vendor.js dist/main.iife.js",
@@ -133,7 +133,7 @@
     "sinon": "^11.1.1",
     "sinon-chai": "^3.7.0",
     "smoo": "^0.0.14",
-    "svelte": "^3.38.2",
+    "svelte": "^3.59.2",
     "testcafe": "^3.4.0",
     "testdouble": "^3.16.6",
     "tv4": "^1.3.0",
diff --git a/src/lib/core/buildResolveSchema.mjs b/src/lib/core/buildResolveSchema.mjs
index b3f66e2..45c1c8c 100644
--- a/src/lib/core/buildResolveSchema.mjs
+++ b/src/lib/core/buildResolveSchema.mjs
@@ -120,6 +120,11 @@ const buildResolveSchema = ({
           mix.forEach(omit => {
             if (omit.required && omit !== fixed) {
               omit.required.forEach(key => {
+                // if the picked schema also includes the required key, do not delete it
+                if (fixed.required && fixed.required.includes(key)) {
+                  return;
+                }
+
                 const includesKey = copy.required && copy.required.includes(key);
                 if (copy.properties && !includesKey) {
                   delete copy.properties[key];


Test patch:
diff --git a/tests/pending/issue-658.json b/tests/pending/issue-658.json
new file mode 100644
index 0000000..fa9dfa1
--- /dev/null
+++ b/tests/pending/issue-658.json
@@ -0,0 +1,68 @@
+{
+  "$ref": "#/definitions/resultInfoType",
+  "$schema": "http://json-schema.org/draft-07/schema#",
+  "definitions": {
+    "nameInfoType": {
+      "additionalProperties": false,
+      "properties": {
+        "name": {
+          "type": "string"
+        }
+      },
+      "required": [
+        "name"
+      ],
+      "type": "object"
+    },
+    "dataInfoType": {
+      "additionalProperties": false,
+      "properties": {
+        "requiredString": {
+          "type": "string"
+        },
+        "requiredNameInfoType": {
+          "$ref": "#/definitions/nameInfoType"
+        }
+      },
+      "required": [
+        "requiredString",
+        "requiredNameInfoType"
+      ],
+      "type": "object"
+    },
+    "surveyInfoType": {
+      "additionalProperties": false,
+      "properties": {
+        "data": {
+          "$ref": "#/definitions/dataInfoType"
+        }
+      },
+      "required": [
+        "data"
+      ],
+      "type": "object"
+    },
+    "resultInfoType": {
+      "additionalProperties": false,
+      "properties": {
+        "nameInfoType": {
+          "$ref": "#/definitions/nameInfoType"
+        },
+        "surveyInfoType": {
+          "$ref": "#/definitions/surveyInfoType"
+        }
+      },
+      "type": "object"
+    },
+    "stepInfoType": {
+      "additionalProperties": false,
+      "properties": {
+        "result": {
+          "$ref": "#/definitions/resultInfoType"
+        }
+      },
+      "required": [],
+      "type": "object"
+    }
+  }
+}
diff --git a/tests/pending/issue-740.json b/tests/pending/issue-740.json
new file mode 100644
index 0000000..ef8e901
--- /dev/null
+++ b/tests/pending/issue-740.json
@@ -0,0 +1,46 @@
+{
+    "$schema": "http://json-schema.org/draft-07/schema#",
+    "$ref": "#/definitions/Test",
+    "definitions": {
+        "Test": {
+            "type": "object",
+            "properties": {
+                "items": {
+                    "type": "array",
+                    "items": {
+                        "type": "object",
+                        "properties": {
+                            "value": {
+                                "type": "string"
+                            }
+                        },
+                        "required": [
+                            "value"
+                        ],
+                        "additionalProperties": false
+                    }
+                },
+                "itemsById": {
+                    "type": "object",
+                    "additionalProperties": {
+                        "type": "object",
+                        "properties": {
+                            "value": {
+                                "type": "string"
+                            }
+                        },
+                        "required": [
+                            "value"
+                        ],
+                        "additionalProperties": false
+                    }
+                }
+            },
+            "required": [
+                "items",
+                "itemsById"
+            ],
+            "additionalProperties": false
+        }
+    }
+}
diff --git a/tests/pending/issue-742.json b/tests/pending/issue-742.json
new file mode 100644
index 0000000..ed57023
--- /dev/null
+++ b/tests/pending/issue-742.json
@@ -0,0 +1,19 @@
+{
+  "type": "array",
+  "minItems": 5,
+  "maxItems": 5,
+  "items": {
+    "type": "object",
+    "properties": {
+      "id": {
+        "type": "integer",
+        "minimum": 1,
+        "autoIncrement": true,
+        "initialOffset": 1
+      }
+    },
+    "required": [
+      "id"
+    ]
+  }
+}
diff --git a/tests/pending/issue-749.json b/tests/pending/issue-749.json
new file mode 100644
index 0000000..67a0188
--- /dev/null
+++ b/tests/pending/issue-749.json
@@ -0,0 +1,10 @@
+{
+  "properties": {
+    "fields": {
+      "type": "object",
+      "additionalProperties": {
+        "type": "string"
+      }
+    }
+  }
+}
diff --git a/tests/pending/issue-772.json b/tests/pending/issue-772.json
new file mode 100644
index 0000000..64713e2
--- /dev/null
+++ b/tests/pending/issue-772.json
@@ -0,0 +1,52 @@
+{
+  "allOf": [
+    {
+      "anyOf": [
+        {
+          "type": "object",
+          "properties": {
+            "a": {
+              "type": "string"
+            },
+            "b": {
+              "type": "string"
+            }
+          },
+          "required": [
+            "a",
+            "b"
+          ],
+          "additionalProperties": false
+        },
+        {
+          "type": "object",
+          "properties": {
+            "c": {
+              "type": "string"
+            },
+            "d": {
+              "type": "string"
+            }
+          },
+          "required": [
+            "c",
+            "d"
+          ],
+          "additionalProperties": false
+        }
+      ]
+    },
+    {
+      "type": "object",
+      "properties": {
+        "a": {
+          "const": "azer"
+        }
+      },
+      "required": [
+        "a"
+      ],
+      "additionalProperties": true
+    }
+  ]
+}
diff --git a/tests/pending/issue-775.json b/tests/pending/issue-775.json
new file mode 100644
index 0000000..dfd24a9
--- /dev/null
+++ b/tests/pending/issue-775.json
@@ -0,0 +1,41 @@
+{
+  "$id": "https://example.com/schemas/customer",
+  "type": "object",
+  "properties": {
+    "first_name": {
+      "$ref": "#/$defs/name"
+    },
+    "last_name": {
+      "$ref": "#/$defs/name"
+    },
+    "test": {
+      "type": "object",
+      "properties": {
+        "test2": {
+          "$ref": "#/$defs/name"
+        }
+      },
+      "required": [
+        "test2"
+      ]
+    }
+  },
+  "required": [
+    "first_name",
+    "last_name",
+    "test"
+  ],
+  "$defs": {
+    "name": {
+      "type": "object",
+      "properties": {
+        "kek": {
+          "type": "string"
+        }
+      },
+      "required": [
+        "kek"
+      ]
+    }
+  }
+}
diff --git a/tests/pending/issue-783.json b/tests/pending/issue-783.json
new file mode 100644
index 0000000..3d3b4cd
--- /dev/null
+++ b/tests/pending/issue-783.json
@@ -0,0 +1,71 @@
+{
+  "$id": "BuiltParameters",
+  "title": "BuiltParameters",
+  "description": "The schema of BuiltParameters",
+  "type": "object",
+  "properties": {
+    "primitiveId": {
+      "type": "string"
+    },
+    "parameterId": {
+      "type": "string"
+    },
+    "parameterName": {
+      "type": "string"
+    },
+    "parameterType": {
+      "type": "string",
+      "enum": [
+        "GI",
+        "GI2",
+        "a"
+      ]
+    },
+    "parameterProperties": {
+      "type": "object"
+    }
+  },
+  "additionalProperties": false,
+  "required": [
+    "primitiveId",
+    "parameterId",
+    "parameterName",
+    "parameterType"
+  ],
+  "dependencies": {
+    "parameterType": {
+      "oneOf": [
+        {
+          "properties": {
+            "parameterType": {
+              "enum": [
+                "GI",
+                "GI2"
+              ]
+            }
+          },
+          "not": {
+            "required": [
+              "parameterProperties"
+            ]
+          }
+        },
+        {
+          "not": {
+            "properties": {
+              "parameterType": {
+                "enum": [
+                  "GI",
+                  "GI2"
+                ]
+              }
+            }
+          },
+          "required": [
+            "parameterProperties"
+          ]
+        }
+      ]
+    }
+  }
+}
diff --git a/tests/schema/core/issues/all-of-one-of-all-of-nested-overlap-with-additional-props.json b/tests/schema/core/issues/all-of-one-of-all-of-nested-overlap-with-additional-props.json
new file mode 100644
index 0000000..e9ad3a9
--- /dev/null
+++ b/tests/schema/core/issues/all-of-one-of-all-of-nested-overlap-with-additional-props.json
@@ -0,0 +1,41 @@
+[
+  {
+    "description": "allOf and oneOf nested with overlapping conditions",
+    "schemas": [{
+      "$schema": "http://json-schema.org/draft-04/schema#",
+      "type": "object",
+      "properties": {
+        "date_of_birth": {
+          "type": "string",
+          "minimum": 10,
+          "maximum": 10
+        },
+        "age_group": {
+          "type": "string",
+          "minLength": 5,
+          "maxLength": 5
+        }
+      },
+
+      "allOf": [{
+        "anyOf": [{
+          "required": [
+            "age_group"
+          ]
+        }, {
+          "required": [
+            "age_group",
+            "date_of_birth"
+          ]
+        }]
+      }]
+    }],
+    "tests": [
+      {
+        "description": "should combine recursively",
+        "schema": "schemas.0",
+        "valid": true
+      }
+    ]
+  }
+]
diff --git a/tests/schema/core/issues/all-of-one-of-all-of-nested-overlap.json b/tests/schema/core/issues/all-of-one-of-all-of-nested-overlap.json
new file mode 100644
index 0000000..c21ae48
--- /dev/null
+++ b/tests/schema/core/issues/all-of-one-of-all-of-nested-overlap.json
@@ -0,0 +1,42 @@
+[
+  {
+    "description": "allOf and oneOf nested with overlapping conditions",
+    "schemas": [{
+      "$schema": "http://json-schema.org/draft-04/schema#",
+      "type": "object",
+      "additionalProperties": false,
+      "properties": {
+        "date_of_birth": {
+          "type": "string",
+          "minimum": 10,
+          "maximum": 10
+        },
+        "age_group": {
+          "type": "string",
+          "minLength": 5,
+          "maxLength": 5
+        }
+      },
+
+      "allOf": [{
+        "anyOf": [{
+          "required": [
+            "age_group"
+          ]
+        }, {
+          "required": [
+            "age_group",
+            "date_of_birth"
+          ]
+        }]
+      }]
+    }],
+    "tests": [
+      {
+        "description": "should combine recursively",
+        "schema": "schemas.0",
+        "valid": true
+      }
+    ]
+  }
+]