json_model_rb 0.1.18 → 0.1.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18911c5ebb83b6699be34560af2a7c8d964ff54c497a135603c3e5e1ae2c8a18
4
- data.tar.gz: 3b2c5736aea3dac28d2a54ba783c0f933284cddf587c76aab20327323cfc876f
3
+ metadata.gz: 7b8f164fcb8a5e085028753dd18332a48586deda0a72ad8a41c13c94e7e063b3
4
+ data.tar.gz: f544f378a0258a4c6bce6027f2df78f9f7ca2c1c1ca5ff0bbf85baf72f4ae537
5
5
  SHA512:
6
- metadata.gz: 9061ca8854c66c5f9d17f2d5381484b898c395b86d826ef0b2b7a1724d45cf1d297a3427d3fa7ca5e3000aeb262e5336d60f5436e4020064a3de01ea01ee40e2
7
- data.tar.gz: 946fc6b81294a7eda74add39544f079691b032158f5de0a58e0b241a35ab66629a0398145273e7645bdc5614046d574e28879765cd04f4b104e69dc285e80e09
6
+ metadata.gz: 4e670ea581752b7c766d5b2f7baebd9e5b86ced3f53fde695cafb5a633be8b2199830bf4773b44fce050714c3d777763c36616dfa67d99f4248c4dadd352c60e
7
+ data.tar.gz: eb8995d23152892fe64ef15556c97b0472dea200dc8dca4e2b94a3ea6a644ffe2319895acaa227c1bbbab2a53dee5521da3a3c0bc98b65aa1c00fcbba2f122d6
@@ -49,17 +49,18 @@ module JsonModel
49
49
  # @param [Object, Class] type
50
50
  # @return [TypeSpec]
51
51
  def resolve(type)
52
- case type
53
- when TypeSpec
54
- type
55
- when Class
56
- resolve_type_from_class(type)
52
+ if type.is_a?(TypeSpec)
53
+ return type
54
+ end
55
+
56
+ if TYPE_MAP.key?(type)
57
+ TYPE_MAP[type]
58
+ elsif type.respond_to?(:to_type_spec)
59
+ type.to_type_spec
60
+ elsif type.is_a?(Class) && type < Schema
61
+ TypeSpec::Object.new(type)
57
62
  else
58
- if type.respond_to?(:to_type_spec)
59
- type.to_type_spec
60
- else
61
- raise(ArgumentError, "Unsupported type: #{type}")
62
- end
63
+ raise(ArgumentError, "Unsupported type: #{type}")
63
64
  end
64
65
  end
65
66
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonModel
4
- VERSION = '0.1.18'
4
+ VERSION = '0.1.19'
5
5
  end
@@ -34,6 +34,8 @@ RSpec.describe('User schema') do
34
34
  property(:addresses, type: T::Array[Address], ref_mode: JsonModel::RefMode::LOCAL)
35
35
  property(:tags, type: T::Array[String], optional: true)
36
36
  property(:birthday, type: Date, optional: true)
37
+ property(:websites, type: T::Array[URI], optional: true)
38
+ property(:height, type: Float, optional: true)
37
39
  end
38
40
 
39
41
  stub_const('User', user_class)
@@ -56,6 +58,8 @@ RSpec.describe('User schema') do
56
58
  },
57
59
  tags: { type: 'array', items: { type: 'string' } },
58
60
  birthday: { type: 'string', format: 'date' },
61
+ websites: { type: 'array', items: { type: 'string', format: 'uri' } },
62
+ height: { type: 'number' },
59
63
  },
60
64
  required: %i(addresses email name),
61
65
  '$defs': {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_model_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Gillesberger