Skip to content

Commit

Permalink
DX-2824 Linter Ruleset Update
Browse files Browse the repository at this point in the history
  • Loading branch information
brianluisgomez committed Jan 6, 2023
1 parent ea51dc2 commit 19d5dd2
Showing 1 changed file with 42 additions and 20 deletions.
62 changes: 42 additions & 20 deletions src/static/.local.spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rules:
then:
function: pattern
functionOptions:
match: "^([0-9]+.[0-9]+.[0-9]+)$"
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-]+)*))?$'
pathsSummary:
description: There needs to be a summary field for every method.
message: "There needs to be a summary property for every method."
Expand Down Expand Up @@ -63,11 +63,12 @@ rules:
componentsRequestBodiesExists:
description: There should be a requestBodies section within components.
message: "Components is missing the '{{property}}' section"
given: "$.components"
given: "$.paths.[*][put, patch, post].requestBody.ref"
severity: warn
then:
- field: "requestBodies"
function: truthy
function: pattern
functionOptions:
match: "#\/components\/requestBodies\/"
camelCaseOperationId:
description: All operationIds should be written in camelCase.
message: "'{{value}}' needs to be written in camelCase."
Expand All @@ -78,21 +79,41 @@ rules:
function: casing
functionOptions:
type: camel
camelCaseParameterName:
description: All parameter names should be written in camelCase.
camelCaseComponentNames:
description: All component names should be written in camelCase.
message: "'{{value}}' needs to be written in camelCase."
type: style
given: "$.components..names"
severity: warn
then:
function: casing
functionOptions:
type: camel
camelCaseComponents:
description: All components (schemas, parameters, etc) should be named in camelCase.
message: "'{{value}}' needs to be written in camelCase."
type: style
given: "$.components.parameters.*.name"
given: "$.components.[callbacks,schemas,parameters,examples,requestBodies,responses][*]~"
severity: warn
then:
function: casing
functionOptions:
type: camel
sentenceCaseDescriptions:
description: Descriptions should be written in a normal sentence case.
message: "'{{value}}' needs to be written in sentence case."
type: style
given: "$.*.[paths,schemas,securitySchemes]..description"
severity: warn
then:
function: pattern
functionOptions:
match: "(^[A-Z]|(?<=[.?!]))*[A-Z][-_`)(A-Za-z0-9,;'\"\\s]*[.?!]"
macroCaseEnum:
description: Enums should be in MACRO case.
message: "Enum value '{{value}}' should be written in MACRO case"
type: style
given: "$.components.*.*.enum.[*]"
given: "$.components..enum.[*]"
severity: warn
then:
function: casing
Expand All @@ -101,63 +122,64 @@ rules:
badRequestError:
description: "Responses should define a HTTP 400 Bad Request error"
message: "Responses should define a 400 Bad Request Error."
given: "$.paths.[*][*].responses"
given: "$.*.paths..responses"
severity: warn
then:
field: "400"
function: truthy
unauthorizedError:
description: "Resources must declare a response for a HTTP 401 Unauthorized error"
message: "Responses should define a 401 Unauthorized Error."
given: "$.paths.[*][*].responses"
given: "$.*.paths..responses"
severity: warn
then:
field: "401"
function: truthy
forbiddenError:
description: "Resources must declare a response for a HTTP 403 Forbidden error"
message: "Responses should define a 403 Forbidden Error."
given: "$.paths.[*][*].responses"
given: "$.*.paths..responses"
severity: warn
then:
field: "403"
function: truthy
notFoundError:
description: "Resources must declare a response for a HTTP 404 Not Found error"
message: "Responses should define a 404 Not Found Error."
given: "$.paths.[*][get, put, patch, delete].responses"
given: "$.*.paths.[*][get, put, patch, delete].responses"
severity: warn
then:
field: "404"
function: truthy
methodNotAllowedError:
description: "Resources must declare a response for a HTTP 405 Method Not Allowed error"
message: "Responses should define a 405 Method Not Allowed Error."
given: "$.paths.[*][*].responses"
given: "$.*.paths..responses"
severity: warn
then:
field: "405"
function: truthy
tooManyRequestsError:
description: "Resources must declare a response for a HTTP 429 Too Many Requests error"
message: "Responses should define a 429 Too Many Requests Error."
given: "$.paths.[*][*].responses"
given: "$.*.paths..responses"
severity: warn
then:
field: "429"
function: truthy
internalServerError:
description: "Resources must declare a response for a HTTP 500 Internal Server error"
message: "Responses should define a 500 Internal Server Error."
given: "$.paths.[*][*].responses"
message: "Responses should define either a 500 or 5XX Internal Server Error. Note that 5XX must be capitalized."
given: "$.*.paths..responses"
severity: warn
then:
field: "500"
function: truthy
function: pattern
functionOptions:
match: "(^[500|5XX]$"
globallyDefinedResponses:
description: "Responses should be defined globally and referenced elsewhere."
message: "All responses should be defined globally and only referenced everywhere else."
given: "$.paths.[*][*].responses.*[*]"
given: "$.*.paths..responses"
resolved: false
severity: error
then:
Expand All @@ -166,7 +188,7 @@ rules:
globallyDefinedRequestBodies:
description: "RequestBodies should be defined globally and referenced elsewhere."
message: "Every requestBody should be defined globally and only referenced everywhere else."
given: "$.paths.[*][*].requestBody[*]"
given: "$.paths.[*][post, put, patch].requestBody[*]"
resolved: false
severity: error
then:
Expand Down

0 comments on commit 19d5dd2

Please sign in to comment.