-
Notifications
You must be signed in to change notification settings - Fork 5
Endpoint API Linting Rules
Schwarz API custom rulesets depend heavily on Spectral OAS Recommended Rules. We consider them to be a very good starting point that we built our custom rules on top of it.
Below you'll find a more semantic description about the API Endpoint rulesets.
Rule to check if a 401 response is implemented on all paths responses
Severities
- Product API Severity Level: hint
- BFF API Severity Level: hint
- Legacy API Severity Level: hint
common-responses-unauthorized:
description: Responses should contain common response - 401 (unauthorized)
message: "{{description}}. Missing {{property}}"
severity: error
given: $.paths[?([email protected](/well-known/ig))]..responses
then:
- field: '401'
function: truthyRule to check if a resource is implementing all intended HTTP verbs for a data source
Severities
- Product API Severity Level: info
- BFF API Severity Level: info
- Legacy API Severity Level: info
http-verbs-should-be-used:
description: HTTP verbs should be used to express different actions or functions on a resource
message: "{{description}}; The HTTP verb {{property}} is missing."
severity: error
given: $.paths[?([email protected](/well-known/ig))]
then:
- field: get
function: truthy
- field: post
function: truthy
- field: put
function: truthy
- field: patch
function: truthy
- field: delete
function: truthyRule to check that every DTO has at least one example
Severities
- Product API Severity Level: warn
- BFF API Severity Level: info
- Legacy API Severity Level: info
must-define-example-schema:
description: Every DTO must define at least one example
message: "{{description}}; DTO is lacking an example {{path}}"
severity: error
given: $.paths[?([email protected](/well-known/ig))]..content.*
then:
- function: xor
functionOptions:
properties:
- example
- examplesRule to check that every path response has a content type defined
Severities
- Product API Severity Level: warn
- BFF API Severity Level: info
- Legacy API Severity Level: info
must-have-content-type:
description: Every response must specify its content type
message: "{{description}}; property {{property}} is missing or not a valid content-type"
severity: error
given: $.paths[?([email protected](/well-known/ig))]..content
then:
- field: "@key"
function: pattern
functionOptions:
match: "/"Rule to check that every path with HTTP status code of 200 or 201 has a response body defined
Severities
- Product API Severity Level: warn
- BFF API Severity Level: info
- Legacy API Severity Level: info
must-have-response-body:
description: Every route returning a http status code of 200 or 201 must have a response body defined
message: "{{description}}; property {{property}} is missing at path: {{path}}"
severity: error
given: $.paths[?([email protected](/well-known/ig))]..responses[200,201]
then:
- field: content
function: truthy
- field: description
function: truthyRule to check misuse of http verbs in url names
Severities
- Product API Severity Level: warn
- BFF API Severity Level: info
- Legacy API Severity Level: info
no-http-verbs-in-resources:
description: The HTTP Verbs should not be used in the route path to define different actions on a resource
message: "{{description}}; {{property}} Instead use HTTP verbs to define actions on a resource. Example: PUT - /digital-twin/api/v1/products/42"
severity: error
given: $.paths[?([email protected](/well-known/ig))]~
then:
function: pattern
functionOptions:
notMatch: \/(get|post|put|patch|delete)(\/|$)Rule to check if every path has a description defined
Severities
- Product API Severity Level: warn
- BFF API Severity Level: info
- Legacy API Severity Level: info
path-description-is-mandatory:
description: Every route of an API should have a description
message: "{{description}}; property: {{property}} is missing"
severity: error
given: $.paths[?([email protected](/well-known/ig))]
then:
- field: description
function: truthyRule to check if every path specifies at least one tag
Severities
- Product API Severity Level: warn
- BFF API Severity Level: info
- Legacy API Severity Level: info
path-must-specify-tags:
description: Every route must specify at least one tag it belongs to
message: "{{description}}; property tags is missing at: {{path}}"
severity: error
given: $.paths[?([email protected](/well-known/ig))].*
then:
- field: tags
function: length
functionOptions:
min: 1