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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c27dabeb33b1644739f90d7bbac22dfe85ae79d742da8376cad64bdfff46c514
4
- data.tar.gz: 5b4df5b8215933c70fd3c04fd3a8cd74c0ff7bdfe4919110f95753348ce28726
3
+ metadata.gz: c2dead9a036c0d9322c68b50938417ebe12a4b62ed2f99a8ae6d4f49f894dabd
4
+ data.tar.gz: ac3b386e3266e8498aa62549cddfbaece9414281beee5710c1930b062eaacde8
5
5
  SHA512:
6
- metadata.gz: 9111228ae652344f54044d93fd7516d67cdefa0789587b786d58291d40f9c61c009207c5b3ef68d7302e8e889a125e51fbd4bfa3a5ee6b8b2629a2e06cf7a538
7
- data.tar.gz: bc1701018a9c35fb618c92a50fb4d68f24957f3d22431e343457dba65645d6476a5c7378620fe934b8520cfd20d62a2d2de1ac5c04af1f0130dfba5de86cb2f9
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
- attr_reader :root
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 initialize(...)
21
- super
22
- flat_left = left.flatten
23
- flat_right = right.flatten
24
- @root = [*flat_left, *flat_right].map(&:_path).reduce(:&)
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
- [MessageSet.new(left).to_h, MessageSet.new(right).to_h]
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 right.is_a?(Array)
21
- if left.is_a?(Array) && paths.uniq.size > 1
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = "1.9.2"
5
+ VERSION = "1.9.3"
6
6
  end
7
7
  end
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.2
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-05-28 00:00:00.000000000 Z
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.2.32
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
- ...