@@ -2,3 +2,83 @@ extends: [ "spectral:oas" ]
22rules :
33 oas3-valid-media-example : off
44 oas3-valid-schema-example : off
5+ strings-need-bounds :
6+ description : Strings must be bounded unless they already use format/enum/pattern
7+ given :
8+ - " $.components.schemas.*"
9+ - " $.paths.*.*.parameters[*].schema"
10+ - " $.paths.*.*.requestBody.content.*.schema"
11+ - " $.paths.*.*.responses.*.content.*.schema"
12+ then :
13+ function : schema
14+ functionOptions :
15+ schema :
16+ if :
17+ properties : { type: { const: string } }
18+ required : [ type ]
19+ then :
20+ anyOf :
21+ - required : [ maxLength ]
22+ - required : [ enum ]
23+ - required : [ pattern ]
24+ - required : [ format ]
25+ severity : warn
26+
27+ arrays-need-maxitems :
28+ given :
29+ - " $.components.schemas.*"
30+ - " $.paths.*.*.parameters[*].schema"
31+ - " $.paths.*.*.requestBody.content.*.schema"
32+ - " $.paths.*.*.responses.*.content.*.schema"
33+ then :
34+ function : schema
35+ functionOptions :
36+ schema :
37+ if :
38+ properties : { type: { const: array } }
39+ required : [ type ]
40+ then :
41+ required : [ maxItems ]
42+ severity : warn
43+
44+ path-string-params-need-format-or-pattern :
45+ given :
46+ - " $.paths.*.*.parameters[?(@.in=='path')].schema"
47+ then :
48+ function : schema
49+ functionOptions :
50+ schema :
51+ if :
52+ properties : { type: { const: string } }
53+ required : [ type ]
54+ then :
55+ anyOf :
56+ - required : [ format ]
57+ - required : [ pattern ]
58+ severity : warn
59+
60+ param-id-needs-format-or-pattern :
61+ given :
62+ - " $.paths.*.*.parameters[?(@.name=='id')].schema"
63+ then :
64+ function : schema
65+ functionOptions :
66+ schema :
67+ anyOf :
68+ - required : [ format ]
69+ - required : [ pattern ]
70+ severity : warn
71+
72+ schema-id-prop-needs-format-or-pattern :
73+ given :
74+ - " $.components.schemas.*.properties.id"
75+ - " $.paths.*.*.requestBody.content.*.schema.properties.id"
76+ then :
77+ function : schema
78+ functionOptions :
79+ schema :
80+ anyOf :
81+ - required : [ format ]
82+ - required : [ pattern ]
83+ severity : warn
84+
0 commit comments