Skip to content
Last updated

no-mixed-number-range-constraints

Ensures that schemas do not use both maximum and exclusiveMaximum (or both minimum and exclusiveMinimum) at the same time.

OASCompatibility
2.0
3.0
3.1
3.2
AsyncAPICompatibility
2.6
3.0
ArazzoCompatibility
1.0

In OpenAPI Specification version 3.1, exclusiveMaximum and exclusiveMinimum changed from booleans to numbers (aligning with JSON Schema draft 2020-12). This means a schema can accidentally specify both maximum: 10 and exclusiveMaximum: 10, creating conflicting constraints.

The default setting for this rule (in the built-in recommended configuration) is warn.

API design principles

When both maximum and exclusiveMaximum are present on the same schema, the intent is ambiguous. Is the upper bound inclusive or exclusive? Pick one:

  • Use maximum for an inclusive upper bound (value <= N).
  • Use exclusiveMaximum for an exclusive upper bound (value < N).

The same applies to minimum and exclusiveMinimum.

Configuration

To configure the rule, add it to the rules object in your configuration file. Set the desired severity for the rule.

rules:
  no-mixed-number-range-constraints: error
OptionTypeDescription
severitystringPossible values: off, warn, error. Default warn (in recommended configuration).

An example configuration:

rules:
  no-mixed-number-range-constraints: error

Examples

Given this configuration:

rules:
  no-mixed-number-range-constraints: error

Example of an incorrect schema:

type: integer
minimum: 0
maximum: 100
exclusiveMaximum: 100

Example of a correct schema (inclusive upper bound):

type: integer
minimum: 0
maximum: 100

Example of a correct schema (exclusive upper bound):

type: integer
minimum: 0
exclusiveMaximum: 100

Resources