timelogic-api 1.1.0 → 2.0.0

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.
@@ -14,48 +14,21 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module TimeLogic::Api
17
+ # One geographic zone whose current offset equals the requested offset.
17
18
  class TimezoneMatch
18
- attr_accessor :unix
19
-
20
- attr_accessor :unix_ms
21
-
22
- attr_accessor :utc
23
-
24
- attr_accessor :iso_local
25
-
26
- attr_accessor :rfc2822
27
-
28
- attr_accessor :human
29
-
30
- # Day of the week counted from Sunday (1 = Sunday, 2 = Monday ... 7 = Saturday).
31
- attr_accessor :day_number
32
-
33
- attr_accessor :day_short
34
-
35
- attr_accessor :day_full
36
-
19
+ # IANA timezone name.
37
20
  attr_accessor :timezone
38
21
 
39
- attr_accessor :formatted
40
-
22
+ # Current UTC offset of the zone in minutes.
41
23
  attr_accessor :offset
42
24
 
25
+ # Whether daylight saving time is currently in effect in the zone.
43
26
  attr_accessor :dst
44
27
 
45
28
  # Attribute mapping from ruby-style variable name to JSON key.
46
29
  def self.attribute_map
47
30
  {
48
- :'unix' => :'unix',
49
- :'unix_ms' => :'unix_ms',
50
- :'utc' => :'utc',
51
- :'iso_local' => :'iso_local',
52
- :'rfc2822' => :'rfc2822',
53
- :'human' => :'human',
54
- :'day_number' => :'day_number',
55
- :'day_short' => :'day_short',
56
- :'day_full' => :'day_full',
57
31
  :'timezone' => :'timezone',
58
- :'formatted' => :'formatted',
59
32
  :'offset' => :'offset',
60
33
  :'dst' => :'dst'
61
34
  }
@@ -69,17 +42,7 @@ module TimeLogic::Api
69
42
  # Attribute type mapping.
70
43
  def self.openapi_types
71
44
  {
72
- :'unix' => :'Integer',
73
- :'unix_ms' => :'Integer',
74
- :'utc' => :'Time',
75
- :'iso_local' => :'String',
76
- :'rfc2822' => :'String',
77
- :'human' => :'String',
78
- :'day_number' => :'Integer',
79
- :'day_short' => :'String',
80
- :'day_full' => :'String',
81
45
  :'timezone' => :'String',
82
- :'formatted' => :'String',
83
46
  :'offset' => :'Integer',
84
47
  :'dst' => :'Boolean'
85
48
  }
@@ -88,17 +51,9 @@ module TimeLogic::Api
88
51
  # List of attributes with nullable: true
89
52
  def self.openapi_nullable
90
53
  Set.new([
91
- :'iso_local',
92
54
  ])
93
55
  end
94
56
 
95
- # List of class defined in allOf (OpenAPI v3)
96
- def self.openapi_all_of
97
- [
98
- :'TimePayload'
99
- ]
100
- end
101
-
102
57
  # Initializes the object
103
58
  # @param [Hash] attributes Model attributes in the form of hash
104
59
  def initialize(attributes = {})
@@ -114,70 +69,12 @@ module TimeLogic::Api
114
69
  h[k.to_sym] = v
115
70
  }
116
71
 
117
- if attributes.key?(:'unix')
118
- self.unix = attributes[:'unix']
119
- else
120
- self.unix = nil
121
- end
122
-
123
- if attributes.key?(:'unix_ms')
124
- self.unix_ms = attributes[:'unix_ms']
125
- else
126
- self.unix_ms = nil
127
- end
128
-
129
- if attributes.key?(:'utc')
130
- self.utc = attributes[:'utc']
131
- else
132
- self.utc = nil
133
- end
134
-
135
- if attributes.key?(:'iso_local')
136
- self.iso_local = attributes[:'iso_local']
137
- else
138
- self.iso_local = nil
139
- end
140
-
141
- if attributes.key?(:'rfc2822')
142
- self.rfc2822 = attributes[:'rfc2822']
143
- else
144
- self.rfc2822 = nil
145
- end
146
-
147
- if attributes.key?(:'human')
148
- self.human = attributes[:'human']
149
- else
150
- self.human = nil
151
- end
152
-
153
- if attributes.key?(:'day_number')
154
- self.day_number = attributes[:'day_number']
155
- else
156
- self.day_number = nil
157
- end
158
-
159
- if attributes.key?(:'day_short')
160
- self.day_short = attributes[:'day_short']
161
- else
162
- self.day_short = nil
163
- end
164
-
165
- if attributes.key?(:'day_full')
166
- self.day_full = attributes[:'day_full']
167
- else
168
- self.day_full = nil
169
- end
170
-
171
72
  if attributes.key?(:'timezone')
172
73
  self.timezone = attributes[:'timezone']
173
74
  else
174
75
  self.timezone = nil
175
76
  end
176
77
 
177
- if attributes.key?(:'formatted')
178
- self.formatted = attributes[:'formatted']
179
- end
180
-
181
78
  if attributes.key?(:'offset')
182
79
  self.offset = attributes[:'offset']
183
80
  else
@@ -196,46 +93,6 @@ module TimeLogic::Api
196
93
  def list_invalid_properties
197
94
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
198
95
  invalid_properties = Array.new
199
- if @unix.nil?
200
- invalid_properties.push('invalid value for "unix", unix cannot be nil.')
201
- end
202
-
203
- if @unix_ms.nil?
204
- invalid_properties.push('invalid value for "unix_ms", unix_ms cannot be nil.')
205
- end
206
-
207
- if @utc.nil?
208
- invalid_properties.push('invalid value for "utc", utc cannot be nil.')
209
- end
210
-
211
- if @rfc2822.nil?
212
- invalid_properties.push('invalid value for "rfc2822", rfc2822 cannot be nil.')
213
- end
214
-
215
- if @human.nil?
216
- invalid_properties.push('invalid value for "human", human cannot be nil.')
217
- end
218
-
219
- if @day_number.nil?
220
- invalid_properties.push('invalid value for "day_number", day_number cannot be nil.')
221
- end
222
-
223
- if @day_number > 7
224
- invalid_properties.push('invalid value for "day_number", must be smaller than or equal to 7.')
225
- end
226
-
227
- if @day_number < 1
228
- invalid_properties.push('invalid value for "day_number", must be greater than or equal to 1.')
229
- end
230
-
231
- if @day_short.nil?
232
- invalid_properties.push('invalid value for "day_short", day_short cannot be nil.')
233
- end
234
-
235
- if @day_full.nil?
236
- invalid_properties.push('invalid value for "day_full", day_full cannot be nil.')
237
- end
238
-
239
96
  if @timezone.nil?
240
97
  invalid_properties.push('invalid value for "timezone", timezone cannot be nil.')
241
98
  end
@@ -255,56 +112,18 @@ module TimeLogic::Api
255
112
  # @return true if the model is valid
256
113
  def valid?
257
114
  warn '[DEPRECATED] the `valid?` method is obsolete'
258
- return false if @unix.nil?
259
- return false if @unix_ms.nil?
260
- return false if @utc.nil?
261
- return false if @rfc2822.nil?
262
- return false if @human.nil?
263
- return false if @day_number.nil?
264
- return false if @day_number > 7
265
- return false if @day_number < 1
266
- return false if @day_short.nil?
267
- return false if @day_full.nil?
268
115
  return false if @timezone.nil?
269
116
  return false if @offset.nil?
270
117
  return false if @dst.nil?
271
118
  true
272
119
  end
273
120
 
274
- # Custom attribute writer method with validation
275
- # @param [Object] day_number Value to be assigned
276
- def day_number=(day_number)
277
- if day_number.nil?
278
- fail ArgumentError, 'day_number cannot be nil'
279
- end
280
-
281
- if day_number > 7
282
- fail ArgumentError, 'invalid value for "day_number", must be smaller than or equal to 7.'
283
- end
284
-
285
- if day_number < 1
286
- fail ArgumentError, 'invalid value for "day_number", must be greater than or equal to 1.'
287
- end
288
-
289
- @day_number = day_number
290
- end
291
-
292
121
  # Checks equality by comparing each attribute.
293
122
  # @param [Object] Object to be compared
294
123
  def ==(o)
295
124
  return true if self.equal?(o)
296
125
  self.class == o.class &&
297
- unix == o.unix &&
298
- unix_ms == o.unix_ms &&
299
- utc == o.utc &&
300
- iso_local == o.iso_local &&
301
- rfc2822 == o.rfc2822 &&
302
- human == o.human &&
303
- day_number == o.day_number &&
304
- day_short == o.day_short &&
305
- day_full == o.day_full &&
306
126
  timezone == o.timezone &&
307
- formatted == o.formatted &&
308
127
  offset == o.offset &&
309
128
  dst == o.dst
310
129
  end
@@ -318,7 +137,7 @@ module TimeLogic::Api
318
137
  # Calculates hash code according to all attributes.
319
138
  # @return [Integer] Hash code
320
139
  def hash
321
- [unix, unix_ms, utc, iso_local, rfc2822, human, day_number, day_short, day_full, timezone, formatted, offset, dst].hash
140
+ [timezone, offset, dst].hash
322
141
  end
323
142
 
324
143
  # Builds the object from hash
@@ -14,8 +14,8 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module TimeLogic::Api
17
- # Offset-based timezone lookup result with `matching_zones` for the current request-time offset match.
18
- class TimezoneOffsetResponse
17
+ # Timezone lookup result. It is the time payload for the resolved target plus `offset` (minutes east of UTC) and `dst`. Every selector returns this one shape. `tz`, `ip`, `lat` + `lon` and `auto_tz` lookups resolve a named zone, so `timezone` is set and `matching_zones` is absent. `offset` lookups return `timezone=null` and add `matching_zones`, the geographic zones whose current offset equals the requested one.
18
+ class TimezoneResponse
19
19
  attr_accessor :unix
20
20
 
21
21
  attr_accessor :unix_ms
@@ -39,11 +39,16 @@ module TimeLogic::Api
39
39
 
40
40
  attr_accessor :formatted
41
41
 
42
+ # UTC offset of the resolved target in minutes, for example `-240` for UTC-04:00.
42
43
  attr_accessor :offset
43
44
 
45
+ # Whether daylight saving time is in effect for the resolved target. Always `false` for `offset` lookups.
44
46
  attr_accessor :dst
45
47
 
46
- # For `offset=` lookups, the geographic zones whose current offset equals the requested one. `UTC` and `Etc/*` zones are intentionally excluded; use `tz=UTC` for UTC.
48
+ # Exact UTC offset in seconds. Present only when the resolved offset has a seconds part (historical local mean time); no zone has one at the current instant, so lookups today do not include it.
49
+ attr_accessor :offset_seconds
50
+
51
+ # Present only for `offset=` lookups. The geographic zones whose current offset equals the requested one. `UTC` and `Etc/*` zones are intentionally excluded; use `tz=UTC` for UTC.
47
52
  attr_accessor :matching_zones
48
53
 
49
54
  # Attribute mapping from ruby-style variable name to JSON key.
@@ -62,6 +67,7 @@ module TimeLogic::Api
62
67
  :'formatted' => :'formatted',
63
68
  :'offset' => :'offset',
64
69
  :'dst' => :'dst',
70
+ :'offset_seconds' => :'offset_seconds',
65
71
  :'matching_zones' => :'matching_zones'
66
72
  }
67
73
  end
@@ -87,6 +93,7 @@ module TimeLogic::Api
87
93
  :'formatted' => :'String',
88
94
  :'offset' => :'Integer',
89
95
  :'dst' => :'Boolean',
96
+ :'offset_seconds' => :'Integer',
90
97
  :'matching_zones' => :'Array<TimezoneMatch>'
91
98
  }
92
99
  end
@@ -102,7 +109,7 @@ module TimeLogic::Api
102
109
  # List of class defined in allOf (OpenAPI v3)
103
110
  def self.openapi_all_of
104
111
  [
105
- :'TimezoneResolvedResponse'
112
+ :'TimePayload'
106
113
  ]
107
114
  end
108
115
 
@@ -110,13 +117,13 @@ module TimeLogic::Api
110
117
  # @param [Hash] attributes Model attributes in the form of hash
111
118
  def initialize(attributes = {})
112
119
  if (!attributes.is_a?(Hash))
113
- fail ArgumentError, "The input argument (attributes) must be a hash in `TimeLogic::Api::TimezoneOffsetResponse` initialize method"
120
+ fail ArgumentError, "The input argument (attributes) must be a hash in `TimeLogic::Api::TimezoneResponse` initialize method"
114
121
  end
115
122
 
116
123
  # check to see if the attribute exists and convert string to symbol for hash key
117
124
  attributes = attributes.each_with_object({}) { |(k, v), h|
118
125
  if (!self.class.attribute_map.key?(k.to_sym))
119
- fail ArgumentError, "`#{k}` is not a valid attribute in `TimeLogic::Api::TimezoneOffsetResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
126
+ fail ArgumentError, "`#{k}` is not a valid attribute in `TimeLogic::Api::TimezoneResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
120
127
  end
121
128
  h[k.to_sym] = v
122
129
  }
@@ -197,12 +204,14 @@ module TimeLogic::Api
197
204
  self.dst = nil
198
205
  end
199
206
 
207
+ if attributes.key?(:'offset_seconds')
208
+ self.offset_seconds = attributes[:'offset_seconds']
209
+ end
210
+
200
211
  if attributes.key?(:'matching_zones')
201
212
  if (value = attributes[:'matching_zones']).is_a?(Array)
202
213
  self.matching_zones = value
203
214
  end
204
- else
205
- self.matching_zones = nil
206
215
  end
207
216
  end
208
217
 
@@ -259,10 +268,6 @@ module TimeLogic::Api
259
268
  invalid_properties.push('invalid value for "dst", dst cannot be nil.')
260
269
  end
261
270
 
262
- if @matching_zones.nil?
263
- invalid_properties.push('invalid value for "matching_zones", matching_zones cannot be nil.')
264
- end
265
-
266
271
  invalid_properties
267
272
  end
268
273
 
@@ -282,7 +287,6 @@ module TimeLogic::Api
282
287
  return false if @day_full.nil?
283
288
  return false if @offset.nil?
284
289
  return false if @dst.nil?
285
- return false if @matching_zones.nil?
286
290
  true
287
291
  end
288
292
 
@@ -322,6 +326,7 @@ module TimeLogic::Api
322
326
  formatted == o.formatted &&
323
327
  offset == o.offset &&
324
328
  dst == o.dst &&
329
+ offset_seconds == o.offset_seconds &&
325
330
  matching_zones == o.matching_zones
326
331
  end
327
332
 
@@ -334,7 +339,7 @@ module TimeLogic::Api
334
339
  # Calculates hash code according to all attributes.
335
340
  # @return [Integer] Hash code
336
341
  def hash
337
- [unix, unix_ms, utc, iso_local, rfc2822, human, day_number, day_short, day_full, timezone, formatted, offset, dst, matching_zones].hash
342
+ [unix, unix_ms, utc, iso_local, rfc2822, human, day_number, day_short, day_full, timezone, formatted, offset, dst, offset_seconds, matching_zones].hash
338
343
  end
339
344
 
340
345
  # Builds the object from hash
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TimeLogic
4
4
  module Api
5
- VERSION = '1.1.0'
5
+ VERSION = '2.0.0'
6
6
  end
7
7
  end
data/lib/timelogic-api.rb CHANGED
@@ -30,14 +30,12 @@ require 'timelogic-api/models/dst_response'
30
30
  require 'timelogic-api/models/elapsed_response'
31
31
  require 'timelogic-api/models/error_response'
32
32
  require 'timelogic-api/models/get_current_time200_response'
33
- require 'timelogic-api/models/get_timezone200_response'
34
33
  require 'timelogic-api/models/jwk_key'
35
34
  require 'timelogic-api/models/jwks_response'
36
35
  require 'timelogic-api/models/time_payload'
37
36
  require 'timelogic-api/models/time_payload_bulk_item'
38
37
  require 'timelogic-api/models/timezone_match'
39
- require 'timelogic-api/models/timezone_offset_response'
40
- require 'timelogic-api/models/timezone_resolved_response'
38
+ require 'timelogic-api/models/timezone_response'
41
39
  require 'timelogic-api/models/time_payload_bulk_response'
42
40
 
43
41
  # APIs
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timelogic-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TimeLogic API LLC
@@ -68,7 +68,6 @@ files:
68
68
  - docs/ElapsedResponse.md
69
69
  - docs/ErrorResponse.md
70
70
  - docs/GetCurrentTime200Response.md
71
- - docs/GetTimezone200Response.md
72
71
  - docs/JwkKey.md
73
72
  - docs/JwksResponse.md
74
73
  - docs/TimeApi.md
@@ -76,8 +75,7 @@ files:
76
75
  - docs/TimePayloadBulkItem.md
77
76
  - docs/TimePayloadBulkResponse.md
78
77
  - docs/TimezoneMatch.md
79
- - docs/TimezoneOffsetResponse.md
80
- - docs/TimezoneResolvedResponse.md
78
+ - docs/TimezoneResponse.md
81
79
  - docs/UtilityApi.md
82
80
  - lib/timelogic-api.rb
83
81
  - lib/timelogic-api/api/time_api.rb
@@ -94,15 +92,13 @@ files:
94
92
  - lib/timelogic-api/models/elapsed_response.rb
95
93
  - lib/timelogic-api/models/error_response.rb
96
94
  - lib/timelogic-api/models/get_current_time200_response.rb
97
- - lib/timelogic-api/models/get_timezone200_response.rb
98
95
  - lib/timelogic-api/models/jwk_key.rb
99
96
  - lib/timelogic-api/models/jwks_response.rb
100
97
  - lib/timelogic-api/models/time_payload.rb
101
98
  - lib/timelogic-api/models/time_payload_bulk_item.rb
102
99
  - lib/timelogic-api/models/time_payload_bulk_response.rb
103
100
  - lib/timelogic-api/models/timezone_match.rb
104
- - lib/timelogic-api/models/timezone_offset_response.rb
105
- - lib/timelogic-api/models/timezone_resolved_response.rb
101
+ - lib/timelogic-api/models/timezone_response.rb
106
102
  - lib/timelogic-api/transport_configuration.rb
107
103
  - lib/timelogic-api/version.rb
108
104
  - lib/timelogic-api/world_time_api.rb
@@ -1,49 +0,0 @@
1
- # TimeLogic::Api::GetTimezone200Response
2
-
3
- ## Class instance methods
4
-
5
- ### `openapi_one_of`
6
-
7
- Returns the list of classes defined in oneOf.
8
-
9
- #### Example
10
-
11
- ```ruby
12
- require 'timelogic-api'
13
-
14
- TimeLogic::Api::GetTimezone200Response.openapi_one_of
15
- # =>
16
- # [
17
- # :'TimezoneOffsetResponse',
18
- # :'TimezoneResolvedResponse'
19
- # ]
20
- ```
21
-
22
- ### build
23
-
24
- Find the appropriate object from the `openapi_one_of` list and casts the data into it.
25
-
26
- #### Example
27
-
28
- ```ruby
29
- require 'timelogic-api'
30
-
31
- TimeLogic::Api::GetTimezone200Response.build(data)
32
- # => #<TimezoneOffsetResponse:0x00007fdd4aab02a0>
33
-
34
- TimeLogic::Api::GetTimezone200Response.build(data_that_doesnt_match)
35
- # => nil
36
- ```
37
-
38
- #### Parameters
39
-
40
- | Name | Type | Description |
41
- | ---- | ---- | ----------- |
42
- | **data** | **Mixed** | data to be matched against the list of oneOf items |
43
-
44
- #### Return type
45
-
46
- - `TimezoneOffsetResponse`
47
- - `TimezoneResolvedResponse`
48
- - `nil` (if no type matches)
49
-
@@ -1,42 +0,0 @@
1
- # TimeLogic::Api::TimezoneResolvedResponse
2
-
3
- ## Properties
4
-
5
- | Name | Type | Description | Notes |
6
- | ---- | ---- | ----------- | ----- |
7
- | **unix** | **Integer** | | |
8
- | **unix_ms** | **Integer** | | |
9
- | **utc** | **Time** | | |
10
- | **iso_local** | **String** | | |
11
- | **rfc2822** | **String** | | |
12
- | **human** | **String** | | |
13
- | **day_number** | **Integer** | Day of the week counted from Sunday (1 &#x3D; Sunday, 2 &#x3D; Monday ... 7 &#x3D; Saturday). | |
14
- | **day_short** | **String** | | |
15
- | **day_full** | **String** | | |
16
- | **timezone** | **String** | | |
17
- | **formatted** | **String** | | [optional] |
18
- | **offset** | **Integer** | | |
19
- | **dst** | **Boolean** | | |
20
-
21
- ## Example
22
-
23
- ```ruby
24
- require 'timelogic-api'
25
-
26
- instance = TimeLogic::Api::TimezoneResolvedResponse.new(
27
- unix: null,
28
- unix_ms: null,
29
- utc: null,
30
- iso_local: null,
31
- rfc2822: null,
32
- human: null,
33
- day_number: null,
34
- day_short: null,
35
- day_full: null,
36
- timezone: null,
37
- formatted: null,
38
- offset: null,
39
- dst: null
40
- )
41
- ```
42
-
@@ -1,105 +0,0 @@
1
- =begin
2
- #TimeLogic API | A World Time API
3
-
4
- #Direct API contract for client integrations. It documents authentication, endpoint parameters, response shapes, public signing keys, and signed JSON controls. Authentication: - the API supports `Authorization: Bearer <token>`, `X-API-Key`, and `api_key` query credentials - RapidAPI access uses `X-RapidAPI-Key` and `X-RapidAPI-Host`; the SDKs expose this as a `rapidApi` transport option that accepts only the RapidAPI key Behavioral notes: - all documented operations are `GET` - only one selector family may be used at a time - current and convert support bulk only through one comma-separated `tz`, `ip`, or `offset` selector - bulk selectors accept at most 10 values, and every request URL is limited to 8192 characters - add, diff, calendar, dst, elapsed, timezone, and clock are single-target routes - credentials are extracted in Authorization, X-API-Key, then api_key query order; conflicting values are rejected - the first server is the default API host. The second server is the RapidAPI gateway and can be selected or overridden by SDK configuration - `sign` is available on supported JSON routes and is not supported on `/v1/time/clock`
5
-
6
- The version of the OpenAPI document: 1.0.0
7
-
8
- Generated by: https://github.com/TimeLogic-API-LLC/timelogic-api-sdks.git
9
- Generator version: 7.10.0
10
-
11
- =end
12
-
13
- require 'date'
14
- require 'time'
15
-
16
- module TimeLogic::Api
17
- module GetTimezone200Response
18
- class << self
19
- # List of class defined in oneOf (OpenAPI v3)
20
- def openapi_one_of
21
- [
22
- :'TimezoneOffsetResponse',
23
- :'TimezoneResolvedResponse'
24
- ]
25
- end
26
-
27
- # Builds the object
28
- # @param [Mixed] Data to be matched against the list of oneOf items
29
- # @return [Object] Returns the model or the data itself
30
- def build(data)
31
- # Go through the list of oneOf items and attempt to identify the appropriate one.
32
- # Note:
33
- # - We do not attempt to check whether exactly one item matches.
34
- # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
35
- # due to the way the deserialization is made in the base_object template (it just casts without verifying).
36
- # - TODO: scalar values are de facto behaving as if they were nullable.
37
- # - TODO: logging when debugging is set.
38
- openapi_one_of.each do |klass|
39
- begin
40
- next if klass == :AnyType # "nullable: true"
41
- typed_data = find_and_cast_into_type(klass, data)
42
- return typed_data if typed_data
43
- rescue # rescue all errors so we keep iterating even if the current item lookup raises
44
- end
45
- end
46
-
47
- openapi_one_of.include?(:AnyType) ? data : nil
48
- end
49
-
50
- private
51
-
52
- SchemaMismatchError = Class.new(StandardError)
53
-
54
- # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
55
- def find_and_cast_into_type(klass, data)
56
- return if data.nil?
57
-
58
- case klass.to_s
59
- when 'Boolean'
60
- return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
61
- when 'Float'
62
- return data if data.instance_of?(Float)
63
- when 'Integer'
64
- return data if data.instance_of?(Integer)
65
- when 'Time'
66
- return Time.parse(data)
67
- when 'Date'
68
- return Date.parse(data)
69
- when 'String'
70
- return data if data.instance_of?(String)
71
- when 'Object' # "type: object"
72
- return data if data.instance_of?(Hash)
73
- when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
74
- if data.instance_of?(Array)
75
- sub_type = Regexp.last_match[:sub_type]
76
- return data.map { |item| find_and_cast_into_type(sub_type, item) }
77
- end
78
- when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
79
- if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
80
- sub_type = Regexp.last_match[:sub_type]
81
- return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
82
- end
83
- else # model
84
- const = TimeLogic::Api.const_get(klass)
85
- if const
86
- if const.respond_to?(:openapi_one_of) # nested oneOf model
87
- model = const.build(data)
88
- return model if model
89
- else
90
- # raise if data contains keys that are not known to the model
91
- raise if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty?
92
- model = const.build_from_hash(data)
93
- return model if model
94
- end
95
- end
96
- end
97
-
98
- raise # if no match by now, raise
99
- rescue
100
- raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
101
- end
102
- end
103
- end
104
-
105
- end