easy_talk 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +15 -43
  3. data/CHANGELOG.md +89 -0
  4. data/README.md +447 -2115
  5. data/docs/json_schema_compliance.md +140 -26
  6. data/docs/primitive-schema-rfc.md +894 -0
  7. data/lib/easy_talk/builders/base_builder.rb +2 -1
  8. data/lib/easy_talk/builders/boolean_builder.rb +2 -1
  9. data/lib/easy_talk/builders/collection_helpers.rb +4 -0
  10. data/lib/easy_talk/builders/composition_builder.rb +7 -2
  11. data/lib/easy_talk/builders/integer_builder.rb +2 -1
  12. data/lib/easy_talk/builders/null_builder.rb +4 -1
  13. data/lib/easy_talk/builders/number_builder.rb +4 -1
  14. data/lib/easy_talk/builders/object_builder.rb +64 -3
  15. data/lib/easy_talk/builders/registry.rb +15 -1
  16. data/lib/easy_talk/builders/string_builder.rb +3 -1
  17. data/lib/easy_talk/builders/temporal_builder.rb +7 -0
  18. data/lib/easy_talk/builders/tuple_builder.rb +89 -0
  19. data/lib/easy_talk/builders/typed_array_builder.rb +4 -2
  20. data/lib/easy_talk/builders/union_builder.rb +5 -1
  21. data/lib/easy_talk/configuration.rb +17 -2
  22. data/lib/easy_talk/errors.rb +1 -0
  23. data/lib/easy_talk/errors_helper.rb +3 -0
  24. data/lib/easy_talk/json_schema_equality.rb +46 -0
  25. data/lib/easy_talk/keywords.rb +0 -1
  26. data/lib/easy_talk/model.rb +27 -1
  27. data/lib/easy_talk/model_helper.rb +4 -0
  28. data/lib/easy_talk/naming_strategies.rb +4 -0
  29. data/lib/easy_talk/property.rb +7 -0
  30. data/lib/easy_talk/ref_helper.rb +6 -0
  31. data/lib/easy_talk/schema.rb +1 -0
  32. data/lib/easy_talk/schema_definition.rb +52 -6
  33. data/lib/easy_talk/schema_methods.rb +36 -5
  34. data/lib/easy_talk/sorbet_extension.rb +1 -0
  35. data/lib/easy_talk/type_introspection.rb +45 -1
  36. data/lib/easy_talk/types/tuple.rb +77 -0
  37. data/lib/easy_talk/validation_adapters/active_model_adapter.rb +350 -62
  38. data/lib/easy_talk/validation_adapters/active_model_schema_validation.rb +106 -0
  39. data/lib/easy_talk/validation_adapters/base.rb +12 -0
  40. data/lib/easy_talk/validation_adapters/none_adapter.rb +9 -0
  41. data/lib/easy_talk/validation_builder.rb +1 -0
  42. data/lib/easy_talk/version.rb +1 -1
  43. data/lib/easy_talk.rb +1 -0
  44. metadata +13 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b77760f0bdffbb877509e133194733d397db6e5963b1484543791169db5dc840
4
- data.tar.gz: 6e805469940229543c059952dc2311dd9acf7ea89ff45fde8b49b3e4d38dd85d
3
+ metadata.gz: 3f11b7be6e0fa32087d5be57be3d3e37d5bd5b96cc61ae8626b33d41a420e401
4
+ data.tar.gz: 82ba98f220e8e75e3bb3e208a595a168f188c226a130e88f13991da9a386cfc6
5
5
  SHA512:
6
- metadata.gz: 5bf66646040995f9de8341e2a4e6ea63ae0c462a0f08f28779244e8eceff958e574042450a9a39cc2ef485e13d6c418e5f71296d6d8cc7e958339f432e84c572
7
- data.tar.gz: 4c26c3bee7751682535f154efef1c4adb86cea08be6c6f09f9ebe08d6a2fde5604d71db884aa7f0de91787118f5bbb719028f8071ec4166ba69af7ad0d9b4ff1
6
+ metadata.gz: 90fb93ef486adb8151e883e6929437be2f52bdbe4a51bb45485006884a983b80ce9f10de1d14b313031be4b8126d6fe21c3bd54a998863543a1be1d752c124d9
7
+ data.tar.gz: 2ff9102ba57ae6738cb79511fdd095b5f798a760c009b10d2b5577c30575f04d94dfb11e410036e566971d92e27e2c4bc2d17336e44c64f9d35b966bbe1b4960
data/.rubocop.yml CHANGED
@@ -1,7 +1,3 @@
1
- plugins:
2
- - rubocop-rspec
3
- - rubocop-rake
4
-
5
1
  AllCops:
6
2
  NewCops: enable
7
3
  TargetRubyVersion: 3.2
@@ -33,6 +29,8 @@ Style/StringLiterals:
33
29
 
34
30
  Metrics/ClassLength:
35
31
  Max: 240
32
+ Exclude:
33
+ - lib/easy_talk/validation_adapters/active_model_adapter.rb
36
34
 
37
35
  Metrics/MethodLength:
38
36
  Max: 60
@@ -55,6 +53,7 @@ Metrics/BlockNesting:
55
53
  Metrics/BlockLength:
56
54
  Exclude:
57
55
  - spec/**/*
56
+ - easy_talk.gemspec
58
57
 
59
58
  Layout/EndAlignment:
60
59
  Enabled: false
@@ -70,45 +69,6 @@ Lint/EmptyBlock:
70
69
  Exclude:
71
70
  - spec/**/*
72
71
 
73
- RSpec/DescribeClass:
74
- Enabled: false
75
-
76
- RSpec/LeakyConstantDeclaration:
77
- Enabled: false
78
-
79
- RSpec/RemoveConst:
80
- Enabled: false
81
-
82
- RSpec/BeforeAfterAll:
83
- Enabled: false
84
-
85
- RSpec/NestedGroups:
86
- Max: 4
87
-
88
- RSpec/RepeatedDescription:
89
- Enabled: false
90
-
91
- RSpec/PendingWithoutReason:
92
- Enabled: false
93
-
94
- RSpec/MultipleDescribes:
95
- Enabled: false
96
-
97
- RSpec/ContextWording:
98
- Enabled: false
99
-
100
- RSpec/MultipleMemoizedHelpers:
101
- Max: 10
102
-
103
- RSpec/ExampleLength:
104
- Max: 40
105
-
106
- RSpec/MultipleExpectations:
107
- Max: 10
108
-
109
- RSpec/SpecFilePathFormat:
110
- Enabled: false
111
-
112
72
  Lint/DuplicateBranch:
113
73
  Enabled: false
114
74
 
@@ -118,3 +78,15 @@ Gemspec/DevelopmentDependencies:
118
78
  Naming/PredicateMethod:
119
79
  Exclude:
120
80
  - spec/support/schema_validation_matcher.rb
81
+
82
+ Naming/BlockForwarding:
83
+ Enabled: false
84
+
85
+ Lint/UnusedMethodArgument:
86
+ AllowUnusedKeywordArguments: true
87
+ Exclude:
88
+ - lib/easy_talk/configuration.rb
89
+ - lib/easy_talk/schema_definition.rb
90
+
91
+ Style/DefWithParentheses:
92
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,92 @@
1
+ ## [3.3.0] - 2026-01-12
2
+
3
+ ### Added
4
+
5
+ - **Schema Objects in additionalProperties**: Extended `additionalProperties` to support type constraints and schema objects (#160)
6
+ - New syntax: `additional_properties Integer, minimum: 0, maximum: 100`
7
+ - Three supported forms: boolean, type class, or type with constraints
8
+ - Generates full JSON Schema for additional properties validation
9
+ - New methods: `ObjectBuilder#process_additional_properties`, `ObjectBuilder#build_additional_properties_schema`
10
+ - Fully backwards compatible with existing boolean usage
11
+
12
+ - **External $ref Support via $id**: Enhanced schema referencing with external URI support (#158)
13
+ - New configuration options:
14
+ - `base_schema_uri` - Base URI for auto-generating $id values
15
+ - `auto_generate_ids` - Enable automatic $id generation (default: false)
16
+ - `prefer_external_refs` - Use external URI in $ref when model has $id (default: false)
17
+ - Three-level schema ID resolution: explicit per-model → auto-generated → global
18
+ - Dynamic $ref templates conditionally use external URIs or local `#/$defs/ModelName` format
19
+ - Supports composition types (T::OneOf, T::AnyOf, T::AllOf) with external refs
20
+
21
+ - **T::Tuple Type for Positional Array Validation**: New tuple type for JSON Schema tuple support (#154, #155)
22
+ - New syntax: `property :coords, T::Tuple[Float, Float]`
23
+ - Generates JSON Schema with `items` as array of schemas
24
+ - Supports `additional_items: false`, `true`, or a type constraint
25
+ - Combines with array constraints: `min_items`, `max_items`, `unique_items`
26
+ - ActiveModel validation for runtime type checking at each position
27
+ - New files: `lib/easy_talk/types/tuple.rb`, `lib/easy_talk/builders/tuple_builder.rb`
28
+
29
+ - **Object-Level JSON Schema Keywords**: Support for schema-wide object constraints (#148, #151)
30
+ - New keywords: `patternProperties`, `minProperties`, `maxProperties`, `dependencies`, `dependentRequired`
31
+ - ActiveModel validators for object-level constraints via `ActiveModelSchemaValidation` module
32
+ - Auto-defined `count_present_properties` private method on model classes
33
+ - Thread-safe validator application with double-checked locking
34
+
35
+ ### Changed
36
+
37
+ - **Format Validation Enhancements**: Improved format validation accuracy and security (#157, #156, #144)
38
+ - **Scope Fix**: Format and pattern validations now only apply to string values (per JSON Schema spec)
39
+ - **URI/URL Validation**: Uses `URI.parse()` with `.absolute?` check instead of regex
40
+ - **Parsing-Based Validators**: Date, DateTime, and Time formats now use parsing instead of regex
41
+ - **Email Validation**: Replaced ReDoS-vulnerable regex with simple linear-time pattern
42
+ - New validation methods: `apply_uri_format_validation`, `apply_date_format_validation`, `apply_datetime_format_validation`, `apply_time_format_validation`
43
+
44
+ - **JSON Schema Equality for uniqueItems**: Implements correct JSON Schema equality semantics for array uniqueness (#152)
45
+ - Objects with same keys/values in different order are equal
46
+ - Numbers are mathematically equal (1 == 1.0)
47
+ - Type matters for non-numbers (true != 1, false != 0)
48
+ - New module: `EasyTalk::JsonSchemaEquality` with `normalize()` and `duplicates?()` methods
49
+ - MAX_DEPTH = 100 limit to prevent SystemStackError on deeply nested structures
50
+
51
+ - **Array Presence Validation**: Required array properties now properly reject nil values (#140)
52
+ - New method: `apply_array_presence_validation()` for array-specific nil checks
53
+ - Rejects nil but allows empty arrays `[]`
54
+ - Aligns with JSON Schema spec: 'optional' means property can be omitted, not that nil is accepted
55
+
56
+ ### Fixed
57
+
58
+ - **Default Additional Properties Configuration**: Fixed `default_additional_properties` config option being ignored (#142)
59
+ - Both `ObjectBuilder` and `SchemaDefinition` now use configured default
60
+ - Added schema hash duplication to prevent mutation side effects
61
+
62
+ - **Property Name Validation**: Fixed validation incorrectly applying to JSON output name (`:as` constraint) instead of Ruby property name (#143)
63
+ - `validate_property_name()` now validates Ruby name only
64
+ - Allows using `:as` for JSON-LD (@type, @id), JSON Schema ($id, $ref), and other special JSON keys
65
+
66
+ - **Method Redefinition Warning**: Fixed "method redefined" warning for `:property` keyword (#153)
67
+ - Removed `:property` from `KEYWORDS` constant since it has dedicated implementation
68
+
69
+ ### Internal
70
+
71
+ - **Type Introspection Improvements**: Enhanced type checking capabilities (#156)
72
+ - New helper methods: `array_type?()`, `boolean_union_type?()`, extracted `boolean_type?()`
73
+ - Improved encapsulation and testability
74
+
75
+ - **ValidationContext Decoupling**: Refactored validation adapter internals (#150)
76
+ - New plain data class `ValidationContext` for pre-computed validation values
77
+ - Replaces `__send__` usage with direct value passing
78
+ - Improved encapsulation and testability
79
+
80
+ - **Code Coverage Integration**: Added SimpleCov and Codecov for test coverage tracking
81
+ - Local HTML reports via SimpleCov
82
+ - CI badge reporting via Codecov
83
+ - Coverage uploads on Ruby 3.4.7 builds only
84
+
85
+ - **Test Infrastructure**: Comprehensive test expansion (~1800 lines of new tests)
86
+ - New test files: `external_ref_spec.rb`, `additional_properties_schema_spec.rb`, `tuple_validation_spec.rb`, `json_schema_equality_spec.rb`
87
+ - Enhanced builder test coverage
88
+ - Improved JSON Schema compliance testing
89
+
1
90
  ## [3.2.0] - 2025-12-28
2
91
 
3
92
  ### Added