Skip to content

encoding/jsonschema: generated int64 bound exceeds the maximum int64 value #4438

Description

@rogpeppe

What version of CUE are you using (cue version)?

$ cue version
cue version (devel)

CUE language version v0.18.0

Built from master at commit e36c3d9.

Does this issue reproduce with the latest stable release?

Yes, with v0.17.0 (the reproducer below produces byte-identical output there).
Also reproduces with master at e36c3d9.

What did you do?

The following testscript (github.com/rogpeppe/go-internal/cmd/testscript) passes,
demonstrating the current behavior:

exec cue export --out jsonschema x.cue
cmp stdout want.json
-- x.cue --
x: int64
-- want.json --
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "x": {
            "allOf": [
                {
                    "type": "number"
                },
                {
                    "type": "integer",
                    "maximum": 9.223372036854776E+18,
                    "minimum": -9.223372036854776E+18
                }
            ]
        }
    },
    "required": [
        "x"
    ]
}

What did you expect to see?

The generated maximum should be the true maximum int64 value,
9223372036854775807 (and the minimum -9223372036854775808), expressed as an
integer rather than a float since the bound is integral.

What did you see instead?

The maximum is 9.223372036854776E+18 = 9223372036854775808, which is one
greater than the maximum int64 value, so the generated schema wrongly accepts
an out-of-range value. The bound is stored as a float64
(itemBounds.n float64 in encoding/jsonschema/generate_items.go), which
cannot represent int64 exactly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions