Skip to content

Commit

Permalink
fix for anyOf wrapped in allOf with overlapping required keys
Browse files Browse the repository at this point in the history
  • Loading branch information
deweller committed Jan 11, 2024
1 parent a3ed934 commit 5ca9fb5
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/core/buildResolveSchema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
42 changes: 42 additions & 0 deletions tests/schema/core/issues/all-of-one-of-all-of-nested-overlap.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]

0 comments on commit 5ca9fb5

Please sign in to comment.