IntegerSchema class final
Schema for validating JSON integer values.
JSON Schema defines an integer as any number with a zero fractional part.
Integral double inputs are therefore normalized to int when conversion
is lossless. Add .safe() when integers must remain exact on JavaScript.
- Inheritance
- Mixed-in types
- Available extensions
- Annotations
-
- @immutable
Constructors
-
IntegerSchema({bool isNullable = false, bool isOptional = false, String? description, List<
Constraint< constraints = const [], List<int> >Refinement< refinements = const []})int> > -
const
Properties
- acceptsNull → bool
-
Whether
parse(null)andencode(null)should accept null without raising a non-nullable failure. Defaults to isNullable; subclasses with branch-level null policies (e.g. AnyOfSchema) override this hook.no setterinherited - baseFieldsHashCode → int
-
Computes hash code for base schema fields.
no setterinherited
-
constraints
→ List<
Constraint< int> > -
Returns an unmodifiable view of the constraints for this schema.
no setterinherited
- description → String?
-
finalinherited
- hashCode → int
-
The hash code for this object.
no setteroverride
- isNullable → bool
-
finalinherited
- isOptional → bool
-
finalinherited
-
refinements
→ List<
Refinement< int> > -
Returns an unmodifiable view of the refinements for this schema.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- schemaType → SchemaType
-
The schema type category for this schema.
no setteroverride
- schemaTypeName → String
-
Human-readable type name for error messages and debugging.
no setterinherited
Methods
-
applyConstraintsAndRefinements(
int value, SchemaContext context) → SchemaResult< int> -
Applies constraints and refinements to a runtime value.
inherited
-
baseFieldsEqual(
AckSchema other) → bool -
Compares base schema fields for equality.
inherited
-
constrain(
Constraint< int> constraint, {String? message}) → IntegerSchema -
Adds a raw
constraintto the schema.inherited -
copyWith(
{bool? isNullable, bool? isOptional, String? description, List< Constraint< ? constraints, List<int> >Refinement< ? refinements}) → IntegerSchemaint> > -
Returns a copy of this schema with the given fields replaced.
override
-
describe(
String description) → IntegerSchema -
Sets the description for the schema.
inherited
-
encode(
int? value, {String? debugName}) → int? -
Encodes a runtime value to a boundary value, throwing on failure.
inherited
-
encodeAsBoundary(
int value, SchemaContext context) → SchemaResult< int> -
Helper for schemas whose boundary == runtime: validates the runtime
value and, if it passes, returns it as the boundary value unchanged.
Only safe to call when
BoundaryandRuntimeare the same type.inherited -
encodeWithContext(
int value, SchemaContext context) → SchemaResult< int> -
Encodes a runtime value into a boundary value. The base class strips
nullbefore calling this; subclasses receive a non-nullvalue.inherited -
failNonNullable(
SchemaContext context) → SchemaResult< int> -
Runtime-side non-nullable failure.
inherited
-
failNonNullableEncode(
SchemaContext context) → SchemaResult< int> -
Encode-side non-nullable failure.
inherited
-
greaterThan(
int n) → IntegerSchema -
Available on IntegerSchema, provided by the IntegerSchemaExtensions extension
Adds a constraint that the integer must be greater thann. -
handleNullInput(
Object? inputValue, SchemaContext context) → SchemaResult< int> ? -
Centralized null gate for the parse/validate paths. Returns null when
inputValueis non-null; otherwise returns Ok(null) if acceptsNull is true or a non-nullable failure.inherited -
lessThan(
int n) → IntegerSchema -
Available on IntegerSchema, provided by the IntegerSchemaExtensions extension
Adds a constraint that the integer must be less thann. -
max(
int n) → IntegerSchema -
Available on IntegerSchema, provided by the IntegerSchemaExtensions extension
Adds a constraint that the integer must be less than or equal ton. -
min(
int n) → IntegerSchema -
Available on IntegerSchema, provided by the IntegerSchemaExtensions extension
Adds a constraint that the integer must be greater than or equal ton. -
multipleOf(
int n) → IntegerSchema -
Available on IntegerSchema, provided by the IntegerSchemaExtensions extension
Adds a constraint that the integer must be a multiple ofn. -
negative(
) → IntegerSchema -
Available on IntegerSchema, provided by the IntegerSchemaExtensions extension
Adds a constraint that the integer must be negative (< 0). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
nullable(
{bool value = true}) → IntegerSchema -
Marks the schema as nullable.
inherited
-
optional(
{bool value = true}) → IntegerSchema -
Marks the schema as optional so the field can be omitted from an object.
inherited
-
parse(
Object? value, {String? debugName}) → int? -
Parses and validates a value, throwing an AckException if it fails.
inherited
-
parseAs<
TOut extends Object> (Object? value, TOut map(int? validated), {String? debugName}) → TOut -
Parses and validates a value, then maps the validated value to
TOut.inherited -
parseWithContext(
Object? value, SchemaContext context) → SchemaResult< int> -
Decodes a boundary value into a runtime value.
inherited
-
positive(
) → IntegerSchema -
Available on IntegerSchema, provided by the IntegerSchemaExtensions extension
Adds a constraint that the integer must be positive (> 0). -
refine(
bool validate(int value), {String message = 'The value did not pass the custom validation.'}) → IntegerSchema -
Adds a custom validation check that runs after all other validations.
inherited
-
safe(
) → IntegerSchema -
Available on IntegerSchema, provided by the IntegerSchemaExtensions extension
Adds a constraint that the integer must be a "safe" integer for use in environments like JavaScript. -
safeEncode(
int? value, {String? debugName}) → SchemaResult< int> -
Encodes a runtime value to a boundary value, returning a SchemaResult.
inherited
-
safeParse(
Object? value, {String? debugName}) → SchemaResult< int> -
Parses and validates a value, returning a SchemaResult.
inherited
-
safeParseAs<
TOut extends Object> (Object? value, TOut map(int? validated), {String? debugName}) → SchemaResult< TOut> -
Parses and validates a value, then maps the validated value to
TOut.inherited -
toJsonSchema(
) → Map< String, Object?> -
Converts this schema to a JSON Schema Draft-7 representation.
inherited
-
toMap(
) → Map< String, Object?> -
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
validateRuntimeWithContext(
Object? value, SchemaContext context) → SchemaResult< int> -
Validates that
valueis a valid runtime value for this schema.override -
withConstraint(
Constraint< int> constraint) → IntegerSchema -
Adds a validation constraint to the schema.
inherited
-
withConstraints(
List< Constraint< newConstraints) → IntegerSchemaint> > -
Adds a list of validation constraints to the schema.
inherited
-
withDefault(
int defaultValue) → DefaultSchema< int, int> -
Wraps this schema in a DefaultSchema that supplies
defaultValuewhen the parse input is null. Object encode also injects encoded defaults for missing default-wrapped fields.inherited -
withRuntimeConfig(
{bool? isNullable, bool? isOptional, String? description, List< Constraint< ? constraints, List<int> >Refinement< ? refinements}) → IntegerSchemaint> > -
Returns a copy of this schema with runtime-side configuration replaced.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override