glia-errors 0.0.0 → 0.0.1

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: 23c0be62fe5b91fe4914d5b6812cfd678a11497e9591291a0664823e6ef1938b
4
- data.tar.gz: 51680c69eaf02641ecc47857d67679fb3e64208f2e008471dffbe64d422d41d1
3
+ metadata.gz: 8336fd0b3da25f1ce3dd3e6b2f61ad4b9e736f391088e1824f6427b5619498b2
4
+ data.tar.gz: 79481e2446fb498d3f606c118fcbfb2e50df1e16e559e8136bd8a30c5cc84109
5
5
  SHA512:
6
- metadata.gz: 3600850fc2f82f50c3608cbba041ef6af9bc9f15a387a64250e465b284ae26316532386443848a8718e4008b37a651c0c876bfb7ddac3e279990b2e11d9e49a7
7
- data.tar.gz: 46a878503202ae5bdb3ba9f8df49c76fd1d122ca76aa9456f0d477753f6f312cd6f01514d59d1babd5a0259b72e2b9f383dc5e0442e7c446a0c9a869350ffc3d
6
+ metadata.gz: 4ea9ab4f9b4e101ea50eb9813a28cc0ff0d221056447e91660e927d3579b531aafb8a1718706ca51ffb09c9bd2556c90c259670590d416b6e602cbbdbcc89389
7
+ data.tar.gz: e83dede85cf3a57e01066970fbfc653fd28414624fda32173b9397691338c8d5e32a200a4e3f4e36eb0d8f480e97bbab7d0588dc7cc50978c0a1cf9cc8a4e93e
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'glia-errors'
8
- spec.version = '0.0.0'
8
+ spec.version = '0.0.1'
9
9
  spec.authors = ['Glia TechMovers']
10
10
  spec.email = ['techmovers@glia.com']
11
11
 
@@ -8,17 +8,18 @@ module Glia
8
8
  lambda do |field, _value, message|
9
9
  type =
10
10
  case message
11
- when 'must be an array'
11
+ when 'must be an array', 'must be Array'
12
12
  InvalidTypeError::Types::ARRAY
13
- when 'must be an integer'
13
+ when 'must be an integer', 'must be Integer'
14
14
  InvalidTypeError::Types::INTEGER
15
- when 'must be a number', 'must be a float', 'must be a decimal'
15
+ when 'must be a number', 'must be a float', 'must be a decimal', 'must be Float',
16
+ 'must be BigDecimal'
16
17
  InvalidTypeError::Types::NUMBER
17
- when 'must be a hash'
18
+ when 'must be a hash', 'must be Hash'
18
19
  InvalidTypeError::Types::OBJECT
19
- when 'must be boolean'
20
+ when 'must be boolean', 'must be Boolean'
20
21
  InvalidTypeError::Types::BOOLEAN
21
- when 'must be a string'
22
+ when 'must be a string', 'must be String'
22
23
  InvalidTypeError::Types::STRING
23
24
  end
24
25
  InvalidTypeError.new(field: field, type: type)
@@ -52,11 +53,11 @@ module Glia
52
53
  if value.is_a?(String)
53
54
  format =
54
55
  case message
55
- when 'must be a date'
56
+ when 'must be a date', 'must be Date'
56
57
  InvalidFormatError::Formats::DATE
57
- when 'must be a date time'
58
+ when 'must be a date time', 'must be DateTime'
58
59
  InvalidFormatError::Formats::DATE_TIME
59
- when 'must be a time'
60
+ when 'must be a time', 'must be Time'
60
61
  InvalidFormatError::Formats::TIME
61
62
  end
62
63
  InvalidFormatError.new(field: field, format: format)
@@ -68,16 +69,26 @@ module Glia
68
69
  ERROR_MAP = {
69
70
  # InvalidTypeError
70
71
  'must be an array' => INVALID_TYPE_ERROR,
72
+ 'must be Array' => INVALID_TYPE_ERROR,
71
73
  'must be an integer' => INVALID_TYPE_ERROR,
74
+ 'must be Integer' => INVALID_TYPE_ERROR,
72
75
  'must be a number' => INVALID_TYPE_ERROR,
73
76
  'must be a float' => INVALID_TYPE_ERROR,
77
+ 'must be Float' => INVALID_TYPE_ERROR,
74
78
  'must be a decimal' => INVALID_TYPE_ERROR,
79
+ 'must be BigDecimal' => INVALID_TYPE_ERROR,
75
80
  'must be a hash' => INVALID_TYPE_ERROR,
81
+ 'must be Hash' => INVALID_TYPE_ERROR,
76
82
  'must be boolean' => INVALID_TYPE_ERROR,
83
+ 'must be Boolean' => INVALID_TYPE_ERROR,
77
84
  'must be a string' => INVALID_TYPE_ERROR,
85
+ 'must be String' => INVALID_TYPE_ERROR,
78
86
  'must be a date time' => INVALID_DATE_FORMAT_OR_TYPE_ERROR,
87
+ 'must be DateTime' => INVALID_DATE_FORMAT_OR_TYPE_ERROR,
79
88
  'must be a date' => INVALID_DATE_FORMAT_OR_TYPE_ERROR,
89
+ 'must be Date' => INVALID_DATE_FORMAT_OR_TYPE_ERROR,
80
90
  'must be a time' => INVALID_DATE_FORMAT_OR_TYPE_ERROR,
91
+ 'must be Time' => INVALID_DATE_FORMAT_OR_TYPE_ERROR,
81
92
  # InvalidFormatError
82
93
  'is in invalid format' => INVALID_FORMAT_ERROR,
83
94
  'is not a valid UUID' => INVALID_UUID_ERROR,
@@ -132,7 +143,9 @@ module Glia
132
143
  field_value = output[field]
133
144
  acc[field] =
134
145
  if field_messages.is_a?(Hash)
135
- from_dry_validation_result_rec(field_value, field_messages, error_map)
146
+ # Wrap result in array as by defined structure each field has an array of errors.
147
+ # This is not needed for the `else` case as dry-validation already provides an array.
148
+ [from_dry_validation_result_rec(field_value, field_messages, error_map)]
136
149
  else
137
150
  field_messages.map do |message|
138
151
  from_dry_validation_error(field, field_value, message, error_map)
@@ -0,0 +1,77 @@
1
+ {
2
+ "input": {
3
+ "object": {
4
+ "invalid_nested_object_value": "invalid"
5
+ },
6
+ "array": [
7
+ {
8
+ "invalid_nested_array_value": "invalid"
9
+ },
10
+ {
11
+ "invalid_nested_array_value": "valid"
12
+ },
13
+ {
14
+ "invalid_nested_array_value": "invalid"
15
+ }
16
+ ]
17
+ },
18
+ "expectation": {
19
+ "type": "input_validation_error",
20
+ "ref": "https://example.com/errors/input_validation_error.html",
21
+ "error_details": {
22
+ "object": [
23
+ {
24
+ "type": "input_validation_error",
25
+ "ref": "https://example.com/errors/input_validation_error.html",
26
+ "error_details": {
27
+ "invalid_nested_object_value": [
28
+ {
29
+ "type": "invalid_value_error",
30
+ "ref": "https://example.com/errors/invalid_value_error.html",
31
+ "message": "Invalid nested object value is invalid"
32
+ }
33
+ ]
34
+ }
35
+ }
36
+ ],
37
+ "array": [
38
+ {
39
+ "type": "input_validation_error",
40
+ "ref": "https://example.com/errors/input_validation_error.html",
41
+ "error_details": {
42
+ "0": [
43
+ {
44
+ "type": "input_validation_error",
45
+ "ref": "https://example.com/errors/input_validation_error.html",
46
+ "error_details": {
47
+ "invalid_nested_array_value": [
48
+ {
49
+ "type": "invalid_value_error",
50
+ "ref": "https://example.com/errors/invalid_value_error.html",
51
+ "message": "Invalid nested array value is invalid"
52
+ }
53
+ ]
54
+ }
55
+ }
56
+ ],
57
+ "2": [
58
+ {
59
+ "type": "input_validation_error",
60
+ "ref": "https://example.com/errors/input_validation_error.html",
61
+ "error_details": {
62
+ "invalid_nested_array_value": [
63
+ {
64
+ "type": "invalid_value_error",
65
+ "ref": "https://example.com/errors/invalid_value_error.html",
66
+ "message": "Invalid nested array value is invalid"
67
+ }
68
+ ]
69
+ }
70
+ }
71
+ ]
72
+ }
73
+ }
74
+ ]
75
+ }
76
+ }
77
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glia-errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glia TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-14 00:00:00.000000000 Z
11
+ date: 2021-01-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ''
14
14
  email:
@@ -39,6 +39,7 @@ files:
39
39
  - lib/glia/errors/validation_errors.rb
40
40
  - test_cases/invalid_format_error_case.json
41
41
  - test_cases/invalid_length_error_case.json
42
+ - test_cases/invalid_nested_params_case.json
42
43
  - test_cases/invalid_number_error_case.json
43
44
  - test_cases/invalid_type_error_case.json
44
45
  - test_cases/invalid_value_error_case.json
@@ -62,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
63
  - !ruby/object:Gem::Version
63
64
  version: '0'
64
65
  requirements: []
65
- rubygems_version: 3.0.3
66
+ rubygems_version: 3.0.6
66
67
  signing_key:
67
68
  specification_version: 4
68
69
  summary: Glia REST API errors