dry-schema 1.9.0 → 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: 630c8c7019a02d6f22386ef4ac1ca68321af93bd3a5e34f8b62b21d28a7eee69
4
- data.tar.gz: e53baa861af349395446deb0183e7358438e4ca4ea7fa78b25d4c4f04e4ea2a5
3
+ metadata.gz: c2dead9a036c0d9322c68b50938417ebe12a4b62ed2f99a8ae6d4f49f894dabd
4
+ data.tar.gz: ac3b386e3266e8498aa62549cddfbaece9414281beee5710c1930b062eaacde8
5
5
  SHA512:
6
- metadata.gz: 2ed11d1eba31d808c75018d5ea78fc649f4f59486c2047554aeabac5cd71e9b2d6e64b88661c8f0615b9a9402c177d2c51f49cd49e3ae6e697c45f9f952dab18
7
- data.tar.gz: 5c085c4994f662a44eb372e92a894c76d83eefdce88389ed6c1947004c7bd39204b843ea5eb408af86ad986e6978dde67227b9bdcf7d888d1a8e277b457c4345
6
+ metadata.gz: '0831055ac93da2898c55b6194703e87bda1c27040ac23965c5f261c2e59387888f679b9dcd967a4a0665cef220b7c97db823670067267b34b40ed09a3c315b81'
7
+ data.tar.gz: d82ee10469742e83ee412ebe6c06593a86c44c1e0f01fd29067700d9a37ecc461dc3e4ad6e2a09bfe4694d1e95b6c28132810bf243d27338257f66e0c50cc98e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
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
+
17
+ ## 1.9.2 2022-05-28
18
+
19
+
20
+ ### Fixed
21
+
22
+ - Fix loose JSON schemas for nested hashes (via #401) (@tomdalling)
23
+ - Correct spelling error 'mininum' to 'minimum' in json-schema extension (via #404) (@svenanderzen)
24
+
25
+ ### Changed
26
+
27
+ - [performance] YAML message backend allocates less strings (via #399) (@casperisfine)
28
+
29
+ [Compare v1.9.1...v1.9.2](https://github.com/dry-rb/dry-schema/compare/v1.9.1...v1.9.2)
30
+
31
+ ## 1.9.1 2022-02-17
32
+
33
+
34
+ ### Fixed
35
+
36
+ - Namespaced messages no longer crashes in certain scenarios (see dry-rb/dry-validation#692 fixed via #398) (@krekoten)
37
+
38
+
39
+ [Compare v1.9.0...v1.9.1](https://github.com/dry-rb/dry-schema/compare/v1.9.0...v1.9.1)
40
+
3
41
  ## 1.9.0 2022-02-15
4
42
 
5
43
 
@@ -136,7 +174,7 @@ This release ships with a bunch of internal refactorings that should improve per
136
174
  - Key validation works correctly with a non-nested maybe hashes (issue #311 fixed via #312) (@svobom57)
137
175
 
138
176
 
139
- [Compare v1.5.3...master](https://github.com/dry-rb/dry-schema/compare/v1.5.3...master)
177
+ [Compare v1.5.3...main](https://github.com/dry-rb/dry-schema/compare/v1.5.3...main)
140
178
 
141
179
  ## 1.5.3 2020-08-21
142
180
 
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  [![CI Status](https://github.com/dry-rb/dry-schema/workflows/ci/badge.svg)][actions]
12
12
  [![Codacy Badge](https://api.codacy.com/project/badge/Grade/961f5c776f1d49218b2cede3745e059c)][codacy]
13
13
  [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/961f5c776f1d49218b2cede3745e059c)][codacy]
14
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-schema.svg?branch=master)][inchpages]
14
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-schema.svg?branch=main)][inchpages]
15
15
 
16
16
  ## Links
17
17
 
data/dry-schema.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
30
- spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-schema/blob/master/CHANGELOG.md"
30
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-schema/blob/main/CHANGELOG.md"
31
31
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-schema"
32
32
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-schema/issues"
33
33
 
@@ -47,7 +47,7 @@ module Dry
47
47
  pattern: "^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$"
48
48
  },
49
49
  gt?: {exclusiveMinimum: IDENTITY},
50
- gteq?: {mininum: IDENTITY},
50
+ gteq?: {minimum: IDENTITY},
51
51
  lt?: {exclusiveMaximum: IDENTITY},
52
52
  lteq?: {maximum: IDENTITY},
53
53
  odd?: {type: "integer", not: {multipleOf: 2}},
@@ -88,7 +88,7 @@ module Dry
88
88
 
89
89
  # @api private
90
90
  def visit_set(node, opts = EMPTY_HASH)
91
- target = (key = opts[:key]) ? self.class.new : self
91
+ target = (key = opts[:key]) ? self.class.new(loose: loose?) : self
92
92
 
93
93
  node.map { |child| target.visit(child, opts) }
94
94
 
@@ -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
@@ -80,6 +80,11 @@ module Dry
80
80
  def interpolate(key, options, **data)
81
81
  messages.interpolate(key, options, **data)
82
82
  end
83
+
84
+ # @api private
85
+ def translate(key, **args)
86
+ messages.translate(key, **args)
87
+ end
83
88
  end
84
89
  end
85
90
  end
@@ -39,10 +39,10 @@ module Dry
39
39
  super do |config|
40
40
  config.default_locale = :en unless config.default_locale
41
41
 
42
- config.root = "%<locale>s.#{config.root}"
42
+ config.root = -"%<locale>s.#{config.root}"
43
43
 
44
44
  config.rule_lookup_paths = config.rule_lookup_paths.map { |path|
45
- "%<locale>s.#{path}"
45
+ -"%<locale>s.#{path}"
46
46
  }
47
47
  end
48
48
  end
@@ -116,7 +116,7 @@ module Dry
116
116
  ->(input) { call(input) }
117
117
  end
118
118
 
119
- # Return string represntation
119
+ # Return string representation
120
120
  #
121
121
  # @return [String]
122
122
  #
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = "1.9.0"
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.0
4
+ version: 1.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-15 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
@@ -237,7 +237,7 @@ licenses:
237
237
  - MIT
238
238
  metadata:
239
239
  allowed_push_host: https://rubygems.org
240
- changelog_uri: https://github.com/dry-rb/dry-schema/blob/master/CHANGELOG.md
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
243
  post_install_message: