The then property defines the check Spectral performs on each value selected by given. It names a function and can optionally identify a field within the selected object. section 3.6
Configure then with two keywords:
- function names the Spectral function that evaluates the input and reports a violation when it finds a problem. section 3.6
- field is optional and narrows evaluation to a property of the selected object, such as description within $.info. section 3.6
- given supplies the JSONPath selection; if it returns no elements, Spectral does not evaluate then. section 3.6
Listing 3.1 A Spectral rule to check that info.description is present
rules:
info-description-is-required: #1
message: "API definition files must
have info.description defined" #2
severity: error #3
given: $.info #4
then:
field: description #5
function: truthy #6
A complete rule uses $.info as given, then targets the description field with Spectral’s truthy function. section 3.6
