katachi 0.0.1.3 → 0.0.1.4
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.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/docs/HASH_COMPARISON_DESIGN.md +3 -3
- data/lib/katachi/comparator.rb +5 -0
- data/lib/katachi/comparison_result.rb +2 -1
- data/lib/katachi/predefined_shapes.rb +2 -0
- data/lib/katachi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 883bae0ce10ea6f6788e55dd3dd26429da93b6514f3e098f84fef2d77e7c96a5
|
4
|
+
data.tar.gz: a944845c4d55b3dc54be12c3e8d0e80879c9ad00194f2e2afed6431e9a09bd3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17f01032afb9118fabd8235a8df89a569475fc6175d26d3c64fb857fa57fe4698faa2ee983f85defc5963651bbd4236fb5d00adc259ec38c1d686f96ad749b74
|
7
|
+
data.tar.gz: 4857e4aec605a1500cd4cc8f44cacc7c8d71e5313b1e1e8fecaa9f00a043f3ebff15cd25ef1999e65ea73e72ecc213081541bd110c1b3d4aa9c7ad9e34b06084
|
data/README.md
CHANGED
@@ -280,8 +280,7 @@ RESULT
|
|
280
280
|
- [ ] Shape-to-TypeScript conversion
|
281
281
|
- [ ] Shape-to-Zod conversion
|
282
282
|
- [ ] Shape-to-OpenAPI conversion
|
283
|
-
- [ ]
|
284
|
-
- [ ] `katachi-rspec-api` for testing+documenting APIs in a way inspired [RSwag](https://github.com/rswag/rswag)
|
283
|
+
- [ ] `katachi-rspec-api` for testing+documenting APIs in a way inspired by [RSwag](https://github.com/rswag/rswag)
|
285
284
|
|
286
285
|
## Installation
|
287
286
|
|
@@ -12,7 +12,7 @@ Here's the story of how they led to the design of Katachi's hash comparison:
|
|
12
12
|
OpenAPI has handled `null` values a few different ways over the years.
|
13
13
|
|
14
14
|
- OpenAPI 2.0 (Swagger) didn't support `null` values at all, so people used `x-nullable: true`
|
15
|
-
- OpenAPI 3.0
|
15
|
+
- OpenAPI 3.0 made this official by supporting `nullable: true`
|
16
16
|
- OpenAPI 3.1 found a much simpler way by treating `null` as a type: `type: ["string", "null"]`
|
17
17
|
|
18
18
|
I like the 3.1 approach of treating `null` as just another possible type.
|
@@ -140,7 +140,7 @@ Another problem with using `Object => Object` for extra keys is that it's means
|
|
140
140
|
|
141
141
|
If the comparison threw a `:hash_mismatch` when the user's hash didn't literally have a key-value pair `Object => Object`, that'd ruin that whole feature.
|
142
142
|
|
143
|
-
The lazy solution was to just ignore `Object => Object`, but what if users
|
143
|
+
The lazy solution was to just ignore `Object => Object`, but what if users want to be a bit stricter about their extra keys?
|
144
144
|
|
145
145
|
- `Symbol => String` is a normal data structure to enforce.
|
146
146
|
- `:$email => User` is an excellent description for a lookup hash.
|
@@ -231,7 +231,7 @@ But it makes for an awesome user experience :)
|
|
231
231
|
|
232
232
|
```ruby
|
233
233
|
shape = {
|
234
|
-
:$
|
234
|
+
:$uuid => {
|
235
235
|
email: :$email,
|
236
236
|
first_name: String,
|
237
237
|
last_name: String,
|
data/lib/katachi/comparator.rb
CHANGED
@@ -18,6 +18,7 @@ module Katachi::Comparator
|
|
18
18
|
retrieved_shape = Katachi::Shapes[shape]
|
19
19
|
return retrieved_shape.kt_compare(value) if retrieved_shape.respond_to?(:kt_compare)
|
20
20
|
return compare_equalities(value:, shape: retrieved_shape) if retrieved_shape.is_a?(Proc)
|
21
|
+
return object_class_universal_match(value:) if retrieved_shape == Object
|
21
22
|
|
22
23
|
case value
|
23
24
|
when Array then compare_array(value:, shape: retrieved_shape)
|
@@ -40,4 +41,8 @@ module Katachi::Comparator
|
|
40
41
|
end
|
41
42
|
Katachi::ComparisonResult.new(value:, shape:, code:)
|
42
43
|
end
|
44
|
+
|
45
|
+
private_class_method def self.object_class_universal_match(value:)
|
46
|
+
Katachi::ComparisonResult.new(value:, shape: Object, code: :object_class_universal_match)
|
47
|
+
end
|
43
48
|
end
|
@@ -9,10 +9,11 @@ class Katachi::ComparisonResult
|
|
9
9
|
# For example, :match is considered a match, while :mismatch is not.
|
10
10
|
CODES = {
|
11
11
|
# General
|
12
|
+
class_mismatch: false,
|
12
13
|
exact_match: true,
|
13
14
|
match: true,
|
14
15
|
mismatch: false,
|
15
|
-
|
16
|
+
object_class_universal_match: true,
|
16
17
|
# AnyOf
|
17
18
|
any_of_match: true,
|
18
19
|
any_of_mismatch: false,
|
data/lib/katachi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katachi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Tannas
|
@@ -17,7 +17,7 @@ description: |
|
|
17
17
|
Example usage:
|
18
18
|
|
19
19
|
shape = {
|
20
|
-
:$
|
20
|
+
:$uuid => {
|
21
21
|
email: :$email,
|
22
22
|
first_name: String,
|
23
23
|
last_name: String,
|