apiwork 0.7.0 → 0.7.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/README.md +7 -2
- data/lib/apiwork/api/object.rb +7 -6
- data/lib/apiwork/contract/object/validator.rb +1 -1
- data/lib/apiwork/contract/object.rb +8 -6
- data/lib/apiwork/object.rb +12 -4
- data/lib/apiwork/representation/attribute.rb +1 -1
- data/lib/apiwork/version.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5949ff5143ec3bdd3c0349b639eb17306ce00d32c6567a618bdd1f8f3474d9fc
|
|
4
|
+
data.tar.gz: 3d8e835b75f3c85725e17459ae24c6b6154002b7733f76315826a776799a9860
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 93ac9cbc50161930b09f247309256590241180080a710c2e49621874a654a0d70d02888a9972ed342058047312371b5de9f47f0039f4f09525991e2a3ba252a7
|
|
7
|
+
data.tar.gz: 757058cf4777c10627862c7dd4142473c76027f340042d636978a805c8adaa82e2c74963e366d168cb2140273e5e845bc3fba8bb9fe76d5d5f5a21d5ad9ce208
|
data/README.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
# Apiwork
|
|
2
2
|
|
|
3
|
-

|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
> 🚧 **Apiwork is pre-1.0 and working toward a stable 1.0.** Minor versions can still bring breaking changes, so follow the [changelog](./CHANGELOG.md).
|
|
8
|
+
|
|
9
|
+
---
|
|
5
10
|
|
|
6
11
|
[](https://rubygems.org/gems/apiwork)
|
|
7
12
|
[](https://github.com/skiftle/apiwork/actions/workflows/ci.yml)
|
data/lib/apiwork/api/object.rb
CHANGED
|
@@ -37,7 +37,7 @@ module Apiwork
|
|
|
37
37
|
# @param as [Symbol, nil] (nil)
|
|
38
38
|
# The target attribute name.
|
|
39
39
|
# @param default [Object] (UNSET)
|
|
40
|
-
# The default value. Omit to declare no default. Pass `nil` for an explicit null default.
|
|
40
|
+
# The default value. Omit to declare no default. Pass `nil` for an explicit null default. A param with a default is always optional.
|
|
41
41
|
# @param deprecated [Boolean] (false)
|
|
42
42
|
# Whether deprecated. Metadata included in exports.
|
|
43
43
|
# @param description [String, nil] (nil)
|
|
@@ -61,7 +61,7 @@ module Apiwork
|
|
|
61
61
|
# @param of [Symbol, Hash, nil] (nil)
|
|
62
62
|
# The element or value type. Arrays and records only.
|
|
63
63
|
# @param optional [Boolean] (false)
|
|
64
|
-
# Whether the param is optional.
|
|
64
|
+
# Whether the param is optional. Always `true` for params with a `default`.
|
|
65
65
|
# @param required [Boolean] (false)
|
|
66
66
|
# Whether the param is required.
|
|
67
67
|
# @param shape [API::Object, API::Union, nil] (nil)
|
|
@@ -103,6 +103,7 @@ module Apiwork
|
|
|
103
103
|
value: nil,
|
|
104
104
|
&block
|
|
105
105
|
)
|
|
106
|
+
optional = normalize_optional(optional, default)
|
|
106
107
|
resolved_of = resolve_of(of, type, &block)
|
|
107
108
|
resolved_shape = [:array, :record].include?(type) ? nil : (shape || build_shape(type, discriminator, &block))
|
|
108
109
|
discriminator = resolved_of&.discriminator if type == :array
|
|
@@ -140,7 +141,7 @@ module Apiwork
|
|
|
140
141
|
# @param as [Symbol, nil] (nil)
|
|
141
142
|
# The target attribute name.
|
|
142
143
|
# @param default [Object] (UNSET)
|
|
143
|
-
# The default value. Omit to declare no default. Pass `nil` for an explicit null default.
|
|
144
|
+
# The default value. Omit to declare no default. Pass `nil` for an explicit null default. A param with a default is always optional.
|
|
144
145
|
# @param deprecated [Boolean] (false)
|
|
145
146
|
# Whether deprecated. Metadata included in exports.
|
|
146
147
|
# @param description [String, nil] (nil)
|
|
@@ -148,7 +149,7 @@ module Apiwork
|
|
|
148
149
|
# @param nullable [Boolean] (false)
|
|
149
150
|
# Whether the value can be `null`.
|
|
150
151
|
# @param optional [Boolean] (false)
|
|
151
|
-
# Whether the param is optional.
|
|
152
|
+
# Whether the param is optional. Always `true` for params with a `default`.
|
|
152
153
|
# @param required [Boolean] (false)
|
|
153
154
|
# Whether the param is required.
|
|
154
155
|
# @yield block for defining element type
|
|
@@ -203,7 +204,7 @@ module Apiwork
|
|
|
203
204
|
# @param as [Symbol, nil] (nil)
|
|
204
205
|
# The target attribute name.
|
|
205
206
|
# @param default [Object] (UNSET)
|
|
206
|
-
# The default value. Omit to declare no default. Pass `nil` for an explicit null default.
|
|
207
|
+
# The default value. Omit to declare no default. Pass `nil` for an explicit null default. A param with a default is always optional.
|
|
207
208
|
# @param deprecated [Boolean] (false)
|
|
208
209
|
# Whether deprecated. Metadata included in exports.
|
|
209
210
|
# @param description [String, nil] (nil)
|
|
@@ -211,7 +212,7 @@ module Apiwork
|
|
|
211
212
|
# @param nullable [Boolean] (false)
|
|
212
213
|
# Whether the value can be `null`.
|
|
213
214
|
# @param optional [Boolean] (false)
|
|
214
|
-
# Whether the param is optional.
|
|
215
|
+
# Whether the param is optional. Always `true` for params with a `default`.
|
|
215
216
|
# @param required [Boolean] (false)
|
|
216
217
|
# Whether the param is required.
|
|
217
218
|
# @yield block for defining value type
|
|
@@ -76,7 +76,7 @@ module Apiwork
|
|
|
76
76
|
required_error = validate_required(name, value, param_options, data, field_path)
|
|
77
77
|
return [[required_error], NOT_SET] if required_error
|
|
78
78
|
|
|
79
|
-
value = param_options[:default] if value.nil? && param_options
|
|
79
|
+
value = param_options[:default] if value.nil? && param_options.key?(:default)
|
|
80
80
|
|
|
81
81
|
nullable_error = validate_nullable(name, value, param_options, data, field_path)
|
|
82
82
|
return [[nullable_error], NOT_SET] if nullable_error
|
|
@@ -61,7 +61,7 @@ module Apiwork
|
|
|
61
61
|
# @param as [Symbol, nil] (nil)
|
|
62
62
|
# The target attribute name.
|
|
63
63
|
# @param default [Object] (UNSET)
|
|
64
|
-
# The default value. Omit to declare no default. Pass `nil` for an explicit null default.
|
|
64
|
+
# The default value. Omit to declare no default. Pass `nil` for an explicit null default. A param with a default is always optional.
|
|
65
65
|
# @param deprecated [Boolean] (false)
|
|
66
66
|
# Whether deprecated. Metadata included in exports.
|
|
67
67
|
# @param description [String, nil] (nil)
|
|
@@ -85,7 +85,7 @@ module Apiwork
|
|
|
85
85
|
# @param of [Symbol, Hash, nil] (nil)
|
|
86
86
|
# The element or value type. Arrays and records only.
|
|
87
87
|
# @param optional [Boolean] (false)
|
|
88
|
-
# Whether the param is optional.
|
|
88
|
+
# Whether the param is optional. Always `true` for params with a `default`.
|
|
89
89
|
# @param required [Boolean] (false)
|
|
90
90
|
# Whether the param is required.
|
|
91
91
|
# @param shape [Contract::Object, Contract::Union, nil] (nil)
|
|
@@ -140,6 +140,8 @@ module Apiwork
|
|
|
140
140
|
|
|
141
141
|
raise ConfigurationError, 'discriminator can only be used with type: :union' if discriminator && type != :union
|
|
142
142
|
|
|
143
|
+
optional = normalize_optional(optional, default)
|
|
144
|
+
|
|
143
145
|
visited_types ||= @visited_types
|
|
144
146
|
visited_types ||= Set.new
|
|
145
147
|
|
|
@@ -184,7 +186,7 @@ module Apiwork
|
|
|
184
186
|
# @param as [Symbol, nil] (nil)
|
|
185
187
|
# The target attribute name.
|
|
186
188
|
# @param default [Object] (UNSET)
|
|
187
|
-
# The default value. Omit to declare no default. Pass `nil` for an explicit null default.
|
|
189
|
+
# The default value. Omit to declare no default. Pass `nil` for an explicit null default. A param with a default is always optional.
|
|
188
190
|
# @param deprecated [Boolean] (false)
|
|
189
191
|
# Whether deprecated. Metadata included in exports.
|
|
190
192
|
# @param description [String, nil] (nil)
|
|
@@ -196,7 +198,7 @@ module Apiwork
|
|
|
196
198
|
# @param nullable [Boolean] (false)
|
|
197
199
|
# Whether the value can be `null`.
|
|
198
200
|
# @param optional [Boolean] (false)
|
|
199
|
-
# Whether the param is optional.
|
|
201
|
+
# Whether the param is optional. Always `true` for params with a `default`.
|
|
200
202
|
# @param required [Boolean] (false)
|
|
201
203
|
# Whether the param is required.
|
|
202
204
|
# @yield block for defining element type
|
|
@@ -255,7 +257,7 @@ module Apiwork
|
|
|
255
257
|
# @param as [Symbol, nil] (nil)
|
|
256
258
|
# The target attribute name.
|
|
257
259
|
# @param default [Object] (UNSET)
|
|
258
|
-
# The default value. Omit to declare no default. Pass `nil` for an explicit null default.
|
|
260
|
+
# The default value. Omit to declare no default. Pass `nil` for an explicit null default. A param with a default is always optional.
|
|
259
261
|
# @param deprecated [Boolean] (false)
|
|
260
262
|
# Whether deprecated. Metadata included in exports.
|
|
261
263
|
# @param description [String, nil] (nil)
|
|
@@ -263,7 +265,7 @@ module Apiwork
|
|
|
263
265
|
# @param nullable [Boolean] (false)
|
|
264
266
|
# Whether the value can be `null`.
|
|
265
267
|
# @param optional [Boolean] (false)
|
|
266
|
-
# Whether the param is optional.
|
|
268
|
+
# Whether the param is optional. Always `true` for params with a `default`.
|
|
267
269
|
# @param required [Boolean] (false)
|
|
268
270
|
# Whether the param is required.
|
|
269
271
|
# @yield block for defining value type
|
data/lib/apiwork/object.rb
CHANGED
|
@@ -157,8 +157,8 @@ module Apiwork
|
|
|
157
157
|
# Whether the param is required.
|
|
158
158
|
# @return [void]
|
|
159
159
|
#
|
|
160
|
-
# @example Optional string
|
|
161
|
-
# string? :nickname
|
|
160
|
+
# @example Optional string
|
|
161
|
+
# string? :nickname
|
|
162
162
|
def string?(
|
|
163
163
|
name,
|
|
164
164
|
as: nil,
|
|
@@ -284,7 +284,7 @@ module Apiwork
|
|
|
284
284
|
# @return [void]
|
|
285
285
|
#
|
|
286
286
|
# @example Optional page number
|
|
287
|
-
# integer? :page, min: 1
|
|
287
|
+
# integer? :page, min: 1
|
|
288
288
|
def integer?(
|
|
289
289
|
name,
|
|
290
290
|
as: nil,
|
|
@@ -619,7 +619,7 @@ module Apiwork
|
|
|
619
619
|
# @return [void]
|
|
620
620
|
#
|
|
621
621
|
# @example Optional notification flag
|
|
622
|
-
# boolean? :notify
|
|
622
|
+
# boolean? :notify
|
|
623
623
|
def boolean?(
|
|
624
624
|
name,
|
|
625
625
|
as: nil,
|
|
@@ -1864,5 +1864,13 @@ module Apiwork
|
|
|
1864
1864
|
def param(name, type: nil, **options, &block)
|
|
1865
1865
|
raise NotImplementedError, "#{self.class} must implement #param"
|
|
1866
1866
|
end
|
|
1867
|
+
|
|
1868
|
+
private
|
|
1869
|
+
|
|
1870
|
+
def normalize_optional(optional, default)
|
|
1871
|
+
return true unless UNSET.equal?(default)
|
|
1872
|
+
|
|
1873
|
+
optional
|
|
1874
|
+
end
|
|
1867
1875
|
end
|
|
1868
1876
|
end
|
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.7.
|
|
4
|
+
version: 0.7.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-08-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -24,20 +24,6 @@ dependencies:
|
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '8.0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: bundler-audit
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0.9'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0.9'
|
|
41
27
|
- !ruby/object:Gem::Dependency
|
|
42
28
|
name: lefthook
|
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|