-
Notifications
You must be signed in to change notification settings - Fork 14
/
baloise.yml
210 lines (184 loc) · 6.6 KB
/
baloise.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
extends: [./zalando.yml] # We're extending the zalando ruleset by replacing or adding baloise specific rules.
functions:
- validate-tracing
- assert-http-codes-for-operation
rules:
# CAN use URI versioning [115a]
# => Alternative to https://opensource.zalando.com/restful-api-guidelines/#115
must-not-use-uri-versioning: off
can-use-correct-uri-versioning:
message: Path can contain correct URI versioning
description: CAN use correct URI versioning [115a]
documentationUrl: https://github.com/baloise-incubator/spectral-ruleset/blob/main/doc/rules/can-use-correct-URI-versioning.test.md
severity: error
given: $.paths.*~
then:
function: pattern
functionOptions:
match: ^((?!.*\/v\d+(\/.*)?\/v\d+)\/.*)$
# MUST property names must be ASCII camelCase [118a]
# => Alternative to https://opensource.zalando.com/restful-api-guidelines/#118
must-use-snake-case-for-property-names: off
must-use-camel-case-for-property-names:
message: Property name has to be ASCII camelCase
description: MUST property names must be ASCII camelCase [118a]
documentationUrl: https://github.com/baloise-incubator/spectral-ruleset/blob/main/doc/rules/property-names-must-be-ascii-camel-case.md
severity: error
given: $.paths.*.*[responses,requestBody]..content..schema..properties.*~
then:
function: pattern
functionOptions:
match: ^[a-z]+((\d)|([A-Z0-9][a-z0-9]+))*([A-Z])?$
# MUST use standard HTTP status codes [150a]
# => Addition of 422 compared to https://opensource.zalando.com/restful-api-guidelines/#150
must-use-standard-http-status-codes: off
must-use-additional-standard-http-status-codes:
message: '{{property}} is not a standardized response code'
description: MUST use standard HTTP status codes [150a]
documentationUrl: https://github.com/baloise-incubator/spectral-ruleset/blob/main/doc/rules/must-use-additional-standard-http-status-codes.md
severity: error
given: $.paths.*.*.responses.*~
then:
function: enumeration
functionOptions:
values:
- '100'
- '101'
- '200'
- '201'
- '202'
- '203'
- '204'
- '205'
- '206'
- '207'
- '300'
- '301'
- '302'
- '303'
- '304'
- '305'
- '307'
- '400'
- '401'
- '402'
- '403'
- '404'
- '405'
- '406'
- '407'
- '408'
- '409'
- '410'
- '411'
- '412'
- '413'
- '414'
- '415'
- '416'
- '417'
- '422'
- '423'
- '426'
- '428'
- '429'
- '431'
- '500'
- '501'
- '502'
- '503'
- '504'
- '505'
- '511'
- default
must-use-additional-standard-http-status-codes-422:
message: 'Prefer 400 over 422 as response code'
description: MUST use standard HTTP status codes [150a]
documentationUrl: https://github.com/baloise-incubator/spectral-ruleset/blob/main/doc/rules/must-use-additional-standard-http-status-codes.md
severity: warn
given: $.paths.*.*.responses.422
then:
field: '422'
function: defined
should-use-well-understood-http-status-codes: off
should-use-additional-well-understood-http-status-codes:
message: '{{error}}'
description: MUST use standard HTTP status codes [150]
documentationUrl: https://github.com/baloise-incubator/spectral-ruleset/blob/main/doc/rules/should-use-additional-well-understood-http-status-codes.md
severity: warn
given: $.paths.*
then:
function: assert-http-codes-for-operation
functionOptions:
wellUnderstood:
# Success Codes
'200': [ ALL ]
'201': [ POST, PUT ]
'202': [ POST, PUT, DELETE, PATCH ]
'204': [ PUT, DELETE, PATCH ]
'207': [ POST ]
# Redirection Codes
'301': [ ALL ]
'303': [ PATCH, POST, PUT, DELETE ]
'304': [ GET, HEAD ]
# Client Side Error Codes
'400': [ ALL ]
'401': [ ALL ]
'403': [ ALL ]
'404': [ ALL ]
'405': [ ALL ]
'406': [ ALL ]
'408': [ ALL ]
'409': [ POST, PUT, DELETE, PATCH ]
'410': [ ALL ]
'412': [ PUT, DELETE, PATCH ]
'415': [ POST, PUT, DELETE, PATCH ]
'422': [ ALL ]
'423': [ PUT, DELETE, PATCH ]
'428': [ ALL ]
'429': [ ALL ]
# Server Side Error Codes
'500': [ ALL ]
'501': [ ALL ]
'503': [ ALL ]
# OpenApi
'default': [ ALL ]
# MUST request must provide tracing [233a]
# => Alternative to https://opensource.zalando.com/restful-api-guidelines/#233
must-use-tracing:
message: Header X-B3-Traceid, X-B3-Spanid or traceparent (w3c) missing
description: MUST use b3 or w3c tracing [233a]
documentationUrl: https://github.com/baloise-incubator/spectral-ruleset/blob/main/doc/rules/requests-must-use-tracing.md
severity: error
given: $.paths.*
then:
function: validate-tracing
# MUST provide API audience [219]
# => https://opensource.zalando.com/restful-api-guidelines/#219
must-provide-api-audience: off
must-provide-baloise-api-audience:
message: Missing or wrong `info.x-audience`.
description: MUST provide API audience [219]
documentationUrl: https://github.com/baloise-incubator/spectral-ruleset/blob/main/doc/rules/property-names-must-be-ascii-camel-case.md
severity: error
given: $.info
then:
- field: x-audience
function: truthy
- field: x-audience
function: pattern
functionOptions:
match: ^(team-internal|domain-internal|company-internal|external-partner|external-public)$
# MUST use camel case for query parameters [130a]
# => Alternative to https://opensource.zalando.com/restful-api-guidelines/#130
must-use-snake-case-for-query-parameters: off
must-use-camel-case-for-query-parameters:
message: Query parameter name has to be ASCII camelCase
description: MUST query parameter names must be ASCII camelCase [130a]
documentationUrl: https://github.com/baloise-incubator/spectral-ruleset/blob/main/doc/rules/query-parameter-names-must-be-ascii-camel-case.md
severity: error
given: $.paths.*.*.parameters[?(@ && @.in=='query')].name
then:
function: pattern
functionOptions:
match: ^[a-z]+((\d)|([A-Z0-9][a-z0-9]+))*([A-Z])?$