Skip to content

Commit 3e729a4

Browse files
feat: add rule for api must have a securitySchemes defined (#35)
1 parent 52be4a6 commit 3e729a4

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { DiagnosticSeverity } from "@stoplight/types";
2+
import testRule from "./__helpers__/helper";
3+
4+
testRule("adv-security-schemes-defined", [
5+
{
6+
name: "valid case",
7+
document: {
8+
openapi: "3.1.0",
9+
info: { version: "1.0" },
10+
components: {
11+
securitySchemes: {
12+
"oAuth2": {
13+
type: "oauth2",
14+
flow: {},
15+
},
16+
},
17+
},
18+
},
19+
errors: [],
20+
},
21+
22+
{
23+
name: "invalid case",
24+
document: {
25+
openapi: "3.1.0",
26+
info: { version: "1.0" },
27+
components: {},
28+
},
29+
errors: [
30+
{
31+
message: "This API definition does not have any security scheme defined.",
32+
path: ["components"],
33+
severity: DiagnosticSeverity.Error,
34+
},
35+
],
36+
},
37+
]);

src/ruleset.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,18 @@ export default {
278278
formats: [oas3],
279279
severity: DiagnosticSeverity.Warning,
280280
},
281+
282+
// Author: Advanced API & Integrations Team (https://www.oneadvanced.com/)
283+
"adv-security-schemes-defined": {
284+
description: "All APIs MUST have a security scheme defined.",
285+
message: "This API definition does not have any security scheme defined.",
286+
given: "$..components",
287+
then: {
288+
field: "securitySchemes",
289+
function: truthy
290+
},
291+
formats: [oas3],
292+
severity: DiagnosticSeverity.Error,
293+
},
281294
},
282295
};

0 commit comments

Comments
 (0)