Skip to content

Commit 2fd49c3

Browse files
fix: do not warn if an operation defines 400 and 422 responses (#38)
In `src/ruleset.ts`, change the `oneOf` schema to `anyOf` Add test cases in `__tests__/owasp-api3-2019-define-error-validation.test.ts`: * test with both `400` and `422` * test with `4XX` Co-authored-by: Nauman <[email protected]>
1 parent 143d735 commit 2fd49c3

File tree

3 files changed

+56
-5637
lines changed

3 files changed

+56
-5637
lines changed

__tests__/owasp-api3-2019-define-error-validation.test.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,49 @@ testRule("owasp:api3:2019-define-error-validation", [
4242
errors: [],
4343
},
4444

45+
{
46+
name: "valid case:400 and 422",
47+
document: {
48+
openapi: "3.1.0",
49+
info: { version: "1.0" },
50+
paths: {
51+
"/": {
52+
get: {
53+
responses: {
54+
"400": {
55+
description: "classic validation fail",
56+
},
57+
"422": {
58+
description: "classic validation fail",
59+
},
60+
},
61+
},
62+
},
63+
},
64+
},
65+
errors: [],
66+
},
67+
68+
{
69+
name: "valid case:4XX",
70+
document: {
71+
openapi: "3.1.0",
72+
info: { version: "1.0" },
73+
paths: {
74+
"/": {
75+
get: {
76+
responses: {
77+
"4XX": {
78+
description: "classic validation fail",
79+
},
80+
},
81+
},
82+
},
83+
},
84+
},
85+
errors: [],
86+
},
87+
4588
{
4689
name: "invalid case",
4790
document: {
@@ -61,7 +104,7 @@ testRule("owasp:api3:2019-define-error-validation", [
61104
},
62105
errors: [
63106
{
64-
message: "Missing error validation response of either 400 or 422.",
107+
message: "Missing error response of either 400, 422 or 4XX.",
65108
path: ["paths", "/", "get", "responses"],
66109
severity: DiagnosticSeverity.Warning,
67110
},

0 commit comments

Comments
 (0)