Skip to content

Commit

Permalink
add description and examples for exclusiveMaximum keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
AgniveshChaubey committed Feb 7, 2024
1 parent bd05e98 commit e789f84
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions content/2020-12/validation/exclusiveMaximum.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,69 @@ related:
- vocabulary: validation
keyword: multipleOf
---

The `exclusiveMaximum` keyword is used to set an exclusive upper limit on numeric instances. It specifies that the numeric value being validated must be strictly less than (not equal to) the provided maximum value.

* Applies only to number data types (integers and floats).
* Validation succeeds if the number is strictly less than the specified `exclusiveMaximum`.

## Examples

{{<schema `Schema defining exclusive upper limit of 10 on numeric values`>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "number",
"exclusiveMaximum": 10
}
{{</schema>}}

{{<instance-fail `An instance with numeric value greater than 10 is invalid`>}}
15
{{</instance-fail>}}

{{<instance-pass `An instance with numeric value less than 10 is valid`>}}
9.5
{{</instance-pass>}}

{{<instance-fail `An instance with numeric value equal to 10 is invalid`>}}
10
{{</instance-fail>}}

{{<schema ` Schema allowing either a string value or a numeric value with an exclusive upper limit of 20`>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": [ "string", "number" ],
"exclusiveMaximum": 20
}
{{</schema>}}

{{<instance-pass `An instance with a numeric value less than 20 is valid`>}}
15
{{</instance-pass>}}

{{<instance-fail `An instance with a boolean datatype is invalid`>}}
true
{{</instance-fail>}}

{{<instance-pass `An instance with a string value is valid`>}}
"Hello World!"
{{</instance-pass>}}

{{<schema `Schema with both 'maximum' and 'exclusiveMaximum' keywords`>}}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "number",
"exclusiveMaximum": 10,
"maximum": 20
}
{{</schema>}}

{{<instance-pass `An instance with numeric value less than 10 is valid`>}}
9.5
{{</instance-pass>}}

{{<instance-fail `An instance with numeric value greater than or equal to 10 is invalid`>}}
15
{{</instance-fail>}}

* _**Note:** Here, the `exclusiveMaximum` takes precedence, even though `maximum` is 20. Only numbers less than 10 are valid._

0 comments on commit e789f84

Please sign in to comment.