Skip to content

Conversation

@leoafarias
Copy link
Collaborator

Summary

Add proper ==() and hashCode implementations to all AckSchema and Constraint classes. Schemas were marked @immutable but relied on identity equality, breaking their use as Map keys and in Sets. This also fixes UniqueItemsConstraint, which depends on value equality for detecting duplicate objects in lists.

Changes

  • Implement equality in 12 concrete schema classes and base class helpers
  • Implement equality in 9 constraint classes and validators
  • Add 62 comprehensive tests for equality semantics across all types

Testing

All 905 existing tests pass plus 62 new equality tests covering schemas as Map keys/Set members and copyWith() preserving equality.

…ints

Add proper ==() and hashCode implementations to all AckSchema classes and
Constraint classes. This enables schemas to work correctly as Map keys,
in Sets, and fixes UniqueItemsConstraint for detecting duplicate objects.
All schemas are @immutable but were using identity equality; now they use
value-based equality matching their configuration. Includes comprehensive
test coverage for equality semantics across all schema and constraint types.
@docs-page
Copy link

docs-page bot commented Jan 14, 2026

To view this pull requests documentation preview, visit the following URL:

docs.page/btwld/ack~63

Documentation is deployed and generated using docs.page.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements value-based equality for all schema and constraint classes in the Ack validation library. Previously, schemas marked as @immutable relied on identity equality (the default for Dart objects), which prevented their use as Map keys or Set members and caused issues with the UniqueItemsConstraint when detecting duplicate objects in lists.

Changes:

  • Implemented ==() and hashCode in 12 concrete schema classes (StringSchema, IntegerSchema, DoubleSchema, BooleanSchema, ListSchema, ObjectSchema, AnyOfSchema, DiscriminatedObjectSchema, EnumSchema, AnySchema, TransformedSchema, TestUnsupportedAckSchema)
  • Implemented ==() and hashCode in 9 constraint classes (ComparisonConstraint, PatternConstraint, StringLiteralConstraint, DateTimeConstraint, StringIpConstraint, InvalidTypeConstraint, ObjectNoAdditionalPropertiesConstraint, ObjectRequiredPropertiesConstraint, _EnumValuesConstraint)
  • Added helper methods baseFieldsEqual() and baseFieldsHashCode in the base AckSchema class for consistent comparison of common fields
  • Added base ==() and hashCode implementation in the Constraint base class
  • Added 62 comprehensive tests covering equality semantics, Set/Map operations, and edge cases

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/ack/lib/src/schemas/schema.dart Added base equality helper methods and imported collection package for ListEquality/MapEquality
packages/ack/lib/src/schemas/string_schema.dart Implemented equality comparing strictPrimitiveParsing field
packages/ack/lib/src/schemas/num_schema.dart Implemented equality for IntegerSchema and DoubleSchema
packages/ack/lib/src/schemas/boolean_schema.dart Implemented equality comparing strictPrimitiveParsing field
packages/ack/lib/src/schemas/list_schema.dart Implemented equality comparing itemSchema
packages/ack/lib/src/schemas/object_schema.dart Implemented equality comparing properties map and additionalProperties
packages/ack/lib/src/schemas/any_of_schema.dart Implemented equality comparing schemas list
packages/ack/lib/src/schemas/discriminated_object_schema.dart Implemented equality comparing discriminatorKey and schemas map
packages/ack/lib/src/schemas/enum_schema.dart Implemented equality comparing values list and for _EnumValuesConstraint
packages/ack/lib/src/schemas/any_schema.dart Implemented equality using only base fields
packages/ack/lib/src/schemas/transformed_schema.dart Implemented equality comparing schema and using identical() for transformer
packages/ack/lib/src/schemas/testing/testing_schemas.dart Implemented equality for TestUnsupportedAckSchema
packages/ack/lib/src/constraints/constraint.dart Added base equality implementation comparing constraintKey and description
packages/ack/lib/src/constraints/comparison_constraint.dart Implemented equality comparing type, threshold, maxThreshold, and multipleValue
packages/ack/lib/src/constraints/pattern_constraint.dart Implemented equality comparing pattern.pattern, type, allowedValues, and example
packages/ack/lib/src/constraints/string_literal_constraint.dart Implemented equality comparing expectedValue
packages/ack/lib/src/constraints/string_ip_constraint.dart Implemented equality comparing version
packages/ack/lib/src/constraints/datetime_constraint.dart Implemented equality comparing type and reference
packages/ack/lib/src/constraints/validators.dart Implemented equality for InvalidTypeConstraint, ObjectNoAdditionalPropertiesConstraint, and ObjectRequiredPropertiesConstraint
packages/ack/lib/src/constraints/number_finite_constraint.dart Added comment indicating base class equality is sufficient
packages/ack/lib/src/constraints/number_safe_integer_constraint.dart Added comment indicating base class equality is sufficient
packages/ack/lib/src/constraints/list_unique_items_constraint.dart Added comment indicating base class equality is sufficient
packages/ack/test/schemas/schema_equality_test.dart Added 62 tests covering schema equality for all types, Set/Map operations, refinements, and defaults
packages/ack/test/constraints/constraint_equality_test.dart Added comprehensive tests for constraint equality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tilucasoli tilucasoli merged commit b4e0e8f into main Jan 14, 2026
8 checks passed
@tilucasoli tilucasoli deleted the feat/schema-equality-semantics branch January 14, 2026 18:48
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.

3 participants