dry-schema 1.9.2 → 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/dry/schema/extensions/json_schema/schema_compiler.rb +12 -0
- data/lib/dry/schema/message/or/multi_path.rb +73 -13
- data/lib/dry/schema/message/or.rb +2 -2
- data/lib/dry/schema/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2dead9a036c0d9322c68b50938417ebe12a4b62ed2f99a8ae6d4f49f894dabd
|
4
|
+
data.tar.gz: ac3b386e3266e8498aa62549cddfbaece9414281beee5710c1930b062eaacde8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0831055ac93da2898c55b6194703e87bda1c27040ac23965c5f261c2e59387888f679b9dcd967a4a0665cef220b7c97db823670067267b34b40ed09a3c315b81'
|
7
|
+
data.tar.gz: d82ee10469742e83ee412ebe6c06593a86c44c1e0f01fd29067700d9a37ecc461dc3e4ad6e2a09bfe4694d1e95b6c28132810bf243d27338257f66e0c50cc98e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 1.9.3 2022-06-23
|
4
|
+
|
5
|
+
|
6
|
+
### Added
|
7
|
+
|
8
|
+
- Support `anyOf` composition in JSON schema output (@robhanlon22)
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
- Allow composition of multiple ors (issue #307 fixed via #409) (@robhanlon22)
|
13
|
+
|
14
|
+
|
15
|
+
[Compare v1.9.2...v1.9.3](https://github.com/dry-rb/dry-schema/compare/v1.9.2...v1.9.3)
|
16
|
+
|
3
17
|
## 1.9.2 2022-05-28
|
4
18
|
|
5
19
|
|
@@ -114,6 +114,18 @@ module Dry
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
+
# @api private
|
118
|
+
def visit_or(node, opts = EMPTY_HASH)
|
119
|
+
node.each do |child|
|
120
|
+
c = self.class.new(loose: loose?)
|
121
|
+
c.keys.update(subschema: {})
|
122
|
+
c.visit(child, opts.merge(key: :subschema))
|
123
|
+
|
124
|
+
any_of = (keys[opts[:key]][:anyOf] ||= [])
|
125
|
+
any_of << c.keys[:subschema]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
117
129
|
# @api private
|
118
130
|
def visit_implication(node, opts = EMPTY_HASH)
|
119
131
|
node.each do |el|
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "dry/core/equalizer"
|
4
|
-
|
5
3
|
require "dry/schema/message/or/abstract"
|
6
4
|
require "dry/schema/path"
|
7
5
|
|
@@ -14,23 +12,85 @@ module Dry
|
|
14
12
|
# @api public
|
15
13
|
class MultiPath < Abstract
|
16
14
|
# @api private
|
17
|
-
|
15
|
+
class MessageArray
|
16
|
+
# @api private
|
17
|
+
def initialize(messages)
|
18
|
+
@messages = messages.flatten
|
19
|
+
end
|
20
|
+
|
21
|
+
# @api private
|
22
|
+
def _paths
|
23
|
+
@messages.map(&:_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @api private
|
27
|
+
def to_or(root)
|
28
|
+
self.class.new(@messages.map { _1.to_or(root) })
|
29
|
+
end
|
30
|
+
|
31
|
+
# @api private
|
32
|
+
def to_h
|
33
|
+
MessageSet.new(@messages).to_h
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# @api private
|
38
|
+
def self.handler(message)
|
39
|
+
handlers.find { |k,| message.is_a?(k) }&.last
|
40
|
+
end
|
18
41
|
|
19
42
|
# @api private
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@left = flat_left.map { _1.to_or(root) }
|
26
|
-
@right = flat_right.map { _1.to_or(root) }
|
43
|
+
private_class_method def self.handlers
|
44
|
+
@handlers ||= {
|
45
|
+
self => -> { _1 },
|
46
|
+
Array => -> { MessageArray.new(_1) }
|
47
|
+
}.freeze
|
27
48
|
end
|
28
49
|
|
29
50
|
# @api public
|
30
51
|
def to_h
|
31
|
-
@to_h ||= Path[[*root, :or]].to_h(
|
32
|
-
|
33
|
-
|
52
|
+
@to_h ||= Path[[*root, :or]].to_h(messages.map(&:to_h))
|
53
|
+
end
|
54
|
+
|
55
|
+
# @api private
|
56
|
+
def messages
|
57
|
+
@messages ||= _messages.flat_map { _1.to_or(root) }
|
58
|
+
end
|
59
|
+
|
60
|
+
# @api private
|
61
|
+
def root
|
62
|
+
@root ||= _messages.flat_map(&:_paths).reduce(:&)
|
63
|
+
end
|
64
|
+
|
65
|
+
# @api private
|
66
|
+
def path
|
67
|
+
root
|
68
|
+
end
|
69
|
+
|
70
|
+
# @api private
|
71
|
+
def _paths
|
72
|
+
@paths ||= [Path[root]]
|
73
|
+
end
|
74
|
+
|
75
|
+
# @api private
|
76
|
+
def to_or(root)
|
77
|
+
self.root == root ? messages : [self]
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
# @api private
|
83
|
+
def _messages
|
84
|
+
@_messages ||= [left, right].map do |message|
|
85
|
+
handler = self.class.handler(message)
|
86
|
+
|
87
|
+
unless handler
|
88
|
+
raise ArgumentError,
|
89
|
+
"#{message.inspect} is of unknown type #{message.class.inspect}"
|
90
|
+
end
|
91
|
+
|
92
|
+
handler.(message)
|
93
|
+
end
|
34
94
|
end
|
35
95
|
end
|
36
96
|
end
|
@@ -17,8 +17,8 @@ module Dry
|
|
17
17
|
|
18
18
|
if paths.uniq.size == 1
|
19
19
|
SinglePath.new(left, right, messages)
|
20
|
-
elsif
|
21
|
-
if
|
20
|
+
elsif MultiPath.handler(right)
|
21
|
+
if MultiPath.handler(left) && paths.uniq.size > 1
|
22
22
|
MultiPath.new(left, right)
|
23
23
|
else
|
24
24
|
right
|
data/lib/dry/schema/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -240,7 +240,7 @@ metadata:
|
|
240
240
|
changelog_uri: https://github.com/dry-rb/dry-schema/blob/main/CHANGELOG.md
|
241
241
|
source_code_uri: https://github.com/dry-rb/dry-schema
|
242
242
|
bug_tracker_uri: https://github.com/dry-rb/dry-schema/issues
|
243
|
-
post_install_message:
|
243
|
+
post_install_message:
|
244
244
|
rdoc_options: []
|
245
245
|
require_paths:
|
246
246
|
- lib
|
@@ -255,9 +255,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
255
255
|
- !ruby/object:Gem::Version
|
256
256
|
version: '0'
|
257
257
|
requirements: []
|
258
|
-
rubygems_version: 3.
|
259
|
-
signing_key:
|
258
|
+
rubygems_version: 3.1.6
|
259
|
+
signing_key:
|
260
260
|
specification_version: 4
|
261
261
|
summary: Coercion and validation for data structures
|
262
262
|
test_files: []
|
263
|
-
...
|