apiwork 0.5.0 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02f6a539dd3708f867af6e298daec039dd03bc4ea38f22e21172940332ee800f
4
- data.tar.gz: a5603ca5b09b0a8baa3195629b848ceb186e3b1e1d40b987539f02195a76d76f
3
+ metadata.gz: e82aa84563a02e2459a6d464c65cd50e5bb3edcb762a0a5b9412e79475663c52
4
+ data.tar.gz: ac7da6d7f57a6be553fa8809da6f449029ac9d9c42e4da24c780e9f4364c1a4a
5
5
  SHA512:
6
- metadata.gz: 187ae2ea46e4df89ccca25bc2b88fd5a81b31f1887def0f7acfdb3dbc1fad3284f4b6f91c13956631aa20d6dd6793ac4ff1015ce36c6150c0b29dc669ca2aa18
7
- data.tar.gz: 844cb5df21fe9803dabd1e450ce6a9c2f1d7f745fcb40d1d92dbfc2d95660d9ee1be719856d1b922ca5a0eeb11f8e711ce8be1eb423f20d90d348f7c55335a32
6
+ metadata.gz: 4f7bd06c06cb8485762e066e8efb64d21af6258b85442bbbc9813b1359e3d38706314dd285fe48de42d8a5526590c08508c436abdb8acfe0c23c203ade8391db
7
+ data.tar.gz: 7ce587bd8232382e56a8f5da4ba33d1dd942482e018e1e968aacb1f1a6be8bb778d85dec4ee425799a350b0afdd7a4c7277c264b661209bb16f6404e7ec9bf32
@@ -7,9 +7,9 @@ module Apiwork
7
7
  class Default < Base
8
8
  class APIBuilder < Adapter::Builder::API::Base
9
9
  def build
10
- enum(:layer, values: %w[http contract domain])
10
+ enum(:error_layer, values: %w[http contract domain])
11
11
 
12
- object(:issue) do |object|
12
+ object(:error_issue) do |object|
13
13
  object.string(:code)
14
14
  object.string(:detail)
15
15
  object.array(:path, &:string)
@@ -18,9 +18,9 @@ module Apiwork
18
18
  end
19
19
 
20
20
  object(data_type) do |object|
21
- object.reference(:layer)
21
+ object.reference(:layer, to: :error_layer)
22
22
  object.array(:issues) do |element|
23
- element.reference(:issue)
23
+ element.reference(:error_issue)
24
24
  end
25
25
  end
26
26
  end
@@ -163,7 +163,7 @@ module Apiwork
163
163
  def validate_enum_value(name, value, enum, field_path)
164
164
  enum_values = resolve_enum(enum)
165
165
  return nil unless enum_values
166
- return nil if enum_values.include?(value.to_s) || enum_values.include?(value)
166
+ return nil if enum_values.any? { |enum_value| enum_value.to_s == value.to_s }
167
167
 
168
168
  Issue.new(
169
169
  :value_invalid,
@@ -189,6 +189,10 @@ module Apiwork
189
189
  # Whether deprecated. Metadata included in exports.
190
190
  # @param description [String, nil] (nil)
191
191
  # The description. Metadata included in exports.
192
+ # @param max [Integer, nil] (nil)
193
+ # The maximum number of elements.
194
+ # @param min [Integer, nil] (nil)
195
+ # The minimum number of elements.
192
196
  # @param nullable [Boolean] (false)
193
197
  # Whether the value can be `null`.
194
198
  # @param optional [Boolean] (false)
@@ -214,6 +218,8 @@ module Apiwork
214
218
  default: nil,
215
219
  deprecated: false,
216
220
  description: nil,
221
+ max: nil,
222
+ min: nil,
217
223
  nullable: false,
218
224
  optional: false,
219
225
  required: false,
@@ -231,6 +237,8 @@ module Apiwork
231
237
  default:,
232
238
  deprecated:,
233
239
  description:,
240
+ max:,
241
+ min:,
234
242
  nullable:,
235
243
  optional:,
236
244
  required:,
@@ -138,10 +138,10 @@ module Apiwork
138
138
  end
139
139
  else
140
140
  data[:meta] = meta if meta.present?
141
- data
141
+ data.deep_symbolize_keys
142
142
  end
143
143
 
144
- response = Response.new(body:)
144
+ response = Response.new(body: deep_as_json(body))
145
145
 
146
146
  if Rails.env.development?
147
147
  result = contract_class.parse_response(response, action_name)
@@ -223,6 +223,19 @@ module Apiwork
223
223
 
224
224
  private
225
225
 
226
+ def deep_as_json(value)
227
+ case value
228
+ when Hash
229
+ value.transform_values { |nested_value| deep_as_json(nested_value) }
230
+ when Array
231
+ value.map { |element| deep_as_json(element) }
232
+ when String, Integer, Float, TrueClass, FalseClass, NilClass, Symbol, Time, Date, BigDecimal
233
+ value
234
+ else
235
+ value.as_json
236
+ end
237
+ end
238
+
226
239
  def validate_contract
227
240
  return unless resource
228
241
  return if contract.valid?
@@ -1341,6 +1341,10 @@ module Apiwork
1341
1341
  # Whether deprecated. Metadata included in exports.
1342
1342
  # @param description [String, nil] (nil)
1343
1343
  # The description. Metadata included in exports.
1344
+ # @param max [Integer, nil] (nil)
1345
+ # The maximum number of elements.
1346
+ # @param min [Integer, nil] (nil)
1347
+ # The minimum number of elements.
1344
1348
  # @param nullable [Boolean] (false)
1345
1349
  # Whether the value can be `null`.
1346
1350
  # @param of [Symbol, Hash, nil] (nil)
@@ -1386,6 +1390,8 @@ module Apiwork
1386
1390
  default: nil,
1387
1391
  deprecated: false,
1388
1392
  description: nil,
1393
+ max: nil,
1394
+ min: nil,
1389
1395
  nullable: false,
1390
1396
  of: nil,
1391
1397
  optional: false,
@@ -1398,6 +1404,8 @@ module Apiwork
1398
1404
  default:,
1399
1405
  deprecated:,
1400
1406
  description:,
1407
+ max:,
1408
+ min:,
1401
1409
  nullable:,
1402
1410
  of:,
1403
1411
  optional:,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Apiwork
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiwork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - skiftle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-23 00:00:00.000000000 Z
11
+ date: 2026-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails