Skip to content

Commit

Permalink
Add "type" qualifier to ensure that "if" clauses fail properly (#2696)
Browse files Browse the repository at this point in the history
If the wrong type is used for a particular piece of data, then a bare
"required" will validate as true, causing the "if" clause to be true, which
can lead to confusing errors when the "then" schema then fires, instead of the
error occurring at a higher position in the schema.
  • Loading branch information
karenetheridge authored Sep 23, 2021
1 parent 085be94 commit 866a4a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions schemas/v3.1/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
},
"path-item-or-reference": {
"if": {
"type": "object",
"required": [
"$ref"
]
Expand Down Expand Up @@ -651,6 +652,7 @@
},
"request-body-or-reference": {
"if": {
"type": "object",
"required": [
"$ref"
]
Expand Down Expand Up @@ -807,6 +809,7 @@
},
"response-or-reference": {
"if": {
"type": "object",
"required": [
"$ref"
]
Expand All @@ -827,6 +830,7 @@
},
"callbacks-or-reference": {
"if": {
"type": "object",
"required": [
"$ref"
]
Expand Down Expand Up @@ -905,6 +909,7 @@
},
"link-or-reference": {
"if": {
"type": "object",
"required": [
"$ref"
]
Expand Down Expand Up @@ -969,6 +974,7 @@
},
"header-or-reference": {
"if": {
"type": "object",
"required": [
"$ref"
]
Expand Down Expand Up @@ -1190,6 +1196,7 @@
},
"security-scheme-or-reference": {
"if": {
"type": "object",
"required": [
"$ref"
]
Expand Down
9 changes: 9 additions & 0 deletions schemas/v3.1/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ $defs:

path-item-or-reference:
if:
type: object
required:
- $ref
then:
Expand Down Expand Up @@ -416,6 +417,7 @@ $defs:

parameter-or-reference:
if:
type: object
required:
- $ref
then:
Expand All @@ -440,6 +442,7 @@ $defs:

request-body-or-reference:
if:
type: object
required:
- $ref
then:
Expand Down Expand Up @@ -545,6 +548,7 @@ $defs:

response-or-reference:
if:
type: object
required:
- $ref
then:
Expand All @@ -560,6 +564,7 @@ $defs:

callbacks-or-reference:
if:
type: object
required:
- $ref
then:
Expand All @@ -583,6 +588,7 @@ $defs:

example-or-reference:
if:
type: object
required:
- $ref
then:
Expand Down Expand Up @@ -614,6 +620,7 @@ $defs:

link-or-reference:
if:
type: object
required:
- $ref
then:
Expand Down Expand Up @@ -656,6 +663,7 @@ $defs:

header-or-reference:
if:
type: object
required:
- $ref
then:
Expand Down Expand Up @@ -801,6 +809,7 @@ $defs:

security-scheme-or-reference:
if:
type: object
required:
- $ref
then:
Expand Down

0 comments on commit 866a4a2

Please sign in to comment.