Skip to content

Bound integer schema values to the JavaScript safe-integer range (§2.2 Data Definitions) #648

Description

@hdamker

Problem description

§2.2 (Data Definitions) requires integer properties to specify format and minimum/maximum, but sets no upper bound on their magnitude. OpenAPI permits the full int64 range, so an API may declare maximum: 9223372036854775807. Values above the JavaScript safe-integer range (9007199254740991, 2^53−1) cannot be represented exactly by the JSON/JavaScript tooling used across the CAMARA API lifecycle and are silently rounded — 9223372036854775807 becomes 9223372036854776000. The published artifact then carries a constraint that differs from the source contract, with nothing flagging the change.

Possible evolution

Add a normative constraint to §2.2: numeric schema values (minimum, maximum, default, example, …) MUST lie within [-9007199254740991, 9007199254740991] (Number.MAX_SAFE_INTEGER). A property that genuinely needs a larger range MUST be modeled as a string with an appropriate pattern, since JSON/JavaScript consumers cannot reliably handle integers beyond 2^53 anyway.

Suggested wording for the §2.2 integer bullet:

If the data type is integer, format (int32 or int64) and range (minimum and maximum) MUST be specified. Numeric schema values MUST lie within the safe-integer range [-9007199254740991, 9007199254740991] (Number.MAX_SAFE_INTEGER); values outside it are silently rounded by JSON/JavaScript tooling and MUST instead be modeled as a string with an appropriate pattern.

This limit will be enforced by a rule in the CAMARA validation tooling, which also keeps the release bundling step producing correct artifacts.

Alternative solution

Non-normative guidance only, without a MUST or a check. Rejected: the mutation is silent and reviewers reasonably treat the bundled snapshot as authoritative, so guidance alone would not prevent corrupted constraints from shipping.

Additional context

Observed in a real release artifact; the precision loss originates in an upstream bundler issue (Redocly/redocly-cli#1389, open since January 2024). int32 values are inherently within range, so the constraint affects only int64; floating-point precision is a separate concern, intentionally out of scope. Tracking: camaraproject/tooling#331

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions