From 866a4a25989b1a9673061ce9ba175fc9677dab6c Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Thu, 23 Sep 2021 09:24:26 -0700 Subject: [PATCH] Add "type" qualifier to ensure that "if" clauses fail properly (#2696) 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. --- schemas/v3.1/schema.json | 7 +++++++ schemas/v3.1/schema.yaml | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/schemas/v3.1/schema.json b/schemas/v3.1/schema.json index 1562450333..a12eaffcc2 100644 --- a/schemas/v3.1/schema.json +++ b/schemas/v3.1/schema.json @@ -316,6 +316,7 @@ }, "path-item-or-reference": { "if": { + "type": "object", "required": [ "$ref" ] @@ -651,6 +652,7 @@ }, "request-body-or-reference": { "if": { + "type": "object", "required": [ "$ref" ] @@ -807,6 +809,7 @@ }, "response-or-reference": { "if": { + "type": "object", "required": [ "$ref" ] @@ -827,6 +830,7 @@ }, "callbacks-or-reference": { "if": { + "type": "object", "required": [ "$ref" ] @@ -905,6 +909,7 @@ }, "link-or-reference": { "if": { + "type": "object", "required": [ "$ref" ] @@ -969,6 +974,7 @@ }, "header-or-reference": { "if": { + "type": "object", "required": [ "$ref" ] @@ -1190,6 +1196,7 @@ }, "security-scheme-or-reference": { "if": { + "type": "object", "required": [ "$ref" ] diff --git a/schemas/v3.1/schema.yaml b/schemas/v3.1/schema.yaml index 9b865a7635..b09dfca3c9 100644 --- a/schemas/v3.1/schema.yaml +++ b/schemas/v3.1/schema.yaml @@ -219,6 +219,7 @@ $defs: path-item-or-reference: if: + type: object required: - $ref then: @@ -416,6 +417,7 @@ $defs: parameter-or-reference: if: + type: object required: - $ref then: @@ -440,6 +442,7 @@ $defs: request-body-or-reference: if: + type: object required: - $ref then: @@ -545,6 +548,7 @@ $defs: response-or-reference: if: + type: object required: - $ref then: @@ -560,6 +564,7 @@ $defs: callbacks-or-reference: if: + type: object required: - $ref then: @@ -583,6 +588,7 @@ $defs: example-or-reference: if: + type: object required: - $ref then: @@ -614,6 +620,7 @@ $defs: link-or-reference: if: + type: object required: - $ref then: @@ -656,6 +663,7 @@ $defs: header-or-reference: if: + type: object required: - $ref then: @@ -801,6 +809,7 @@ $defs: security-scheme-or-reference: if: + type: object required: - $ref then: