Repository navigation
feat(schema): bounded 32-bit numeric schemas - #934
Merged
Merged
Conversation
Add Int32, NonNegativeInt32, PositiveInt32, NonNegativeNumber32 and PositiveNumber32 with runtime-enforced Java Integer / binary32 ranges and matching JSON Schema / OpenAPI bounds and formats. Make flattenSimpleAllOf intersect repeated bounds instead of overwriting them.
@effect-app/cli
effect-app
@effect-app/eslint-codegen-model
@effect-app/eslint-shared-config
@effect-app/infra
@effect-app/vue
@effect-app/vue-components
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Int,PositiveIntandNonNegativeIntaccept the full JavaScript safe-integer range and exporttype: integer,maximum: 9007199254740991without aformat. OpenAPI Generator's Java client (7.27.0, bean validation) maps them toIntegerand emits the unsuffixed literal@Max(9007199254740991), whichjavacrejects withinteger number too large(anLsuffix would compile, since@Max.value()islong, but would still advertise a rangeIntegercannot hold); and the runtime still accepts values a JavaIntegerconsumer cannot represent. There was no bounded alternative for the number family either.What
Additive 32-bit counterparts for the complete numeric family in
effect-app/Schema(existing schemas unchanged):Int32[-2147483648, 2147483647]integer, min/max,format: int320IntNonNegativeInt32[0, 2147483647]integer,minimum: 0, max,int320Int32,NonNegativeInt,NonNegativeNumber32PositiveInt32[1, 2147483647]integer,minimum: 1, max,int321NonNegativeInt32,PositiveInt,PositiveNumber32NonNegativeNumber32[0, 3.4028235e38]number, min/max,format: float0NonNegativeNumberPositiveNumber32[1.4e-45, 3.4028235e38]number, min/max,float1NonNegativeNumber32,PositiveNumberAlso exported:
INT32_MIN,INT32_MAX,FLOAT32_MIN_POSITIVE = 1.4e-45andFLOAT32_MAX = 3.4028235e38: the literals Java writes forFloat.MIN_VALUE/Float.MAX_VALUE, so the server accepts Java's own extremes. They round to the exact binary32 extremes2^-149and(2-2^-23)*2^127.The deprecated
PositiveDecimal/NonNegativeDecimalaliases get no 32-bit counterpart: they are deprecated aliases of the Number schemas, so theNumber32schemas cover them.flattenSimpleAllOfnow intersects repeated bounds and keeps theallOfon other conflicting validation keywords. Before, the lastallOfmember overwrote the parent, e.g.S.Number.check(S.isInt32(), S.isGreaterThanOrEqualTo(0))exportedminimum: -2147483648.How
S.Int+ the existing lower-bound check +isLessThanOrEqualTo(INT32_MAX), whose JSON Schema also carriesformat: "int32", so Effect inlines it and tightens the safe-integer bounds.S.Finite+ the lower-bound check +isLessThanOrEqualTo(FLOAT32_MAX)withformat: "float". These are range checks only: values are not rounded to binary32, and fractions stay as they are. Values aboveFLOAT32_MAXare rejected, so nothing that overflows toInfinityis accepted. This is conservative: the double-only sliver up to the rounding threshold is also rejected.PositiveNumber32rejects values belowFLOAT32_MIN_POSITIVE, so nothing that underflows to0is accepted.NonNegativeNumber32accepts those tiny values, because underflowing to0keeps them non-negative.schema(n)), construction-onlywithConstructorDefaultand Arbitrary conventions as the existing schemas.numbers32.test.ts): both boundaries and the values just beyond them, zero, negatives, fractions,NaN/Infinityfor decode, encode and make; Arbitrary samples; defaults; brand assignability; exact JSON Schema and deduplicated OpenAPI components next to the existingInt/PositiveInt/NonNegativeInt; theflattenSimpleAllOfregression.Remarks
-g java --library native,useBeanValidation=true,useJakartaEe=true, JDK 21.0.12mvn compile. The input was an OpenAPI 3.1 doc fromOpenApi.fromApi+deduplicateOpenApiSchemaswith aClassmodel using all five new schemas, plus optional, nullable and array-item variants. Result:Integer/Floatfields with@Min(-2147483648|0|1) @Max(2147483647)and@DecimalMin("1.4E-45"|"0") @DecimalMax("340282350000000000000000000000000000000"); compiled. Control: the same doc with the existingPositiveInt/NonNegativeIntfails withinteger number too large. Not covered: other generators/libraries and runtime bean validation.PositiveInt32uses>= 1instead of> 0(same integer set) because the generator turns 3.1exclusiveMinimum: 0into@Min(0), which would accept0.effect-apppackage group.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.