Skip to content

Check safe integers and make JSON values public - #876

Merged
mristin merged 1 commit into
mainfrom
mristin/Publish-JSON-values-and-check-safe-integers
Nov 1, 2026
Merged

mristin merged 1 commit into
mainfrom
mristin/Publish-JSON-values-and-check-safe-integers

Conversation

@mristin

@mristin mristin commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

We make the de/serialization of JSON-able values public in all SDKs so that the aas-client3.2 implementations can use them, e.g., json_value_from_jsonable in Python, JsonValueFromJsonable in Go, Deserialize.JsonValueFrom in C# and JsonValueFrom in C++.

A JSON number is read as a 64-bit float by the other SDKs, so we refuse every integer outside the safe integer range [-2^53 + 1, 2^53 - 1] consistently: for integer properties and in JSON-able values, in JSON and XML de/serialization, in XML-RPC, in parsing with int and in the verification. Once the verification passes, the serialization thus works.

The bounds live in a single shared predicate per SDK, e.g., in Go:

func IsSafeInteger(value int64) bool {
    return -9007199254740991 <= value && value <= 9007199254740991
}

(common.is_safe_integer in Python, common::IsSafeInteger in C++, Common.IsSafeInteger in C#, Verification.isSafeInteger in Java and Number.isSafeInteger in TypeScript), generated if intermediate_uses.safe_integer_checks holds.

We accept a whole float such as 5.0 for an integer property.

The new live-test data and the generated unit tests cover the bounds in all SDKs. The generated tests set an unsafe integer at every integer property, and check that the verification and both serializations refuse it. We hence made no_seven_from in int_length_interplay check start against the bounds before it indexes, as an invariant would otherwise crash on count = -(2 ** 53).

The transpiled int(...) keeps checking the safe integer range, and we document why: TypeScript represents the integers as number, so all SDKs check the same range to behave the same.

We make the de/serialization of JSON-able values public in all SDKs so
that the aas-client3.2 implementations can use them, e.g.,
``json_value_from_jsonable`` in Python, ``JsonValueFromJsonable`` in Go,
``Deserialize.JsonValueFrom`` in C# and ``JsonValueFrom`` in C++.

A JSON number is read as a 64-bit float by the other SDKs, so we refuse
every integer outside the safe integer range [-2^53 + 1, 2^53 - 1]
consistently: for integer properties and in JSON-able values, in JSON
and XML de/serialization, in XML-RPC, in parsing with ``int`` and in
the verification. Once the verification passes, the serialization thus
works.

The bounds live in a single shared predicate per SDK, e.g., in Go:

    func IsSafeInteger(value int64) bool {
        return -9007199254740991 <= value && value <= 9007199254740991
    }

(``common.is_safe_integer`` in Python, ``common::IsSafeInteger`` in C++,
``Common.IsSafeInteger`` in C#, ``Verification.isSafeInteger`` in Java
and ``Number.isSafeInteger`` in TypeScript), generated if
``intermediate_uses.safe_integer_checks`` holds.

We accept a whole float such as ``5.0`` for an integer property.

The new live-test data and the generated unit tests cover the bounds in
all SDKs. The generated tests set an unsafe integer at every integer
property, and check that the verification and both serializations
refuse it. We hence made ``no_seven_from`` in ``int_length_interplay``
check ``start`` against the bounds before it indexes, as an invariant
would otherwise crash on ``count = -(2 ** 53)``.

The transpiled ``int(...)`` keeps checking the safe integer range, and
we document why: TypeScript represents the integers as ``number``, so
all SDKs check the same range to behave the same.
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 41355765637

Coverage increased (+0.1%) to 90.349%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: Could not be determined — this PR's diff is too large for GitHub to return (406 error at GitHub).
  • 451 coverage regressions across 21 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

451 previously-covered lines in 21 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
aas_core_codegen/java/lib/_generate_verification.py 51 91.04%
aas_core_codegen/csharp/lib/_generate_verification.py 49 91.17%
aas_core_codegen/python/lib/_generate_verification.py 43 91.29%
aas_core_codegen/golang/lib/_generate_verification.py 42 91.96%
aas_core_codegen/cpp/lib/_generate_verification.py 33 94.55%
aas_core_codegen/cpp/lib/_generate_jsonization.py 29 96.72%
aas_core_codegen/csharp/lib/_generate_jsonization.py 23 96.23%
aas_core_codegen/java/lib/_generate_jsonization.py 23 96.79%
aas_core_codegen/csharp/lib/_generate_xmlization.py 22 96.3%
aas_core_codegen/typescript/lib/_generate_verification.py 20 91.75%

Coverage Stats

Coverage Status
Relevant Lines: 52016
Covered Lines: 46996
Line Coverage: 90.35%
Coverage Strength: 2.71 hits per line

💛 - Coveralls

@mristin
mristin merged commit 7492e7e into main Nov 1, 2026
5 checks passed
@mristin
mristin deleted the mristin/Publish-JSON-values-and-check-safe-integers branch November 1, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants