From 544c0c9366395d7021da16db7f7a47f3beac71ab Mon Sep 17 00:00:00 2001 From: Heitor Tashiro Sergent Date: Mon, 18 Jul 2022 16:50:06 -0500 Subject: [PATCH 1/2] docs(repo): add multiple thens example --- docs/guides/4-custom-rulesets.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/guides/4-custom-rulesets.md b/docs/guides/4-custom-rulesets.md index 7f071e34f..ecf3d8771 100644 --- a/docs/guides/4-custom-rulesets.md +++ b/docs/guides/4-custom-rulesets.md @@ -86,7 +86,7 @@ rules: The `then` part of the rule explains which function to apply to the `given` JSONPath. The function you apply [may be one of the core functions](../reference/functions.md) or it may be [a custom function](./5-custom-functions.md). -`then` has two required keywords: +`then` has two main keywords: ```yaml then: @@ -115,6 +115,22 @@ responses: foo: bar ``` +You can also have multiple `then`s to target different properties in the same object, or to use different functions. For example, you can have one rule that will check if an object has multiple properties: + +```yaml +contact-properties: + description: Contact object must have "name", "url", and "email". + given: $.info.contact + severity: warn + then: + - field: name + function: truthy + - field: url + function: truthy + - field: email + function: truthy +``` + ### Message To help you create meaningful messages for results, Spectral comes with a couple of placeholders that are evaluated at runtime. From 0b14a6ce079b40bcb16303b89731cda74f21b845 Mon Sep 17 00:00:00 2001 From: Heitor Tashiro Sergent Date: Mon, 18 Jul 2022 17:13:00 -0500 Subject: [PATCH 2/2] docs(repo): prettier --- docs/guides/4-custom-rulesets.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/guides/4-custom-rulesets.md b/docs/guides/4-custom-rulesets.md index ecf3d8771..276b5fb39 100644 --- a/docs/guides/4-custom-rulesets.md +++ b/docs/guides/4-custom-rulesets.md @@ -119,16 +119,16 @@ You can also have multiple `then`s to target different properties in the same ob ```yaml contact-properties: - description: Contact object must have "name", "url", and "email". - given: $.info.contact - severity: warn - then: - - field: name - function: truthy - - field: url - function: truthy - - field: email - function: truthy + description: Contact object must have "name", "url", and "email". + given: $.info.contact + severity: warn + then: + - field: name + function: truthy + - field: url + function: truthy + - field: email + function: truthy ``` ### Message