1+ # This file is part of Dependency-Track.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+ #
15+ # SPDX-License-Identifier: Apache-2.0
16+ # Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+ # Rules to assert conformance to a curated subset of Zalando's
19+ # RESTful API guidelines: https://opensource.zalando.com/restful-api-guidelines/#
20+ #
21+ # Credit to the folks at baloise for providing these spectral rules:
22+ # https://github.com/baloise-incubator/spectral-ruleset/blob/main/zalando.yml
23+ rules :
24+ must-use-semantic-versioning :
25+ message : ' {{error}}'
26+ description : MUST use semantic versioning [116]
27+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#116
28+ severity : error
29+ given : $.info.version
30+ then :
31+ function : schema
32+ functionOptions :
33+ schema :
34+ type : string
35+ pattern : ' ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$'
36+
37+ must-use-snake-case-for-property-names :
38+ message : Property name has to be ASCII snake_case
39+ description : MUST property names must be ASCII snake_case [118]
40+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#118
41+ severity : error
42+ given : $.paths.*.*[responses,requestBody]..content..schema..properties.*~
43+ then :
44+ function : pattern
45+ functionOptions :
46+ match : ^[a-z_][a-z_0-9]*$
47+
48+ must-use-lowercase-with-hypens-for-path-segements :
49+ message : Path segments have to be lowercase separate words with hyphens
50+ description : MUST use lowercase separate words with hyphens for path segments [129]
51+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#129
52+ severity : error
53+ given : $.paths.*~
54+ then :
55+ function : pattern
56+ functionOptions :
57+ match : ^(?=((([\/a-z][a-z0-9\-\/]*)?({[^}]*})?)+))\1$
58+
59+ must-use-snake-case-for-query-parameters :
60+ message : Query parameters must be snake_case
61+ description : MUST use snake_case (never camelCase) for query parameters [130]
62+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#130
63+ severity : error
64+ given : $.paths.*.*.parameters[?(@ && @.in=='query')].name
65+ then :
66+ function : pattern
67+ functionOptions :
68+ match : ^[a-z][_a-z0-9]*$
69+
70+ must-use-normalized-paths-without-empty-path-segments :
71+ message : Empty path segments are not allowed
72+ description : MUST use normalized paths without empty path segments and trailing slashes [136]
73+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#136
74+ severity : error
75+ given : $.paths.*~
76+ then :
77+ function : pattern
78+ functionOptions :
79+ notMatch : //
80+
81+ must-use-normalized-paths-without-trailing-slash :
82+ message : Path with trailing slash is not allowed
83+ description : MUST use normalized paths without empty path segments and trailing slashes [136]
84+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#136
85+ severity : error
86+ given : $.paths.*~
87+ then :
88+ function : pattern
89+ functionOptions :
90+ notMatch : /$
91+
92+ must-specify-default-response :
93+ message : Operation does not contain a default response
94+ description : MUST specify success and error responses [151]
95+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#151
96+ severity : error
97+ given : $.paths.*.*.responses
98+ then :
99+ field : default
100+ function : truthy
101+
102+ must-use-standard-formats-for-date-and-time-properties-example :
103+ message : " You should provide an example for {{property}}"
104+ description : MUST use standard formats for date and time properties [169]
105+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#169
106+ severity : warn # Not an error as you only should provide an example to help your consumers
107+ given : $.paths..[?(@.type === 'string' && (@.format === 'date-time' || @.format === 'date' || @.format === 'time' || @.format === 'duration' || @.format === 'period'))]
108+ then :
109+ field : example
110+ function : truthy
111+
112+ must-use-standard-formats-for-date-and-time-properties-utc :
113+ message : " You should UTC for {{property}}"
114+ description : MUST use standard formats for date and time properties [169]
115+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#169
116+ severity : warn # Not an error as you only should provide an example to help your consumers
117+ given : $.paths..[?(@.type === 'string' && @.format === 'date-time')]
118+ then :
119+ field : example
120+ function : pattern
121+ functionOptions :
122+ match : " Z$"
123+
124+ must-use-problem-json-as-default-response :
125+ message : Operation must use problem json as default response
126+ description : MUST specify success and error responses [151]
127+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#151
128+ severity : error
129+ given : $.paths.*.*.responses.default
130+ then :
131+ field : content.application/problem+json
132+ function : truthy
133+
134+ must-define-a-format-for-number-types :
135+ message : Numeric properties must have valid format specified
136+ description : MUST define a format for number and integer types [171]
137+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#171
138+ severity : error
139+ given : $.paths.*.*..schema..properties..[?(@ && @.type=='number')]
140+ then :
141+ - field : format
142+ function : defined
143+ - field : format
144+ function : pattern
145+ functionOptions :
146+ match : ^(float|double|decimal)$
147+
148+ must-define-a-format-for-integer-types :
149+ message : Numeric properties must have valid format specified
150+ description : MUST define a format for number and integer types [171]
151+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#171
152+ severity : error
153+ given : $.paths.*.*..schema..properties..[?(@ && @.type=='integer')]
154+ then :
155+ - field : format
156+ function : defined
157+ - field : format
158+ function : pattern
159+ functionOptions :
160+ match : ^(int32|int64|bigint)$
161+
162+ should-prefer-standard-media-type-names :
163+ message : Custom media types should only be used for versioning
164+ description : SHOULD prefer standard media type name application/json [172]
165+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#172
166+ severity : warn
167+ given : $.paths.*.*.responses.*.content.*~
168+ then :
169+ function : pattern
170+ functionOptions :
171+ match : ^application\/(problem\+)?json$|^[a-zA-Z0-9_]+\/[-+.a-zA-Z0-9_]+;(v|version)=[0-9]+$
172+
173+ must-use-problem-json-for-errors :
174+ message : Error response must be application/problem+json
175+ description : MUST support problem JSON [176]
176+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#176
177+ severity : error
178+ given : $.paths.*.*.responses[?(@ && @property.match(/^(4|5)/))]
179+ then :
180+ field : content.application/problem+json
181+ function : truthy
182+
183+ should-declare-enum-values-using-upper-snake-case-format :
184+ message : ' Enum values should be in UPPER_SNAKE_CASE format'
185+ description : SHOULD declare enum values using UPPER_SNAKE_CASE format [240]
186+ documentationUrl : https://opensource.zalando.com/restful-api-guidelines/#240
187+ severity : warn
188+ given : $.paths..[?(@ && @.type=='string')].[enum,x-extensible-enum].*
189+ then :
190+ function : pattern
191+ functionOptions :
192+ match : ^[A-Z][A-Z_0-9]*$
0 commit comments