apiwork 0.5.0 → 0.6.1
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 +4 -4
- data/lib/apiwork/adapter/serializer/error/default/api_builder.rb +4 -4
- data/lib/apiwork/adapter/serializer/resource/default/contract_builder.rb +2 -0
- data/lib/apiwork/contract/object/validator.rb +1 -1
- data/lib/apiwork/contract/object.rb +8 -0
- data/lib/apiwork/controller.rb +15 -2
- data/lib/apiwork/object.rb +8 -0
- data/lib/apiwork/representation/attribute.rb +12 -1
- data/lib/apiwork/representation/base.rb +5 -0
- data/lib/apiwork/representation/serializer.rb +2 -0
- data/lib/apiwork/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e7d4674d14687a7f9eb3547135c22df22c1cada2dc55b7f2b0f011462d20bf1a
|
|
4
|
+
data.tar.gz: f580dcdf234e49b933b1636f2a2c14d2ca11caf4d5364a70ec574763978c834c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 33a16b4c739c5c13ba2374882d0997bea4cda29b00eef1c1afe7c810fe0247fab1ca6568bb225ac8e32617742b0ff9df85920518db7a4c062a223cdc688cee6b
|
|
7
|
+
data.tar.gz: d707cbf17e3df65f57a523e7695b5ce2c7d009b3aa28599b071fb0ec1ba910281af9224493708214654a979ffe6362d661d6d5410bcec93ffadc08e37c9f6f96
|
|
@@ -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(:
|
|
10
|
+
enum(:error_layer, values: %w[http contract domain])
|
|
11
11
|
|
|
12
|
-
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(:
|
|
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.
|
|
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:,
|
data/lib/apiwork/controller.rb
CHANGED
|
@@ -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?
|
data/lib/apiwork/object.rb
CHANGED
|
@@ -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:,
|
|
@@ -83,7 +83,8 @@ module Apiwork
|
|
|
83
83
|
:of,
|
|
84
84
|
:optional,
|
|
85
85
|
:preload,
|
|
86
|
-
:type
|
|
86
|
+
:type,
|
|
87
|
+
:write_only
|
|
87
88
|
|
|
88
89
|
def initialize(
|
|
89
90
|
name,
|
|
@@ -105,6 +106,7 @@ module Apiwork
|
|
|
105
106
|
sortable: false,
|
|
106
107
|
type: nil,
|
|
107
108
|
writable: false,
|
|
109
|
+
write_only: false,
|
|
108
110
|
&block
|
|
109
111
|
)
|
|
110
112
|
@name = name
|
|
@@ -157,6 +159,7 @@ module Apiwork
|
|
|
157
159
|
@example = example
|
|
158
160
|
@format = format
|
|
159
161
|
@deprecated = deprecated
|
|
162
|
+
@write_only = write_only
|
|
160
163
|
|
|
161
164
|
validate_min_max_range!
|
|
162
165
|
validate_format!
|
|
@@ -225,6 +228,14 @@ module Apiwork
|
|
|
225
228
|
[true, action].include?(@writable)
|
|
226
229
|
end
|
|
227
230
|
|
|
231
|
+
# @api public
|
|
232
|
+
# Whether this attribute is write-only.
|
|
233
|
+
#
|
|
234
|
+
# @return [Boolean]
|
|
235
|
+
def write_only?
|
|
236
|
+
@write_only
|
|
237
|
+
end
|
|
238
|
+
|
|
228
239
|
def encode(value)
|
|
229
240
|
result = @empty && value.nil? ? '' : value
|
|
230
241
|
@encode ? @encode.call(result) : result
|
|
@@ -222,6 +222,9 @@ module Apiwork
|
|
|
222
222
|
# Use an explicit type or block in those cases.
|
|
223
223
|
# @param writable [Boolean, Symbol] (false) [:create, :update]
|
|
224
224
|
# The write access. `true` for both create and update, `:create` for create only, `:update` for update only.
|
|
225
|
+
# @param write_only [Boolean] (false)
|
|
226
|
+
# Whether the attribute is write-only. Write-only attributes are excluded from response
|
|
227
|
+
# serialization and response types but remain in writable payloads.
|
|
225
228
|
# @yieldparam element [Representation::Element]
|
|
226
229
|
# @return [void]
|
|
227
230
|
#
|
|
@@ -286,6 +289,7 @@ module Apiwork
|
|
|
286
289
|
sortable: false,
|
|
287
290
|
type: nil,
|
|
288
291
|
writable: false,
|
|
292
|
+
write_only: false,
|
|
289
293
|
&block
|
|
290
294
|
)
|
|
291
295
|
self.attributes = attributes.merge(
|
|
@@ -309,6 +313,7 @@ module Apiwork
|
|
|
309
313
|
sortable:,
|
|
310
314
|
type:,
|
|
311
315
|
writable:,
|
|
316
|
+
write_only:,
|
|
312
317
|
&block
|
|
313
318
|
),
|
|
314
319
|
)
|
|
@@ -21,6 +21,8 @@ module Apiwork
|
|
|
21
21
|
add_discriminator_field(fields) if @representation_class.subclass?
|
|
22
22
|
|
|
23
23
|
@representation_class.attributes.each do |name, attribute|
|
|
24
|
+
next if attribute.write_only?
|
|
25
|
+
|
|
24
26
|
value = @representation.respond_to?(name) ? @representation.public_send(name) : @representation.record.public_send(name)
|
|
25
27
|
value = map_type_column_output(name, value)
|
|
26
28
|
value = attribute.encode(value)
|
data/lib/apiwork/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- skiftle
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-04-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|