Skip to content

Commit 3994363

Browse files
Merge pull request #11 from Bandwidth/DX-2824
DX-2824 Linter Ruleset Update
2 parents ea51dc2 + 19d5dd2 commit 3994363

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

src/static/.local.spectral.yaml

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ rules:
3030
then:
3131
function: pattern
3232
functionOptions:
33-
match: "^([0-9]+.[0-9]+.[0-9]+)$"
33+
match: '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
3434
pathsSummary:
3535
description: There needs to be a summary field for every method.
3636
message: "There needs to be a summary property for every method."
@@ -63,11 +63,12 @@ rules:
6363
componentsRequestBodiesExists:
6464
description: There should be a requestBodies section within components.
6565
message: "Components is missing the '{{property}}' section"
66-
given: "$.components"
66+
given: "$.paths.[*][put, patch, post].requestBody.ref"
6767
severity: warn
6868
then:
69-
- field: "requestBodies"
70-
function: truthy
69+
function: pattern
70+
functionOptions:
71+
match: "#\/components\/requestBodies\/"
7172
camelCaseOperationId:
7273
description: All operationIds should be written in camelCase.
7374
message: "'{{value}}' needs to be written in camelCase."
@@ -78,21 +79,41 @@ rules:
7879
function: casing
7980
functionOptions:
8081
type: camel
81-
camelCaseParameterName:
82-
description: All parameter names should be written in camelCase.
82+
camelCaseComponentNames:
83+
description: All component names should be written in camelCase.
84+
message: "'{{value}}' needs to be written in camelCase."
85+
type: style
86+
given: "$.components..names"
87+
severity: warn
88+
then:
89+
function: casing
90+
functionOptions:
91+
type: camel
92+
camelCaseComponents:
93+
description: All components (schemas, parameters, etc) should be named in camelCase.
8394
message: "'{{value}}' needs to be written in camelCase."
8495
type: style
85-
given: "$.components.parameters.*.name"
96+
given: "$.components.[callbacks,schemas,parameters,examples,requestBodies,responses][*]~"
8697
severity: warn
8798
then:
8899
function: casing
89100
functionOptions:
90101
type: camel
102+
sentenceCaseDescriptions:
103+
description: Descriptions should be written in a normal sentence case.
104+
message: "'{{value}}' needs to be written in sentence case."
105+
type: style
106+
given: "$.*.[paths,schemas,securitySchemes]..description"
107+
severity: warn
108+
then:
109+
function: pattern
110+
functionOptions:
111+
match: "(^[A-Z]|(?<=[.?!]))*[A-Z][-_`)(A-Za-z0-9,;'\"\\s]*[.?!]"
91112
macroCaseEnum:
92113
description: Enums should be in MACRO case.
93114
message: "Enum value '{{value}}' should be written in MACRO case"
94115
type: style
95-
given: "$.components.*.*.enum.[*]"
116+
given: "$.components..enum.[*]"
96117
severity: warn
97118
then:
98119
function: casing
@@ -101,63 +122,64 @@ rules:
101122
badRequestError:
102123
description: "Responses should define a HTTP 400 Bad Request error"
103124
message: "Responses should define a 400 Bad Request Error."
104-
given: "$.paths.[*][*].responses"
125+
given: "$.*.paths..responses"
105126
severity: warn
106127
then:
107128
field: "400"
108129
function: truthy
109130
unauthorizedError:
110131
description: "Resources must declare a response for a HTTP 401 Unauthorized error"
111132
message: "Responses should define a 401 Unauthorized Error."
112-
given: "$.paths.[*][*].responses"
133+
given: "$.*.paths..responses"
113134
severity: warn
114135
then:
115136
field: "401"
116137
function: truthy
117138
forbiddenError:
118139
description: "Resources must declare a response for a HTTP 403 Forbidden error"
119140
message: "Responses should define a 403 Forbidden Error."
120-
given: "$.paths.[*][*].responses"
141+
given: "$.*.paths..responses"
121142
severity: warn
122143
then:
123144
field: "403"
124145
function: truthy
125146
notFoundError:
126147
description: "Resources must declare a response for a HTTP 404 Not Found error"
127148
message: "Responses should define a 404 Not Found Error."
128-
given: "$.paths.[*][get, put, patch, delete].responses"
149+
given: "$.*.paths.[*][get, put, patch, delete].responses"
129150
severity: warn
130151
then:
131152
field: "404"
132153
function: truthy
133154
methodNotAllowedError:
134155
description: "Resources must declare a response for a HTTP 405 Method Not Allowed error"
135156
message: "Responses should define a 405 Method Not Allowed Error."
136-
given: "$.paths.[*][*].responses"
157+
given: "$.*.paths..responses"
137158
severity: warn
138159
then:
139160
field: "405"
140161
function: truthy
141162
tooManyRequestsError:
142163
description: "Resources must declare a response for a HTTP 429 Too Many Requests error"
143164
message: "Responses should define a 429 Too Many Requests Error."
144-
given: "$.paths.[*][*].responses"
165+
given: "$.*.paths..responses"
145166
severity: warn
146167
then:
147168
field: "429"
148169
function: truthy
149170
internalServerError:
150171
description: "Resources must declare a response for a HTTP 500 Internal Server error"
151-
message: "Responses should define a 500 Internal Server Error."
152-
given: "$.paths.[*][*].responses"
172+
message: "Responses should define either a 500 or 5XX Internal Server Error. Note that 5XX must be capitalized."
173+
given: "$.*.paths..responses"
153174
severity: warn
154175
then:
155-
field: "500"
156-
function: truthy
176+
function: pattern
177+
functionOptions:
178+
match: "(^[500|5XX]$"
157179
globallyDefinedResponses:
158180
description: "Responses should be defined globally and referenced elsewhere."
159181
message: "All responses should be defined globally and only referenced everywhere else."
160-
given: "$.paths.[*][*].responses.*[*]"
182+
given: "$.*.paths..responses"
161183
resolved: false
162184
severity: error
163185
then:
@@ -166,7 +188,7 @@ rules:
166188
globallyDefinedRequestBodies:
167189
description: "RequestBodies should be defined globally and referenced elsewhere."
168190
message: "Every requestBody should be defined globally and only referenced everywhere else."
169-
given: "$.paths.[*][*].requestBody[*]"
191+
given: "$.paths.[*][post, put, patch].requestBody[*]"
170192
resolved: false
171193
severity: error
172194
then:

0 commit comments

Comments
 (0)