-
Notifications
You must be signed in to change notification settings - Fork 35
/
.spectral.yml
158 lines (140 loc) · 4.16 KB
/
.spectral.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
extends: spectral:oas
rules:
# Host is required
oas2-api-host: off
# ENDPOINT PROPERTIES
endpoint-requires-description:
description: Endpoint MUST include description
severity: error
given: $.paths[*][?( @property !== 'parameters' )]
then:
- field: "description"
function: truthy
endpoint-description-length:
description: The endpoint description should be at least 128 characters.
severity: warn
given: $.paths[*][*].description
then:
function: length
functionOptions:
min: 128
endpoint-operation-id-case:
description: Path operationId MUST be camelCase
severity: error
given: "$..operationId"
then:
function: pattern
functionOptions:
match: '^[a-z]+[a-zA-Z0-9]*$'
endpoint-path-case:
description: Paths MUST be kebab-case and {params} in path MUST be camelCase
severity: error
given: $..paths[*]~
then:
function: pattern
functionOptions:
match: '^/(/|[a-z]+(\-[a-z]+)*|{[a-z0-9]+[a-zA-Z0-9]*})*$'
# PRODUCES AND CONSUMES
endpoint-requires-produces:
description: Endpoints MUST include produces property
given: $.paths[*][?( @property !== 'parameters' )]
then:
- field: "produces"
function: truthy
- field: "produces.*"
function: enumeration
functionOptions:
values:
- application/json
- application/pdf
produces-allowed-types:
#message: "{{error}}"
description: Allowable types for produces are [application/json, application/pdf]
given: $.paths[*][?( @property !== 'parameters' )].produces.*
then:
- function: enumeration
functionOptions:
values:
- application/json
- application/pdf
endpoint-requires-consumes:
description: Endpoints that [POST,PUT,PATCH] methods must include consumes property
#message: "{{error}}"
given: $.paths.*[?( @property === 'post' || @property === 'patch' || @property === 'put')]
then:
- field: "consumes"
function: truthy
consumes-allowed-types:
description: Allowable types for consumes are [application/json, multipart/form-data]
#message: "{{error}}"
given: $.paths.*[?( @property === 'post' || @property === 'patch' || @property === 'put')].consumes.*
then:
- function: enumeration
functionOptions:
values:
- application/json
- multipart/form-data
# BODY PROPERTIES
body-properties-case:
description: Body properties MUST be camelCase
severity: error
given: $..properties.*~
then:
function: pattern
functionOptions:
match: '^[a-z]+[a-zA-Z0-9]*$'
created-at-read-only:
description: Property createdAt MUST be readOnly
#message: "{{error}}"
severity: error
given: $..properties.createdAt
then:
- field: "readOnly"
function: truthy
updated-at-read-only:
description: Property updatedAt MUST be readOnly
#message: "{{error}}"
severity: error
given: $..properties.updatedAt
then:
- field: "readOnly"
function: truthy
etag-read-only:
description: Property eTag MUST be readOnly
#message: "{{error}}"
severity: error
given: $..properties.eTag
then:
- field: "readOnly"
function: truthy
date-no-example:
description: Property of type date should not give example, due to ReDoc quirk
#message: "{{error}}"
severity: error
given: $..properties[?(@.format == "date")]
then:
- field: example
function: falsy
# DEFINITIONS
definitions-sort:
description: Definitions should be sorted alphabetically
#message: "{{warn}}"
severity: warn
given: $.definitions.~
then:
function: alphabetical
definitions-no-payload:
description: Definition names MUST not end in Payload
#message: "{{error}}"
severity: error
given: $.definitions.~
then:
function: pattern
functionOptions:
notMatch: '^.*[Pp]ayload$'
# camelCase inside curly braces
# match: '^{[a-z]+[a-zA-Z]*}$'
# kebab-case with
# match: '^[a-z]+(\-[a-z]+)*$'
# this or that
# match: '^(/|abc|def)*$'