apiwork 0.0.0.pre → 0.1.2
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/LICENSE.txt +2 -2
- data/README.md +117 -1
- data/Rakefile +5 -3
- data/app/controllers/apiwork/errors_controller.rb +13 -0
- data/app/controllers/apiwork/exports_controller.rb +22 -0
- data/lib/apiwork/abstractable.rb +26 -0
- data/lib/apiwork/adapter/base.rb +369 -0
- data/lib/apiwork/adapter/builder/api/base.rb +66 -0
- data/lib/apiwork/adapter/builder/contract/base.rb +86 -0
- data/lib/apiwork/adapter/capability/api/base.rb +51 -0
- data/lib/apiwork/adapter/capability/api/scope.rb +64 -0
- data/lib/apiwork/adapter/capability/base.rb +291 -0
- data/lib/apiwork/adapter/capability/contract/base.rb +37 -0
- data/lib/apiwork/adapter/capability/contract/scope.rb +110 -0
- data/lib/apiwork/adapter/capability/operation/base.rb +172 -0
- data/lib/apiwork/adapter/capability/operation/metadata_shape.rb +165 -0
- data/lib/apiwork/adapter/capability/result.rb +21 -0
- data/lib/apiwork/adapter/capability/runner.rb +56 -0
- data/lib/apiwork/adapter/capability/transformer/request/base.rb +72 -0
- data/lib/apiwork/adapter/capability/transformer/response/base.rb +45 -0
- data/lib/apiwork/adapter/registry.rb +16 -0
- data/lib/apiwork/adapter/serializer/error/base.rb +72 -0
- data/lib/apiwork/adapter/serializer/error/default/api_builder.rb +32 -0
- data/lib/apiwork/adapter/serializer/error/default.rb +37 -0
- data/lib/apiwork/adapter/serializer/resource/base.rb +84 -0
- data/lib/apiwork/adapter/serializer/resource/default/contract_builder.rb +209 -0
- data/lib/apiwork/adapter/serializer/resource/default.rb +39 -0
- data/lib/apiwork/adapter/standard/capability/filtering/api_builder.rb +75 -0
- data/lib/apiwork/adapter/standard/capability/filtering/constants.rb +37 -0
- data/lib/apiwork/adapter/standard/capability/filtering/contract_builder.rb +193 -0
- data/lib/apiwork/adapter/standard/capability/filtering/operation/filter/builder.rb +47 -0
- data/lib/apiwork/adapter/standard/capability/filtering/operation/filter/operator_builder.rb +36 -0
- data/lib/apiwork/adapter/standard/capability/filtering/operation/filter.rb +462 -0
- data/lib/apiwork/adapter/standard/capability/filtering/operation.rb +22 -0
- data/lib/apiwork/adapter/standard/capability/filtering/request_transformer.rb +47 -0
- data/lib/apiwork/adapter/standard/capability/filtering.rb +18 -0
- data/lib/apiwork/adapter/standard/capability/including/contract_builder.rb +169 -0
- data/lib/apiwork/adapter/standard/capability/including/operation.rb +20 -0
- data/lib/apiwork/adapter/standard/capability/including.rb +16 -0
- data/lib/apiwork/adapter/standard/capability/pagination/api_builder.rb +34 -0
- data/lib/apiwork/adapter/standard/capability/pagination/contract_builder.rb +35 -0
- data/lib/apiwork/adapter/standard/capability/pagination/operation/paginate/cursor.rb +84 -0
- data/lib/apiwork/adapter/standard/capability/pagination/operation/paginate/offset.rb +66 -0
- data/lib/apiwork/adapter/standard/capability/pagination/operation/paginate.rb +24 -0
- data/lib/apiwork/adapter/standard/capability/pagination/operation.rb +24 -0
- data/lib/apiwork/adapter/standard/capability/pagination.rb +21 -0
- data/lib/apiwork/adapter/standard/capability/sorting/api_builder.rb +19 -0
- data/lib/apiwork/adapter/standard/capability/sorting/contract_builder.rb +84 -0
- data/lib/apiwork/adapter/standard/capability/sorting/operation/sort.rb +83 -0
- data/lib/apiwork/adapter/standard/capability/sorting/operation.rb +22 -0
- data/lib/apiwork/adapter/standard/capability/sorting.rb +17 -0
- data/lib/apiwork/adapter/standard/capability/writing/constants.rb +15 -0
- data/lib/apiwork/adapter/standard/capability/writing/contract_builder.rb +253 -0
- data/lib/apiwork/adapter/standard/capability/writing/operation/issue_mapper.rb +210 -0
- data/lib/apiwork/adapter/standard/capability/writing/operation.rb +32 -0
- data/lib/apiwork/adapter/standard/capability/writing/request_transformer.rb +37 -0
- data/lib/apiwork/adapter/standard/capability/writing.rb +17 -0
- data/lib/apiwork/adapter/standard/includes_resolver.rb +106 -0
- data/lib/apiwork/adapter/standard.rb +22 -0
- data/lib/apiwork/adapter/wrapper/base.rb +70 -0
- data/lib/apiwork/adapter/wrapper/collection/base.rb +60 -0
- data/lib/apiwork/adapter/wrapper/collection/default.rb +47 -0
- data/lib/apiwork/adapter/wrapper/error/base.rb +30 -0
- data/lib/apiwork/adapter/wrapper/error/default.rb +34 -0
- data/lib/apiwork/adapter/wrapper/member/base.rb +58 -0
- data/lib/apiwork/adapter/wrapper/member/default.rb +40 -0
- data/lib/apiwork/adapter/wrapper/shape.rb +203 -0
- data/lib/apiwork/adapter.rb +50 -0
- data/lib/apiwork/api/base.rb +802 -0
- data/lib/apiwork/api/element.rb +110 -0
- data/lib/apiwork/api/enum_registry/definition.rb +51 -0
- data/lib/apiwork/api/enum_registry.rb +98 -0
- data/lib/apiwork/api/info/contact.rb +67 -0
- data/lib/apiwork/api/info/license.rb +50 -0
- data/lib/apiwork/api/info/server.rb +50 -0
- data/lib/apiwork/api/info.rb +221 -0
- data/lib/apiwork/api/object.rb +235 -0
- data/lib/apiwork/api/registry.rb +33 -0
- data/lib/apiwork/api/representation_registry.rb +76 -0
- data/lib/apiwork/api/resource/action.rb +41 -0
- data/lib/apiwork/api/resource.rb +648 -0
- data/lib/apiwork/api/router.rb +104 -0
- data/lib/apiwork/api/type_registry/definition.rb +117 -0
- data/lib/apiwork/api/type_registry.rb +99 -0
- data/lib/apiwork/api/union.rb +49 -0
- data/lib/apiwork/api.rb +85 -0
- data/lib/apiwork/configurable.rb +71 -0
- data/lib/apiwork/configuration/option.rb +125 -0
- data/lib/apiwork/configuration/validatable.rb +25 -0
- data/lib/apiwork/configuration.rb +95 -0
- data/lib/apiwork/configuration_error.rb +6 -0
- data/lib/apiwork/constraint_error.rb +20 -0
- data/lib/apiwork/contract/action/request.rb +79 -0
- data/lib/apiwork/contract/action/response.rb +87 -0
- data/lib/apiwork/contract/action.rb +258 -0
- data/lib/apiwork/contract/base.rb +714 -0
- data/lib/apiwork/contract/element.rb +130 -0
- data/lib/apiwork/contract/object/coercer.rb +194 -0
- data/lib/apiwork/contract/object/deserializer.rb +101 -0
- data/lib/apiwork/contract/object/transformer.rb +95 -0
- data/lib/apiwork/contract/object/validator/result.rb +27 -0
- data/lib/apiwork/contract/object/validator.rb +734 -0
- data/lib/apiwork/contract/object.rb +566 -0
- data/lib/apiwork/contract/request_parser/result.rb +25 -0
- data/lib/apiwork/contract/request_parser.rb +72 -0
- data/lib/apiwork/contract/response_parser/result.rb +25 -0
- data/lib/apiwork/contract/response_parser.rb +35 -0
- data/lib/apiwork/contract/union.rb +56 -0
- data/lib/apiwork/contract_error.rb +9 -0
- data/lib/apiwork/controller.rb +300 -0
- data/lib/apiwork/domain_error.rb +13 -0
- data/lib/apiwork/element.rb +386 -0
- data/lib/apiwork/engine.rb +20 -0
- data/lib/apiwork/error.rb +6 -0
- data/lib/apiwork/error_code/definition.rb +63 -0
- data/lib/apiwork/error_code/registry.rb +18 -0
- data/lib/apiwork/error_code.rb +132 -0
- data/lib/apiwork/export/base.rb +291 -0
- data/lib/apiwork/export/open_api.rb +600 -0
- data/lib/apiwork/export/pipeline/writer.rb +66 -0
- data/lib/apiwork/export/pipeline.rb +84 -0
- data/lib/apiwork/export/registry.rb +16 -0
- data/lib/apiwork/export/surface_resolver.rb +189 -0
- data/lib/apiwork/export/type_analysis.rb +170 -0
- data/lib/apiwork/export/type_script.rb +23 -0
- data/lib/apiwork/export/type_script_mapper.rb +349 -0
- data/lib/apiwork/export/zod.rb +39 -0
- data/lib/apiwork/export/zod_mapper.rb +421 -0
- data/lib/apiwork/export.rb +80 -0
- data/lib/apiwork/http_error.rb +16 -0
- data/lib/apiwork/introspection/action/request.rb +66 -0
- data/lib/apiwork/introspection/action/response.rb +57 -0
- data/lib/apiwork/introspection/action.rb +124 -0
- data/lib/apiwork/introspection/api/info/contact.rb +59 -0
- data/lib/apiwork/introspection/api/info/license.rb +49 -0
- data/lib/apiwork/introspection/api/info/server.rb +50 -0
- data/lib/apiwork/introspection/api/info.rb +107 -0
- data/lib/apiwork/introspection/api/resource.rb +83 -0
- data/lib/apiwork/introspection/api.rb +92 -0
- data/lib/apiwork/introspection/contract.rb +63 -0
- data/lib/apiwork/introspection/dump/action.rb +101 -0
- data/lib/apiwork/introspection/dump/api.rb +119 -0
- data/lib/apiwork/introspection/dump/contract.rb +129 -0
- data/lib/apiwork/introspection/dump/param.rb +486 -0
- data/lib/apiwork/introspection/dump/resource.rb +112 -0
- data/lib/apiwork/introspection/dump/type.rb +339 -0
- data/lib/apiwork/introspection/dump.rb +17 -0
- data/lib/apiwork/introspection/enum.rb +63 -0
- data/lib/apiwork/introspection/error_code.rb +44 -0
- data/lib/apiwork/introspection/param/array.rb +88 -0
- data/lib/apiwork/introspection/param/base.rb +285 -0
- data/lib/apiwork/introspection/param/binary.rb +73 -0
- data/lib/apiwork/introspection/param/boolean.rb +73 -0
- data/lib/apiwork/introspection/param/date.rb +73 -0
- data/lib/apiwork/introspection/param/date_time.rb +73 -0
- data/lib/apiwork/introspection/param/decimal.rb +121 -0
- data/lib/apiwork/introspection/param/integer.rb +131 -0
- data/lib/apiwork/introspection/param/literal.rb +45 -0
- data/lib/apiwork/introspection/param/number.rb +121 -0
- data/lib/apiwork/introspection/param/object.rb +59 -0
- data/lib/apiwork/introspection/param/reference.rb +45 -0
- data/lib/apiwork/introspection/param/string.rb +122 -0
- data/lib/apiwork/introspection/param/time.rb +73 -0
- data/lib/apiwork/introspection/param/union.rb +57 -0
- data/lib/apiwork/introspection/param/unknown.rb +26 -0
- data/lib/apiwork/introspection/param/uuid.rb +73 -0
- data/lib/apiwork/introspection/param.rb +31 -0
- data/lib/apiwork/introspection/type.rb +129 -0
- data/lib/apiwork/introspection.rb +28 -0
- data/lib/apiwork/issue.rb +80 -0
- data/lib/apiwork/json_pointer.rb +21 -0
- data/lib/apiwork/object.rb +1618 -0
- data/lib/apiwork/reference_generator.rb +638 -0
- data/lib/apiwork/registry.rb +56 -0
- data/lib/apiwork/representation/association.rb +391 -0
- data/lib/apiwork/representation/attribute.rb +335 -0
- data/lib/apiwork/representation/base.rb +819 -0
- data/lib/apiwork/representation/deserializer.rb +95 -0
- data/lib/apiwork/representation/element.rb +128 -0
- data/lib/apiwork/representation/inheritance.rb +78 -0
- data/lib/apiwork/representation/model_detector.rb +75 -0
- data/lib/apiwork/representation/root_key.rb +35 -0
- data/lib/apiwork/representation/serializer.rb +127 -0
- data/lib/apiwork/request.rb +79 -0
- data/lib/apiwork/response.rb +56 -0
- data/lib/apiwork/union.rb +102 -0
- data/lib/apiwork/version.rb +2 -2
- data/lib/apiwork.rb +61 -3
- data/lib/generators/apiwork/api_generator.rb +38 -0
- data/lib/generators/apiwork/contract_generator.rb +25 -0
- data/lib/generators/apiwork/install_generator.rb +27 -0
- data/lib/generators/apiwork/representation_generator.rb +25 -0
- data/lib/generators/apiwork/templates/api/api.rb.tt +4 -0
- data/lib/generators/apiwork/templates/contract/contract.rb.tt +6 -0
- data/lib/generators/apiwork/templates/install/application_contract.rb.tt +5 -0
- data/lib/generators/apiwork/templates/install/application_representation.rb.tt +5 -0
- data/lib/generators/apiwork/templates/representation/representation.rb.tt +6 -0
- data/lib/tasks/apiwork.rake +102 -0
- metadata +319 -19
- data/.rubocop.yml +0 -8
- data/sig/apiwork.rbs +0 -4
|
@@ -0,0 +1,1618 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apiwork
|
|
4
|
+
class Object
|
|
5
|
+
attr_reader :merged,
|
|
6
|
+
:params
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@extends = []
|
|
10
|
+
@merged = []
|
|
11
|
+
@params = {}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @api public
|
|
15
|
+
# Inherits all properties from another type.
|
|
16
|
+
# Can be called multiple times to inherit from multiple types.
|
|
17
|
+
#
|
|
18
|
+
# @param type_name [Symbol, nil] (nil)
|
|
19
|
+
# The type to inherit from.
|
|
20
|
+
# @return [Array<Symbol>]
|
|
21
|
+
#
|
|
22
|
+
# @example Single inheritance
|
|
23
|
+
# object :admin do
|
|
24
|
+
# extends :user
|
|
25
|
+
# boolean :superuser
|
|
26
|
+
# end
|
|
27
|
+
#
|
|
28
|
+
# @example Multiple inheritance
|
|
29
|
+
# object :employee do
|
|
30
|
+
# extends :person
|
|
31
|
+
# extends :contactable
|
|
32
|
+
# string :employee_id
|
|
33
|
+
# end
|
|
34
|
+
def extends(type_name = nil)
|
|
35
|
+
@extends << type_name if type_name
|
|
36
|
+
@extends
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @api public
|
|
40
|
+
# Includes all properties from another type.
|
|
41
|
+
# Can be called multiple times to merge from multiple types.
|
|
42
|
+
#
|
|
43
|
+
# @param type_name [Symbol, nil] (nil)
|
|
44
|
+
# The type to merge from.
|
|
45
|
+
# @return [Array<Symbol>]
|
|
46
|
+
#
|
|
47
|
+
# @example
|
|
48
|
+
# object :admin do
|
|
49
|
+
# merge :user
|
|
50
|
+
# boolean :superuser
|
|
51
|
+
# end
|
|
52
|
+
def merge(type_name = nil)
|
|
53
|
+
@merged << type_name if type_name
|
|
54
|
+
@merged
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @api public
|
|
58
|
+
# Defines a string.
|
|
59
|
+
#
|
|
60
|
+
# @param name [Symbol]
|
|
61
|
+
# The name.
|
|
62
|
+
# @param as [Symbol, nil] (nil)
|
|
63
|
+
# The target attribute name.
|
|
64
|
+
# @param default [Object, nil] (nil)
|
|
65
|
+
# The default value.
|
|
66
|
+
# @param deprecated [Boolean] (false)
|
|
67
|
+
# Whether deprecated. Metadata included in exports.
|
|
68
|
+
# @param description [String, nil] (nil)
|
|
69
|
+
# The description. Metadata included in exports.
|
|
70
|
+
# @param enum [Array, Symbol, nil] (nil)
|
|
71
|
+
# The allowed values.
|
|
72
|
+
# @param example [String, nil] (nil)
|
|
73
|
+
# The example value. Metadata included in exports.
|
|
74
|
+
# @param format [Symbol, nil] (nil) [:date, :datetime, :email, :hostname, :ipv4, :ipv6, :password, :url, :uuid]
|
|
75
|
+
# Format hint for exports. Does not change the type, but exports may add validation or documentation based on it.
|
|
76
|
+
# Valid formats by type: `:string`.
|
|
77
|
+
# @param max [Integer, nil] (nil)
|
|
78
|
+
# The maximum length.
|
|
79
|
+
# @param min [Integer, nil] (nil)
|
|
80
|
+
# The minimum length.
|
|
81
|
+
# @param nullable [Boolean] (false)
|
|
82
|
+
# Whether the value can be `null`.
|
|
83
|
+
# @param optional [Boolean] (false)
|
|
84
|
+
# Whether the param is optional.
|
|
85
|
+
# @param required [Boolean] (false)
|
|
86
|
+
# Whether the param is required.
|
|
87
|
+
# @return [void]
|
|
88
|
+
#
|
|
89
|
+
# @example Basic string
|
|
90
|
+
# string :name
|
|
91
|
+
#
|
|
92
|
+
# @example With format validation
|
|
93
|
+
# string :email, format: :email
|
|
94
|
+
#
|
|
95
|
+
# @example With length constraints
|
|
96
|
+
# string :title, min: 1, max: 100
|
|
97
|
+
def string(
|
|
98
|
+
name,
|
|
99
|
+
as: nil,
|
|
100
|
+
default: nil,
|
|
101
|
+
deprecated: false,
|
|
102
|
+
description: nil,
|
|
103
|
+
enum: nil,
|
|
104
|
+
example: nil,
|
|
105
|
+
format: nil,
|
|
106
|
+
max: nil,
|
|
107
|
+
min: nil,
|
|
108
|
+
nullable: false,
|
|
109
|
+
optional: false,
|
|
110
|
+
required: false
|
|
111
|
+
)
|
|
112
|
+
param(
|
|
113
|
+
name,
|
|
114
|
+
as:,
|
|
115
|
+
default:,
|
|
116
|
+
deprecated:,
|
|
117
|
+
description:,
|
|
118
|
+
enum:,
|
|
119
|
+
example:,
|
|
120
|
+
format:,
|
|
121
|
+
max:,
|
|
122
|
+
min:,
|
|
123
|
+
nullable:,
|
|
124
|
+
optional:,
|
|
125
|
+
required:,
|
|
126
|
+
type: :string,
|
|
127
|
+
)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# @api public
|
|
131
|
+
# Defines an optional string.
|
|
132
|
+
#
|
|
133
|
+
# @param name [Symbol]
|
|
134
|
+
# The name.
|
|
135
|
+
# @param as [Symbol, nil] (nil)
|
|
136
|
+
# The target attribute name.
|
|
137
|
+
# @param default [Object, nil] (nil)
|
|
138
|
+
# The default value.
|
|
139
|
+
# @param deprecated [Boolean] (false)
|
|
140
|
+
# Whether deprecated. Metadata included in exports.
|
|
141
|
+
# @param description [String, nil] (nil)
|
|
142
|
+
# The description. Metadata included in exports.
|
|
143
|
+
# @param enum [Array, Symbol, nil] (nil)
|
|
144
|
+
# The allowed values.
|
|
145
|
+
# @param example [String, nil] (nil)
|
|
146
|
+
# The example value. Metadata included in exports.
|
|
147
|
+
# @param format [Symbol, nil] (nil) [:date, :datetime, :email, :hostname, :ipv4, :ipv6, :password, :url, :uuid]
|
|
148
|
+
# Format hint for exports. Does not change the type, but exports may add validation or documentation based on it.
|
|
149
|
+
# Valid formats by type: `:string`.
|
|
150
|
+
# @param max [Integer, nil] (nil)
|
|
151
|
+
# The maximum length.
|
|
152
|
+
# @param min [Integer, nil] (nil)
|
|
153
|
+
# The minimum length.
|
|
154
|
+
# @param nullable [Boolean] (false)
|
|
155
|
+
# Whether the value can be `null`.
|
|
156
|
+
# @param required [Boolean] (false)
|
|
157
|
+
# Whether the param is required.
|
|
158
|
+
# @return [void]
|
|
159
|
+
#
|
|
160
|
+
# @example Optional string with default
|
|
161
|
+
# string? :nickname, default: 'Anonymous'
|
|
162
|
+
def string?(
|
|
163
|
+
name,
|
|
164
|
+
as: nil,
|
|
165
|
+
default: nil,
|
|
166
|
+
deprecated: false,
|
|
167
|
+
description: nil,
|
|
168
|
+
enum: nil,
|
|
169
|
+
example: nil,
|
|
170
|
+
format: nil,
|
|
171
|
+
max: nil,
|
|
172
|
+
min: nil,
|
|
173
|
+
nullable: false,
|
|
174
|
+
required: false
|
|
175
|
+
)
|
|
176
|
+
param(
|
|
177
|
+
name,
|
|
178
|
+
as:,
|
|
179
|
+
default:,
|
|
180
|
+
deprecated:,
|
|
181
|
+
description:,
|
|
182
|
+
enum:,
|
|
183
|
+
example:,
|
|
184
|
+
format:,
|
|
185
|
+
max:,
|
|
186
|
+
min:,
|
|
187
|
+
nullable:,
|
|
188
|
+
required:,
|
|
189
|
+
optional: true,
|
|
190
|
+
type: :string,
|
|
191
|
+
)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# @api public
|
|
195
|
+
# Defines an integer.
|
|
196
|
+
#
|
|
197
|
+
# @param name [Symbol]
|
|
198
|
+
# The name.
|
|
199
|
+
# @param as [Symbol, nil] (nil)
|
|
200
|
+
# The target attribute name.
|
|
201
|
+
# @param default [Object, nil] (nil)
|
|
202
|
+
# The default value.
|
|
203
|
+
# @param deprecated [Boolean] (false)
|
|
204
|
+
# Whether deprecated. Metadata included in exports.
|
|
205
|
+
# @param description [String, nil] (nil)
|
|
206
|
+
# The description. Metadata included in exports.
|
|
207
|
+
# @param enum [Array, Symbol, nil] (nil)
|
|
208
|
+
# The allowed values.
|
|
209
|
+
# @param example [Integer, nil] (nil)
|
|
210
|
+
# The example value. Metadata included in exports.
|
|
211
|
+
# @param max [Integer, nil] (nil)
|
|
212
|
+
# The maximum value.
|
|
213
|
+
# @param min [Integer, nil] (nil)
|
|
214
|
+
# The minimum value.
|
|
215
|
+
# @param nullable [Boolean] (false)
|
|
216
|
+
# Whether the value can be `null`.
|
|
217
|
+
# @param optional [Boolean] (false)
|
|
218
|
+
# Whether the param is optional.
|
|
219
|
+
# @param required [Boolean] (false)
|
|
220
|
+
# Whether the param is required.
|
|
221
|
+
# @return [void]
|
|
222
|
+
#
|
|
223
|
+
# @example Basic integer
|
|
224
|
+
# integer :quantity
|
|
225
|
+
#
|
|
226
|
+
# @example With range constraints
|
|
227
|
+
# integer :age, min: 0, max: 150
|
|
228
|
+
def integer(
|
|
229
|
+
name,
|
|
230
|
+
as: nil,
|
|
231
|
+
default: nil,
|
|
232
|
+
deprecated: false,
|
|
233
|
+
description: nil,
|
|
234
|
+
enum: nil,
|
|
235
|
+
example: nil,
|
|
236
|
+
max: nil,
|
|
237
|
+
min: nil,
|
|
238
|
+
nullable: false,
|
|
239
|
+
optional: false,
|
|
240
|
+
required: false
|
|
241
|
+
)
|
|
242
|
+
param(
|
|
243
|
+
name,
|
|
244
|
+
as:,
|
|
245
|
+
default:,
|
|
246
|
+
deprecated:,
|
|
247
|
+
description:,
|
|
248
|
+
enum:,
|
|
249
|
+
example:,
|
|
250
|
+
max:,
|
|
251
|
+
min:,
|
|
252
|
+
nullable:,
|
|
253
|
+
optional:,
|
|
254
|
+
required:,
|
|
255
|
+
type: :integer,
|
|
256
|
+
)
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# @api public
|
|
260
|
+
# Defines an optional integer.
|
|
261
|
+
#
|
|
262
|
+
# @param name [Symbol]
|
|
263
|
+
# The name.
|
|
264
|
+
# @param as [Symbol, nil] (nil)
|
|
265
|
+
# The target attribute name.
|
|
266
|
+
# @param default [Object, nil] (nil)
|
|
267
|
+
# The default value.
|
|
268
|
+
# @param deprecated [Boolean] (false)
|
|
269
|
+
# Whether deprecated. Metadata included in exports.
|
|
270
|
+
# @param description [String, nil] (nil)
|
|
271
|
+
# The description. Metadata included in exports.
|
|
272
|
+
# @param enum [Array, Symbol, nil] (nil)
|
|
273
|
+
# The allowed values.
|
|
274
|
+
# @param example [Integer, nil] (nil)
|
|
275
|
+
# The example value. Metadata included in exports.
|
|
276
|
+
# @param max [Integer, nil] (nil)
|
|
277
|
+
# The maximum value.
|
|
278
|
+
# @param min [Integer, nil] (nil)
|
|
279
|
+
# The minimum value.
|
|
280
|
+
# @param nullable [Boolean] (false)
|
|
281
|
+
# Whether the value can be `null`.
|
|
282
|
+
# @param required [Boolean] (false)
|
|
283
|
+
# Whether the param is required.
|
|
284
|
+
# @return [void]
|
|
285
|
+
#
|
|
286
|
+
# @example Optional page number
|
|
287
|
+
# integer? :page, min: 1, default: 1
|
|
288
|
+
def integer?(
|
|
289
|
+
name,
|
|
290
|
+
as: nil,
|
|
291
|
+
default: nil,
|
|
292
|
+
deprecated: false,
|
|
293
|
+
description: nil,
|
|
294
|
+
enum: nil,
|
|
295
|
+
example: nil,
|
|
296
|
+
max: nil,
|
|
297
|
+
min: nil,
|
|
298
|
+
nullable: false,
|
|
299
|
+
required: false
|
|
300
|
+
)
|
|
301
|
+
param(
|
|
302
|
+
name,
|
|
303
|
+
as:,
|
|
304
|
+
default:,
|
|
305
|
+
deprecated:,
|
|
306
|
+
description:,
|
|
307
|
+
enum:,
|
|
308
|
+
example:,
|
|
309
|
+
max:,
|
|
310
|
+
min:,
|
|
311
|
+
nullable:,
|
|
312
|
+
required:,
|
|
313
|
+
optional: true,
|
|
314
|
+
type: :integer,
|
|
315
|
+
)
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
# @api public
|
|
319
|
+
# Defines a decimal.
|
|
320
|
+
#
|
|
321
|
+
# @param name [Symbol]
|
|
322
|
+
# The name.
|
|
323
|
+
# @param as [Symbol, nil] (nil)
|
|
324
|
+
# The target attribute name.
|
|
325
|
+
# @param default [Object, nil] (nil)
|
|
326
|
+
# The default value.
|
|
327
|
+
# @param deprecated [Boolean] (false)
|
|
328
|
+
# Whether deprecated. Metadata included in exports.
|
|
329
|
+
# @param description [String, nil] (nil)
|
|
330
|
+
# The description. Metadata included in exports.
|
|
331
|
+
# @param example [Numeric, nil] (nil)
|
|
332
|
+
# The example value. Metadata included in exports.
|
|
333
|
+
# @param max [Numeric, nil] (nil)
|
|
334
|
+
# The maximum value.
|
|
335
|
+
# @param min [Numeric, nil] (nil)
|
|
336
|
+
# The minimum value.
|
|
337
|
+
# @param nullable [Boolean] (false)
|
|
338
|
+
# Whether the value can be `null`.
|
|
339
|
+
# @param optional [Boolean] (false)
|
|
340
|
+
# Whether the param is optional.
|
|
341
|
+
# @param required [Boolean] (false)
|
|
342
|
+
# Whether the param is required.
|
|
343
|
+
# @return [void]
|
|
344
|
+
#
|
|
345
|
+
# @example Price with minimum
|
|
346
|
+
# decimal :amount, min: 0
|
|
347
|
+
#
|
|
348
|
+
# @example Percentage with range
|
|
349
|
+
# decimal :discount, min: 0, max: 100
|
|
350
|
+
def decimal(
|
|
351
|
+
name,
|
|
352
|
+
as: nil,
|
|
353
|
+
default: nil,
|
|
354
|
+
deprecated: false,
|
|
355
|
+
description: nil,
|
|
356
|
+
example: nil,
|
|
357
|
+
max: nil,
|
|
358
|
+
min: nil,
|
|
359
|
+
nullable: false,
|
|
360
|
+
optional: false,
|
|
361
|
+
required: false
|
|
362
|
+
)
|
|
363
|
+
param(
|
|
364
|
+
name,
|
|
365
|
+
as:,
|
|
366
|
+
default:,
|
|
367
|
+
deprecated:,
|
|
368
|
+
description:,
|
|
369
|
+
example:,
|
|
370
|
+
max:,
|
|
371
|
+
min:,
|
|
372
|
+
nullable:,
|
|
373
|
+
optional:,
|
|
374
|
+
required:,
|
|
375
|
+
type: :decimal,
|
|
376
|
+
)
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
# @api public
|
|
380
|
+
# Defines an optional decimal.
|
|
381
|
+
#
|
|
382
|
+
# @param name [Symbol]
|
|
383
|
+
# The name.
|
|
384
|
+
# @param as [Symbol, nil] (nil)
|
|
385
|
+
# The target attribute name.
|
|
386
|
+
# @param default [Object, nil] (nil)
|
|
387
|
+
# The default value.
|
|
388
|
+
# @param deprecated [Boolean] (false)
|
|
389
|
+
# Whether deprecated. Metadata included in exports.
|
|
390
|
+
# @param description [String, nil] (nil)
|
|
391
|
+
# The description. Metadata included in exports.
|
|
392
|
+
# @param example [Numeric, nil] (nil)
|
|
393
|
+
# The example value. Metadata included in exports.
|
|
394
|
+
# @param max [Numeric, nil] (nil)
|
|
395
|
+
# The maximum value.
|
|
396
|
+
# @param min [Numeric, nil] (nil)
|
|
397
|
+
# The minimum value.
|
|
398
|
+
# @param nullable [Boolean] (false)
|
|
399
|
+
# Whether the value can be `null`.
|
|
400
|
+
# @param required [Boolean] (false)
|
|
401
|
+
# Whether the param is required.
|
|
402
|
+
# @return [void]
|
|
403
|
+
#
|
|
404
|
+
# @example Optional tax rate
|
|
405
|
+
# decimal? :tax_rate, min: 0, max: 1
|
|
406
|
+
def decimal?(
|
|
407
|
+
name,
|
|
408
|
+
as: nil,
|
|
409
|
+
default: nil,
|
|
410
|
+
deprecated: false,
|
|
411
|
+
description: nil,
|
|
412
|
+
example: nil,
|
|
413
|
+
max: nil,
|
|
414
|
+
min: nil,
|
|
415
|
+
nullable: false,
|
|
416
|
+
required: false
|
|
417
|
+
)
|
|
418
|
+
param(
|
|
419
|
+
name,
|
|
420
|
+
as:,
|
|
421
|
+
default:,
|
|
422
|
+
deprecated:,
|
|
423
|
+
description:,
|
|
424
|
+
example:,
|
|
425
|
+
max:,
|
|
426
|
+
min:,
|
|
427
|
+
nullable:,
|
|
428
|
+
required:,
|
|
429
|
+
optional: true,
|
|
430
|
+
type: :decimal,
|
|
431
|
+
)
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
# @api public
|
|
435
|
+
# Defines a number.
|
|
436
|
+
#
|
|
437
|
+
# @param name [Symbol]
|
|
438
|
+
# The name.
|
|
439
|
+
# @param as [Symbol, nil] (nil)
|
|
440
|
+
# The target attribute name.
|
|
441
|
+
# @param default [Object, nil] (nil)
|
|
442
|
+
# The default value.
|
|
443
|
+
# @param deprecated [Boolean] (false)
|
|
444
|
+
# Whether deprecated. Metadata included in exports.
|
|
445
|
+
# @param description [String, nil] (nil)
|
|
446
|
+
# The description. Metadata included in exports.
|
|
447
|
+
# @param example [Numeric, nil] (nil)
|
|
448
|
+
# The example value. Metadata included in exports.
|
|
449
|
+
# @param max [Numeric, nil] (nil)
|
|
450
|
+
# The maximum value.
|
|
451
|
+
# @param min [Numeric, nil] (nil)
|
|
452
|
+
# The minimum value.
|
|
453
|
+
# @param nullable [Boolean] (false)
|
|
454
|
+
# Whether the value can be `null`.
|
|
455
|
+
# @param optional [Boolean] (false)
|
|
456
|
+
# Whether the param is optional.
|
|
457
|
+
# @param required [Boolean] (false)
|
|
458
|
+
# Whether the param is required.
|
|
459
|
+
# @return [void]
|
|
460
|
+
#
|
|
461
|
+
# @example Coordinate value
|
|
462
|
+
# number :latitude, min: -90, max: 90
|
|
463
|
+
def number(
|
|
464
|
+
name,
|
|
465
|
+
as: nil,
|
|
466
|
+
default: nil,
|
|
467
|
+
deprecated: false,
|
|
468
|
+
description: nil,
|
|
469
|
+
example: nil,
|
|
470
|
+
max: nil,
|
|
471
|
+
min: nil,
|
|
472
|
+
nullable: false,
|
|
473
|
+
optional: false,
|
|
474
|
+
required: false
|
|
475
|
+
)
|
|
476
|
+
param(
|
|
477
|
+
name,
|
|
478
|
+
as:,
|
|
479
|
+
default:,
|
|
480
|
+
deprecated:,
|
|
481
|
+
description:,
|
|
482
|
+
example:,
|
|
483
|
+
max:,
|
|
484
|
+
min:,
|
|
485
|
+
nullable:,
|
|
486
|
+
optional:,
|
|
487
|
+
required:,
|
|
488
|
+
type: :number,
|
|
489
|
+
)
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
# @api public
|
|
493
|
+
# Defines an optional number.
|
|
494
|
+
#
|
|
495
|
+
# @param name [Symbol]
|
|
496
|
+
# The name.
|
|
497
|
+
# @param as [Symbol, nil] (nil)
|
|
498
|
+
# The target attribute name.
|
|
499
|
+
# @param default [Object, nil] (nil)
|
|
500
|
+
# The default value.
|
|
501
|
+
# @param deprecated [Boolean] (false)
|
|
502
|
+
# Whether deprecated. Metadata included in exports.
|
|
503
|
+
# @param description [String, nil] (nil)
|
|
504
|
+
# The description. Metadata included in exports.
|
|
505
|
+
# @param example [Numeric, nil] (nil)
|
|
506
|
+
# The example value. Metadata included in exports.
|
|
507
|
+
# @param max [Numeric, nil] (nil)
|
|
508
|
+
# The maximum value.
|
|
509
|
+
# @param min [Numeric, nil] (nil)
|
|
510
|
+
# The minimum value.
|
|
511
|
+
# @param nullable [Boolean] (false)
|
|
512
|
+
# Whether the value can be `null`.
|
|
513
|
+
# @param required [Boolean] (false)
|
|
514
|
+
# Whether the param is required.
|
|
515
|
+
# @return [void]
|
|
516
|
+
#
|
|
517
|
+
# @example Optional score
|
|
518
|
+
# number? :score, min: 0, max: 100
|
|
519
|
+
def number?(
|
|
520
|
+
name,
|
|
521
|
+
as: nil,
|
|
522
|
+
default: nil,
|
|
523
|
+
deprecated: false,
|
|
524
|
+
description: nil,
|
|
525
|
+
example: nil,
|
|
526
|
+
max: nil,
|
|
527
|
+
min: nil,
|
|
528
|
+
nullable: false,
|
|
529
|
+
required: false
|
|
530
|
+
)
|
|
531
|
+
param(
|
|
532
|
+
name,
|
|
533
|
+
as:,
|
|
534
|
+
default:,
|
|
535
|
+
deprecated:,
|
|
536
|
+
description:,
|
|
537
|
+
example:,
|
|
538
|
+
max:,
|
|
539
|
+
min:,
|
|
540
|
+
nullable:,
|
|
541
|
+
required:,
|
|
542
|
+
optional: true,
|
|
543
|
+
type: :number,
|
|
544
|
+
)
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
# @api public
|
|
548
|
+
# Defines a boolean.
|
|
549
|
+
#
|
|
550
|
+
# @param name [Symbol]
|
|
551
|
+
# The name.
|
|
552
|
+
# @param as [Symbol, nil] (nil)
|
|
553
|
+
# The target attribute name.
|
|
554
|
+
# @param default [Object, nil] (nil)
|
|
555
|
+
# The default value.
|
|
556
|
+
# @param deprecated [Boolean] (false)
|
|
557
|
+
# Whether deprecated. Metadata included in exports.
|
|
558
|
+
# @param description [String, nil] (nil)
|
|
559
|
+
# The description. Metadata included in exports.
|
|
560
|
+
# @param example [Boolean, nil] (nil)
|
|
561
|
+
# The example value. Metadata included in exports.
|
|
562
|
+
# @param nullable [Boolean] (false)
|
|
563
|
+
# Whether the value can be `null`.
|
|
564
|
+
# @param optional [Boolean] (false)
|
|
565
|
+
# Whether the param is optional.
|
|
566
|
+
# @param required [Boolean] (false)
|
|
567
|
+
# Whether the param is required.
|
|
568
|
+
# @return [void]
|
|
569
|
+
#
|
|
570
|
+
# @example Active flag
|
|
571
|
+
# boolean :active
|
|
572
|
+
#
|
|
573
|
+
# @example With default
|
|
574
|
+
# boolean :published, default: false
|
|
575
|
+
def boolean(
|
|
576
|
+
name,
|
|
577
|
+
as: nil,
|
|
578
|
+
default: nil,
|
|
579
|
+
deprecated: false,
|
|
580
|
+
description: nil,
|
|
581
|
+
example: nil,
|
|
582
|
+
nullable: false,
|
|
583
|
+
optional: false,
|
|
584
|
+
required: false
|
|
585
|
+
)
|
|
586
|
+
param(
|
|
587
|
+
name,
|
|
588
|
+
as:,
|
|
589
|
+
default:,
|
|
590
|
+
deprecated:,
|
|
591
|
+
description:,
|
|
592
|
+
example:,
|
|
593
|
+
nullable:,
|
|
594
|
+
optional:,
|
|
595
|
+
required:,
|
|
596
|
+
type: :boolean,
|
|
597
|
+
)
|
|
598
|
+
end
|
|
599
|
+
|
|
600
|
+
# @api public
|
|
601
|
+
# Defines an optional boolean.
|
|
602
|
+
#
|
|
603
|
+
# @param name [Symbol]
|
|
604
|
+
# The name.
|
|
605
|
+
# @param as [Symbol, nil] (nil)
|
|
606
|
+
# The target attribute name.
|
|
607
|
+
# @param default [Object, nil] (nil)
|
|
608
|
+
# The default value.
|
|
609
|
+
# @param deprecated [Boolean] (false)
|
|
610
|
+
# Whether deprecated. Metadata included in exports.
|
|
611
|
+
# @param description [String, nil] (nil)
|
|
612
|
+
# The description. Metadata included in exports.
|
|
613
|
+
# @param example [Boolean, nil] (nil)
|
|
614
|
+
# The example value. Metadata included in exports.
|
|
615
|
+
# @param nullable [Boolean] (false)
|
|
616
|
+
# Whether the value can be `null`.
|
|
617
|
+
# @param required [Boolean] (false)
|
|
618
|
+
# Whether the param is required.
|
|
619
|
+
# @return [void]
|
|
620
|
+
#
|
|
621
|
+
# @example Optional notification flag
|
|
622
|
+
# boolean? :notify, default: true
|
|
623
|
+
def boolean?(
|
|
624
|
+
name,
|
|
625
|
+
as: nil,
|
|
626
|
+
default: nil,
|
|
627
|
+
deprecated: false,
|
|
628
|
+
description: nil,
|
|
629
|
+
example: nil,
|
|
630
|
+
nullable: false,
|
|
631
|
+
required: false
|
|
632
|
+
)
|
|
633
|
+
param(
|
|
634
|
+
name,
|
|
635
|
+
as:,
|
|
636
|
+
default:,
|
|
637
|
+
deprecated:,
|
|
638
|
+
description:,
|
|
639
|
+
example:,
|
|
640
|
+
nullable:,
|
|
641
|
+
required:,
|
|
642
|
+
optional: true,
|
|
643
|
+
type: :boolean,
|
|
644
|
+
)
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
# @api public
|
|
648
|
+
# Defines a datetime.
|
|
649
|
+
#
|
|
650
|
+
# @param name [Symbol]
|
|
651
|
+
# The name.
|
|
652
|
+
# @param as [Symbol, nil] (nil)
|
|
653
|
+
# The target attribute name.
|
|
654
|
+
# @param default [Object, nil] (nil)
|
|
655
|
+
# The default value.
|
|
656
|
+
# @param deprecated [Boolean] (false)
|
|
657
|
+
# Whether deprecated. Metadata included in exports.
|
|
658
|
+
# @param description [String, nil] (nil)
|
|
659
|
+
# The description. Metadata included in exports.
|
|
660
|
+
# @param example [String, nil] (nil)
|
|
661
|
+
# The example value. Metadata included in exports.
|
|
662
|
+
# @param nullable [Boolean] (false)
|
|
663
|
+
# Whether the value can be `null`.
|
|
664
|
+
# @param optional [Boolean] (false)
|
|
665
|
+
# Whether the param is optional.
|
|
666
|
+
# @param required [Boolean] (false)
|
|
667
|
+
# Whether the param is required.
|
|
668
|
+
# @return [void]
|
|
669
|
+
#
|
|
670
|
+
# @example Timestamp
|
|
671
|
+
# datetime :created_at
|
|
672
|
+
def datetime(
|
|
673
|
+
name,
|
|
674
|
+
as: nil,
|
|
675
|
+
default: nil,
|
|
676
|
+
deprecated: false,
|
|
677
|
+
description: nil,
|
|
678
|
+
example: nil,
|
|
679
|
+
nullable: false,
|
|
680
|
+
optional: false,
|
|
681
|
+
required: false
|
|
682
|
+
)
|
|
683
|
+
param(
|
|
684
|
+
name,
|
|
685
|
+
as:,
|
|
686
|
+
default:,
|
|
687
|
+
deprecated:,
|
|
688
|
+
description:,
|
|
689
|
+
example:,
|
|
690
|
+
nullable:,
|
|
691
|
+
optional:,
|
|
692
|
+
required:,
|
|
693
|
+
type: :datetime,
|
|
694
|
+
)
|
|
695
|
+
end
|
|
696
|
+
|
|
697
|
+
# @api public
|
|
698
|
+
# Defines an optional datetime.
|
|
699
|
+
#
|
|
700
|
+
# @param name [Symbol]
|
|
701
|
+
# The name.
|
|
702
|
+
# @param as [Symbol, nil] (nil)
|
|
703
|
+
# The target attribute name.
|
|
704
|
+
# @param default [Object, nil] (nil)
|
|
705
|
+
# The default value.
|
|
706
|
+
# @param deprecated [Boolean] (false)
|
|
707
|
+
# Whether deprecated. Metadata included in exports.
|
|
708
|
+
# @param description [String, nil] (nil)
|
|
709
|
+
# The description. Metadata included in exports.
|
|
710
|
+
# @param example [String, nil] (nil)
|
|
711
|
+
# The example value. Metadata included in exports.
|
|
712
|
+
# @param nullable [Boolean] (false)
|
|
713
|
+
# Whether the value can be `null`.
|
|
714
|
+
# @param required [Boolean] (false)
|
|
715
|
+
# Whether the param is required.
|
|
716
|
+
# @return [void]
|
|
717
|
+
#
|
|
718
|
+
# @example Optional deletion timestamp
|
|
719
|
+
# datetime? :deleted_at
|
|
720
|
+
def datetime?(
|
|
721
|
+
name,
|
|
722
|
+
as: nil,
|
|
723
|
+
default: nil,
|
|
724
|
+
deprecated: false,
|
|
725
|
+
description: nil,
|
|
726
|
+
example: nil,
|
|
727
|
+
nullable: false,
|
|
728
|
+
required: false
|
|
729
|
+
)
|
|
730
|
+
param(
|
|
731
|
+
name,
|
|
732
|
+
as:,
|
|
733
|
+
default:,
|
|
734
|
+
deprecated:,
|
|
735
|
+
description:,
|
|
736
|
+
example:,
|
|
737
|
+
nullable:,
|
|
738
|
+
required:,
|
|
739
|
+
optional: true,
|
|
740
|
+
type: :datetime,
|
|
741
|
+
)
|
|
742
|
+
end
|
|
743
|
+
|
|
744
|
+
# @api public
|
|
745
|
+
# Defines a date.
|
|
746
|
+
#
|
|
747
|
+
# @param name [Symbol]
|
|
748
|
+
# The name.
|
|
749
|
+
# @param as [Symbol, nil] (nil)
|
|
750
|
+
# The target attribute name.
|
|
751
|
+
# @param default [Object, nil] (nil)
|
|
752
|
+
# The default value.
|
|
753
|
+
# @param deprecated [Boolean] (false)
|
|
754
|
+
# Whether deprecated. Metadata included in exports.
|
|
755
|
+
# @param description [String, nil] (nil)
|
|
756
|
+
# The description. Metadata included in exports.
|
|
757
|
+
# @param example [String, nil] (nil)
|
|
758
|
+
# The example value. Metadata included in exports.
|
|
759
|
+
# @param nullable [Boolean] (false)
|
|
760
|
+
# Whether the value can be `null`.
|
|
761
|
+
# @param optional [Boolean] (false)
|
|
762
|
+
# Whether the param is optional.
|
|
763
|
+
# @param required [Boolean] (false)
|
|
764
|
+
# Whether the param is required.
|
|
765
|
+
# @return [void]
|
|
766
|
+
#
|
|
767
|
+
# @example Birth date
|
|
768
|
+
# date :birth_date
|
|
769
|
+
def date(
|
|
770
|
+
name,
|
|
771
|
+
as: nil,
|
|
772
|
+
default: nil,
|
|
773
|
+
deprecated: false,
|
|
774
|
+
description: nil,
|
|
775
|
+
example: nil,
|
|
776
|
+
nullable: false,
|
|
777
|
+
optional: false,
|
|
778
|
+
required: false
|
|
779
|
+
)
|
|
780
|
+
param(
|
|
781
|
+
name,
|
|
782
|
+
as:,
|
|
783
|
+
default:,
|
|
784
|
+
deprecated:,
|
|
785
|
+
description:,
|
|
786
|
+
example:,
|
|
787
|
+
nullable:,
|
|
788
|
+
optional:,
|
|
789
|
+
required:,
|
|
790
|
+
type: :date,
|
|
791
|
+
)
|
|
792
|
+
end
|
|
793
|
+
|
|
794
|
+
# @api public
|
|
795
|
+
# Defines an optional date.
|
|
796
|
+
#
|
|
797
|
+
# @param name [Symbol]
|
|
798
|
+
# The name.
|
|
799
|
+
# @param as [Symbol, nil] (nil)
|
|
800
|
+
# The target attribute name.
|
|
801
|
+
# @param default [Object, nil] (nil)
|
|
802
|
+
# The default value.
|
|
803
|
+
# @param deprecated [Boolean] (false)
|
|
804
|
+
# Whether deprecated. Metadata included in exports.
|
|
805
|
+
# @param description [String, nil] (nil)
|
|
806
|
+
# The description. Metadata included in exports.
|
|
807
|
+
# @param example [String, nil] (nil)
|
|
808
|
+
# The example value. Metadata included in exports.
|
|
809
|
+
# @param nullable [Boolean] (false)
|
|
810
|
+
# Whether the value can be `null`.
|
|
811
|
+
# @param required [Boolean] (false)
|
|
812
|
+
# Whether the param is required.
|
|
813
|
+
# @return [void]
|
|
814
|
+
#
|
|
815
|
+
# @example Optional expiry date
|
|
816
|
+
# date? :expires_on
|
|
817
|
+
def date?(
|
|
818
|
+
name,
|
|
819
|
+
as: nil,
|
|
820
|
+
default: nil,
|
|
821
|
+
deprecated: false,
|
|
822
|
+
description: nil,
|
|
823
|
+
example: nil,
|
|
824
|
+
nullable: false,
|
|
825
|
+
required: false
|
|
826
|
+
)
|
|
827
|
+
param(
|
|
828
|
+
name,
|
|
829
|
+
as:,
|
|
830
|
+
default:,
|
|
831
|
+
deprecated:,
|
|
832
|
+
description:,
|
|
833
|
+
example:,
|
|
834
|
+
nullable:,
|
|
835
|
+
required:,
|
|
836
|
+
optional: true,
|
|
837
|
+
type: :date,
|
|
838
|
+
)
|
|
839
|
+
end
|
|
840
|
+
|
|
841
|
+
# @api public
|
|
842
|
+
# Defines a UUID.
|
|
843
|
+
#
|
|
844
|
+
# @param name [Symbol]
|
|
845
|
+
# The name.
|
|
846
|
+
# @param as [Symbol, nil] (nil)
|
|
847
|
+
# The target attribute name.
|
|
848
|
+
# @param default [Object, nil] (nil)
|
|
849
|
+
# The default value.
|
|
850
|
+
# @param deprecated [Boolean] (false)
|
|
851
|
+
# Whether deprecated. Metadata included in exports.
|
|
852
|
+
# @param description [String, nil] (nil)
|
|
853
|
+
# The description. Metadata included in exports.
|
|
854
|
+
# @param example [String, nil] (nil)
|
|
855
|
+
# The example value. Metadata included in exports.
|
|
856
|
+
# @param nullable [Boolean] (false)
|
|
857
|
+
# Whether the value can be `null`.
|
|
858
|
+
# @param optional [Boolean] (false)
|
|
859
|
+
# Whether the param is optional.
|
|
860
|
+
# @param required [Boolean] (false)
|
|
861
|
+
# Whether the param is required.
|
|
862
|
+
# @return [void]
|
|
863
|
+
#
|
|
864
|
+
# @example Primary key
|
|
865
|
+
# uuid :id
|
|
866
|
+
def uuid(
|
|
867
|
+
name,
|
|
868
|
+
as: nil,
|
|
869
|
+
default: nil,
|
|
870
|
+
deprecated: false,
|
|
871
|
+
description: nil,
|
|
872
|
+
example: nil,
|
|
873
|
+
nullable: false,
|
|
874
|
+
optional: false,
|
|
875
|
+
required: false
|
|
876
|
+
)
|
|
877
|
+
param(
|
|
878
|
+
name,
|
|
879
|
+
as:,
|
|
880
|
+
default:,
|
|
881
|
+
deprecated:,
|
|
882
|
+
description:,
|
|
883
|
+
example:,
|
|
884
|
+
nullable:,
|
|
885
|
+
optional:,
|
|
886
|
+
required:,
|
|
887
|
+
type: :uuid,
|
|
888
|
+
)
|
|
889
|
+
end
|
|
890
|
+
|
|
891
|
+
# @api public
|
|
892
|
+
# Defines an optional UUID.
|
|
893
|
+
#
|
|
894
|
+
# @param name [Symbol]
|
|
895
|
+
# The name.
|
|
896
|
+
# @param as [Symbol, nil] (nil)
|
|
897
|
+
# The target attribute name.
|
|
898
|
+
# @param default [Object, nil] (nil)
|
|
899
|
+
# The default value.
|
|
900
|
+
# @param deprecated [Boolean] (false)
|
|
901
|
+
# Whether deprecated. Metadata included in exports.
|
|
902
|
+
# @param description [String, nil] (nil)
|
|
903
|
+
# The description. Metadata included in exports.
|
|
904
|
+
# @param example [String, nil] (nil)
|
|
905
|
+
# The example value. Metadata included in exports.
|
|
906
|
+
# @param nullable [Boolean] (false)
|
|
907
|
+
# Whether the value can be `null`.
|
|
908
|
+
# @param required [Boolean] (false)
|
|
909
|
+
# Whether the param is required.
|
|
910
|
+
# @return [void]
|
|
911
|
+
#
|
|
912
|
+
# @example Optional parent reference
|
|
913
|
+
# uuid? :parent_id
|
|
914
|
+
def uuid?(
|
|
915
|
+
name,
|
|
916
|
+
as: nil,
|
|
917
|
+
default: nil,
|
|
918
|
+
deprecated: false,
|
|
919
|
+
description: nil,
|
|
920
|
+
example: nil,
|
|
921
|
+
nullable: false,
|
|
922
|
+
required: false
|
|
923
|
+
)
|
|
924
|
+
param(
|
|
925
|
+
name,
|
|
926
|
+
as:,
|
|
927
|
+
default:,
|
|
928
|
+
deprecated:,
|
|
929
|
+
description:,
|
|
930
|
+
example:,
|
|
931
|
+
nullable:,
|
|
932
|
+
required:,
|
|
933
|
+
optional: true,
|
|
934
|
+
type: :uuid,
|
|
935
|
+
)
|
|
936
|
+
end
|
|
937
|
+
|
|
938
|
+
# @api public
|
|
939
|
+
# Defines a time.
|
|
940
|
+
#
|
|
941
|
+
# @param name [Symbol]
|
|
942
|
+
# The name.
|
|
943
|
+
# @param as [Symbol, nil] (nil)
|
|
944
|
+
# The target attribute name.
|
|
945
|
+
# @param default [Object, nil] (nil)
|
|
946
|
+
# The default value.
|
|
947
|
+
# @param deprecated [Boolean] (false)
|
|
948
|
+
# Whether deprecated. Metadata included in exports.
|
|
949
|
+
# @param description [String, nil] (nil)
|
|
950
|
+
# The description. Metadata included in exports.
|
|
951
|
+
# @param example [String, nil] (nil)
|
|
952
|
+
# The example value. Metadata included in exports.
|
|
953
|
+
# @param nullable [Boolean] (false)
|
|
954
|
+
# Whether the value can be `null`.
|
|
955
|
+
# @param optional [Boolean] (false)
|
|
956
|
+
# Whether the param is optional.
|
|
957
|
+
# @param required [Boolean] (false)
|
|
958
|
+
# Whether the param is required.
|
|
959
|
+
# @return [void]
|
|
960
|
+
#
|
|
961
|
+
# @example Opening time
|
|
962
|
+
# time :opens_at
|
|
963
|
+
def time(
|
|
964
|
+
name,
|
|
965
|
+
as: nil,
|
|
966
|
+
default: nil,
|
|
967
|
+
deprecated: false,
|
|
968
|
+
description: nil,
|
|
969
|
+
example: nil,
|
|
970
|
+
nullable: false,
|
|
971
|
+
optional: false,
|
|
972
|
+
required: false
|
|
973
|
+
)
|
|
974
|
+
param(
|
|
975
|
+
name,
|
|
976
|
+
as:,
|
|
977
|
+
default:,
|
|
978
|
+
deprecated:,
|
|
979
|
+
description:,
|
|
980
|
+
example:,
|
|
981
|
+
nullable:,
|
|
982
|
+
optional:,
|
|
983
|
+
required:,
|
|
984
|
+
type: :time,
|
|
985
|
+
)
|
|
986
|
+
end
|
|
987
|
+
|
|
988
|
+
# @api public
|
|
989
|
+
# Defines an optional time.
|
|
990
|
+
#
|
|
991
|
+
# @param name [Symbol]
|
|
992
|
+
# The name.
|
|
993
|
+
# @param as [Symbol, nil] (nil)
|
|
994
|
+
# The target attribute name.
|
|
995
|
+
# @param default [Object, nil] (nil)
|
|
996
|
+
# The default value.
|
|
997
|
+
# @param deprecated [Boolean] (false)
|
|
998
|
+
# Whether deprecated. Metadata included in exports.
|
|
999
|
+
# @param description [String, nil] (nil)
|
|
1000
|
+
# The description. Metadata included in exports.
|
|
1001
|
+
# @param example [String, nil] (nil)
|
|
1002
|
+
# The example value. Metadata included in exports.
|
|
1003
|
+
# @param nullable [Boolean] (false)
|
|
1004
|
+
# Whether the value can be `null`.
|
|
1005
|
+
# @param required [Boolean] (false)
|
|
1006
|
+
# Whether the param is required.
|
|
1007
|
+
# @return [void]
|
|
1008
|
+
#
|
|
1009
|
+
# @example Optional closing time
|
|
1010
|
+
# time? :closes_at
|
|
1011
|
+
def time?(
|
|
1012
|
+
name,
|
|
1013
|
+
as: nil,
|
|
1014
|
+
default: nil,
|
|
1015
|
+
deprecated: false,
|
|
1016
|
+
description: nil,
|
|
1017
|
+
example: nil,
|
|
1018
|
+
nullable: false,
|
|
1019
|
+
required: false
|
|
1020
|
+
)
|
|
1021
|
+
param(
|
|
1022
|
+
name,
|
|
1023
|
+
as:,
|
|
1024
|
+
default:,
|
|
1025
|
+
deprecated:,
|
|
1026
|
+
description:,
|
|
1027
|
+
example:,
|
|
1028
|
+
nullable:,
|
|
1029
|
+
required:,
|
|
1030
|
+
optional: true,
|
|
1031
|
+
type: :time,
|
|
1032
|
+
)
|
|
1033
|
+
end
|
|
1034
|
+
|
|
1035
|
+
# @api public
|
|
1036
|
+
# Defines a binary.
|
|
1037
|
+
#
|
|
1038
|
+
# @param name [Symbol]
|
|
1039
|
+
# The name.
|
|
1040
|
+
# @param as [Symbol, nil] (nil)
|
|
1041
|
+
# The target attribute name.
|
|
1042
|
+
# @param default [Object, nil] (nil)
|
|
1043
|
+
# The default value.
|
|
1044
|
+
# @param deprecated [Boolean] (false)
|
|
1045
|
+
# Whether deprecated. Metadata included in exports.
|
|
1046
|
+
# @param description [String, nil] (nil)
|
|
1047
|
+
# The description. Metadata included in exports.
|
|
1048
|
+
# @param example [String, nil] (nil)
|
|
1049
|
+
# The example value. Metadata included in exports.
|
|
1050
|
+
# @param nullable [Boolean] (false)
|
|
1051
|
+
# Whether the value can be `null`.
|
|
1052
|
+
# @param optional [Boolean] (false)
|
|
1053
|
+
# Whether the param is optional.
|
|
1054
|
+
# @param required [Boolean] (false)
|
|
1055
|
+
# Whether the param is required.
|
|
1056
|
+
# @return [void]
|
|
1057
|
+
#
|
|
1058
|
+
# @example File content
|
|
1059
|
+
# binary :content
|
|
1060
|
+
def binary(
|
|
1061
|
+
name,
|
|
1062
|
+
as: nil,
|
|
1063
|
+
default: nil,
|
|
1064
|
+
deprecated: false,
|
|
1065
|
+
description: nil,
|
|
1066
|
+
example: nil,
|
|
1067
|
+
nullable: false,
|
|
1068
|
+
optional: false,
|
|
1069
|
+
required: false
|
|
1070
|
+
)
|
|
1071
|
+
param(
|
|
1072
|
+
name,
|
|
1073
|
+
as:,
|
|
1074
|
+
default:,
|
|
1075
|
+
deprecated:,
|
|
1076
|
+
description:,
|
|
1077
|
+
example:,
|
|
1078
|
+
nullable:,
|
|
1079
|
+
optional:,
|
|
1080
|
+
required:,
|
|
1081
|
+
type: :binary,
|
|
1082
|
+
)
|
|
1083
|
+
end
|
|
1084
|
+
|
|
1085
|
+
# @api public
|
|
1086
|
+
# Defines an optional binary.
|
|
1087
|
+
#
|
|
1088
|
+
# @param name [Symbol]
|
|
1089
|
+
# The name.
|
|
1090
|
+
# @param as [Symbol, nil] (nil)
|
|
1091
|
+
# The target attribute name.
|
|
1092
|
+
# @param default [Object, nil] (nil)
|
|
1093
|
+
# The default value.
|
|
1094
|
+
# @param deprecated [Boolean] (false)
|
|
1095
|
+
# Whether deprecated. Metadata included in exports.
|
|
1096
|
+
# @param description [String, nil] (nil)
|
|
1097
|
+
# The description. Metadata included in exports.
|
|
1098
|
+
# @param example [String, nil] (nil)
|
|
1099
|
+
# The example value. Metadata included in exports.
|
|
1100
|
+
# @param nullable [Boolean] (false)
|
|
1101
|
+
# Whether the value can be `null`.
|
|
1102
|
+
# @param required [Boolean] (false)
|
|
1103
|
+
# Whether the param is required.
|
|
1104
|
+
# @return [void]
|
|
1105
|
+
#
|
|
1106
|
+
# @example Optional attachment
|
|
1107
|
+
# binary? :attachment
|
|
1108
|
+
def binary?(
|
|
1109
|
+
name,
|
|
1110
|
+
as: nil,
|
|
1111
|
+
default: nil,
|
|
1112
|
+
deprecated: false,
|
|
1113
|
+
description: nil,
|
|
1114
|
+
example: nil,
|
|
1115
|
+
nullable: false,
|
|
1116
|
+
required: false
|
|
1117
|
+
)
|
|
1118
|
+
param(
|
|
1119
|
+
name,
|
|
1120
|
+
as:,
|
|
1121
|
+
default:,
|
|
1122
|
+
deprecated:,
|
|
1123
|
+
description:,
|
|
1124
|
+
example:,
|
|
1125
|
+
nullable:,
|
|
1126
|
+
required:,
|
|
1127
|
+
optional: true,
|
|
1128
|
+
type: :binary,
|
|
1129
|
+
)
|
|
1130
|
+
end
|
|
1131
|
+
|
|
1132
|
+
# @api public
|
|
1133
|
+
# Defines an object.
|
|
1134
|
+
#
|
|
1135
|
+
# @param name [Symbol]
|
|
1136
|
+
# The name.
|
|
1137
|
+
# @param as [Symbol, nil] (nil)
|
|
1138
|
+
# The target attribute name.
|
|
1139
|
+
# @param default [Object, nil] (nil)
|
|
1140
|
+
# The default value.
|
|
1141
|
+
# @param deprecated [Boolean] (false)
|
|
1142
|
+
# Whether deprecated. Metadata included in exports.
|
|
1143
|
+
# @param description [String, nil] (nil)
|
|
1144
|
+
# The description. Metadata included in exports.
|
|
1145
|
+
# @param nullable [Boolean] (false)
|
|
1146
|
+
# Whether the value can be `null`.
|
|
1147
|
+
# @param optional [Boolean] (false)
|
|
1148
|
+
# Whether the param is optional.
|
|
1149
|
+
# @param required [Boolean] (false)
|
|
1150
|
+
# Whether the param is required.
|
|
1151
|
+
# @yield block defining nested structure
|
|
1152
|
+
# @return [void]
|
|
1153
|
+
#
|
|
1154
|
+
# @example Nested address object
|
|
1155
|
+
# object :address do
|
|
1156
|
+
# string :street
|
|
1157
|
+
# string :city
|
|
1158
|
+
# string :country
|
|
1159
|
+
# end
|
|
1160
|
+
def object(
|
|
1161
|
+
name,
|
|
1162
|
+
as: nil,
|
|
1163
|
+
default: nil,
|
|
1164
|
+
deprecated: false,
|
|
1165
|
+
description: nil,
|
|
1166
|
+
nullable: false,
|
|
1167
|
+
optional: false,
|
|
1168
|
+
required: false,
|
|
1169
|
+
&block
|
|
1170
|
+
)
|
|
1171
|
+
param(
|
|
1172
|
+
name,
|
|
1173
|
+
as:,
|
|
1174
|
+
default:,
|
|
1175
|
+
deprecated:,
|
|
1176
|
+
description:,
|
|
1177
|
+
nullable:,
|
|
1178
|
+
optional:,
|
|
1179
|
+
required:,
|
|
1180
|
+
type: :object,
|
|
1181
|
+
&block
|
|
1182
|
+
)
|
|
1183
|
+
end
|
|
1184
|
+
|
|
1185
|
+
# @api public
|
|
1186
|
+
# Defines an optional object.
|
|
1187
|
+
#
|
|
1188
|
+
# @param name [Symbol]
|
|
1189
|
+
# The name.
|
|
1190
|
+
# @param as [Symbol, nil] (nil)
|
|
1191
|
+
# The target attribute name.
|
|
1192
|
+
# @param default [Object, nil] (nil)
|
|
1193
|
+
# The default value.
|
|
1194
|
+
# @param deprecated [Boolean] (false)
|
|
1195
|
+
# Whether deprecated. Metadata included in exports.
|
|
1196
|
+
# @param description [String, nil] (nil)
|
|
1197
|
+
# The description. Metadata included in exports.
|
|
1198
|
+
# @param nullable [Boolean] (false)
|
|
1199
|
+
# Whether the value can be `null`.
|
|
1200
|
+
# @param required [Boolean] (false)
|
|
1201
|
+
# Whether the param is required.
|
|
1202
|
+
# @yield block defining nested structure
|
|
1203
|
+
# @return [void]
|
|
1204
|
+
#
|
|
1205
|
+
# @example Optional metadata
|
|
1206
|
+
# object? :metadata do
|
|
1207
|
+
# string :key
|
|
1208
|
+
# string :value
|
|
1209
|
+
# end
|
|
1210
|
+
def object?(
|
|
1211
|
+
name,
|
|
1212
|
+
as: nil,
|
|
1213
|
+
default: nil,
|
|
1214
|
+
deprecated: false,
|
|
1215
|
+
description: nil,
|
|
1216
|
+
nullable: false,
|
|
1217
|
+
required: false,
|
|
1218
|
+
&block
|
|
1219
|
+
)
|
|
1220
|
+
param(
|
|
1221
|
+
name,
|
|
1222
|
+
as:,
|
|
1223
|
+
default:,
|
|
1224
|
+
deprecated:,
|
|
1225
|
+
description:,
|
|
1226
|
+
nullable:,
|
|
1227
|
+
required:,
|
|
1228
|
+
optional: true,
|
|
1229
|
+
type: :object,
|
|
1230
|
+
&block
|
|
1231
|
+
)
|
|
1232
|
+
end
|
|
1233
|
+
|
|
1234
|
+
# @api public
|
|
1235
|
+
# Defines an array.
|
|
1236
|
+
#
|
|
1237
|
+
# @param name [Symbol]
|
|
1238
|
+
# The name.
|
|
1239
|
+
# @param as [Symbol, nil] (nil)
|
|
1240
|
+
# The target attribute name.
|
|
1241
|
+
# @param default [Object, nil] (nil)
|
|
1242
|
+
# The default value.
|
|
1243
|
+
# @param deprecated [Boolean] (false)
|
|
1244
|
+
# Whether deprecated. Metadata included in exports.
|
|
1245
|
+
# @param description [String, nil] (nil)
|
|
1246
|
+
# The description. Metadata included in exports.
|
|
1247
|
+
# @param nullable [Boolean] (false)
|
|
1248
|
+
# Whether the value can be `null`.
|
|
1249
|
+
# @param of [Symbol, Hash, nil] (nil)
|
|
1250
|
+
# The element type. Arrays only.
|
|
1251
|
+
# @param optional [Boolean] (false)
|
|
1252
|
+
# Whether the param is optional.
|
|
1253
|
+
# @param required [Boolean] (false)
|
|
1254
|
+
# Whether the param is required.
|
|
1255
|
+
# @yield block defining element type
|
|
1256
|
+
# @return [void]
|
|
1257
|
+
#
|
|
1258
|
+
# @example Array of strings
|
|
1259
|
+
# array :tags do
|
|
1260
|
+
# string
|
|
1261
|
+
# end
|
|
1262
|
+
#
|
|
1263
|
+
# @example Array of objects
|
|
1264
|
+
# array :items do
|
|
1265
|
+
# object do
|
|
1266
|
+
# string :name
|
|
1267
|
+
# decimal :price
|
|
1268
|
+
# end
|
|
1269
|
+
# end
|
|
1270
|
+
def array(
|
|
1271
|
+
name,
|
|
1272
|
+
as: nil,
|
|
1273
|
+
default: nil,
|
|
1274
|
+
deprecated: false,
|
|
1275
|
+
description: nil,
|
|
1276
|
+
nullable: false,
|
|
1277
|
+
of: nil,
|
|
1278
|
+
optional: false,
|
|
1279
|
+
required: false,
|
|
1280
|
+
&block
|
|
1281
|
+
)
|
|
1282
|
+
param(
|
|
1283
|
+
name,
|
|
1284
|
+
as:,
|
|
1285
|
+
default:,
|
|
1286
|
+
deprecated:,
|
|
1287
|
+
description:,
|
|
1288
|
+
nullable:,
|
|
1289
|
+
of:,
|
|
1290
|
+
optional:,
|
|
1291
|
+
required:,
|
|
1292
|
+
type: :array,
|
|
1293
|
+
&block
|
|
1294
|
+
)
|
|
1295
|
+
end
|
|
1296
|
+
|
|
1297
|
+
# @api public
|
|
1298
|
+
# Defines an optional array.
|
|
1299
|
+
#
|
|
1300
|
+
# @param name [Symbol]
|
|
1301
|
+
# The name.
|
|
1302
|
+
# @param as [Symbol, nil] (nil)
|
|
1303
|
+
# The target attribute name.
|
|
1304
|
+
# @param default [Object, nil] (nil)
|
|
1305
|
+
# The default value.
|
|
1306
|
+
# @param deprecated [Boolean] (false)
|
|
1307
|
+
# Whether deprecated. Metadata included in exports.
|
|
1308
|
+
# @param description [String, nil] (nil)
|
|
1309
|
+
# The description. Metadata included in exports.
|
|
1310
|
+
# @param nullable [Boolean] (false)
|
|
1311
|
+
# Whether the value can be `null`.
|
|
1312
|
+
# @param of [Symbol, Hash, nil] (nil)
|
|
1313
|
+
# The element type. Arrays only.
|
|
1314
|
+
# @param required [Boolean] (false)
|
|
1315
|
+
# Whether the param is required.
|
|
1316
|
+
# @yield block defining element type
|
|
1317
|
+
# @return [void]
|
|
1318
|
+
#
|
|
1319
|
+
# @example Optional array of labels
|
|
1320
|
+
# array? :labels do
|
|
1321
|
+
# string
|
|
1322
|
+
# end
|
|
1323
|
+
def array?(
|
|
1324
|
+
name,
|
|
1325
|
+
as: nil,
|
|
1326
|
+
default: nil,
|
|
1327
|
+
deprecated: false,
|
|
1328
|
+
description: nil,
|
|
1329
|
+
nullable: false,
|
|
1330
|
+
of: nil,
|
|
1331
|
+
required: false,
|
|
1332
|
+
&block
|
|
1333
|
+
)
|
|
1334
|
+
param(
|
|
1335
|
+
name,
|
|
1336
|
+
as:,
|
|
1337
|
+
default:,
|
|
1338
|
+
deprecated:,
|
|
1339
|
+
description:,
|
|
1340
|
+
nullable:,
|
|
1341
|
+
of:,
|
|
1342
|
+
required:,
|
|
1343
|
+
optional: true,
|
|
1344
|
+
type: :array,
|
|
1345
|
+
&block
|
|
1346
|
+
)
|
|
1347
|
+
end
|
|
1348
|
+
|
|
1349
|
+
# @api public
|
|
1350
|
+
# Defines a union.
|
|
1351
|
+
#
|
|
1352
|
+
# @param name [Symbol]
|
|
1353
|
+
# The name.
|
|
1354
|
+
# @param as [Symbol, nil] (nil)
|
|
1355
|
+
# The target attribute name.
|
|
1356
|
+
# @param default [Object, nil] (nil)
|
|
1357
|
+
# The default value.
|
|
1358
|
+
# @param deprecated [Boolean] (false)
|
|
1359
|
+
# Whether deprecated. Metadata included in exports.
|
|
1360
|
+
# @param description [String, nil] (nil)
|
|
1361
|
+
# The description. Metadata included in exports.
|
|
1362
|
+
# @param discriminator [Symbol, nil] (nil)
|
|
1363
|
+
# The discriminator field name. Unions only.
|
|
1364
|
+
# @param nullable [Boolean] (false)
|
|
1365
|
+
# Whether the value can be `null`.
|
|
1366
|
+
# @param optional [Boolean] (false)
|
|
1367
|
+
# Whether the param is optional.
|
|
1368
|
+
# @param required [Boolean] (false)
|
|
1369
|
+
# Whether the param is required.
|
|
1370
|
+
# @yield block defining union variants
|
|
1371
|
+
# @return [void]
|
|
1372
|
+
#
|
|
1373
|
+
# @example Payment method union
|
|
1374
|
+
# union :payment_method, discriminator: :type do
|
|
1375
|
+
# variant tag: 'card' do
|
|
1376
|
+
# object do
|
|
1377
|
+
# string :last_four
|
|
1378
|
+
# end
|
|
1379
|
+
# end
|
|
1380
|
+
# variant tag: 'bank' do
|
|
1381
|
+
# object do
|
|
1382
|
+
# string :account_number
|
|
1383
|
+
# end
|
|
1384
|
+
# end
|
|
1385
|
+
# end
|
|
1386
|
+
def union(
|
|
1387
|
+
name,
|
|
1388
|
+
as: nil,
|
|
1389
|
+
default: nil,
|
|
1390
|
+
deprecated: false,
|
|
1391
|
+
description: nil,
|
|
1392
|
+
discriminator: nil,
|
|
1393
|
+
nullable: false,
|
|
1394
|
+
optional: false,
|
|
1395
|
+
required: false,
|
|
1396
|
+
&block
|
|
1397
|
+
)
|
|
1398
|
+
param(
|
|
1399
|
+
name,
|
|
1400
|
+
as:,
|
|
1401
|
+
default:,
|
|
1402
|
+
deprecated:,
|
|
1403
|
+
description:,
|
|
1404
|
+
discriminator:,
|
|
1405
|
+
nullable:,
|
|
1406
|
+
optional:,
|
|
1407
|
+
required:,
|
|
1408
|
+
type: :union,
|
|
1409
|
+
&block
|
|
1410
|
+
)
|
|
1411
|
+
end
|
|
1412
|
+
|
|
1413
|
+
# @api public
|
|
1414
|
+
# Defines an optional union.
|
|
1415
|
+
#
|
|
1416
|
+
# @param name [Symbol]
|
|
1417
|
+
# The name.
|
|
1418
|
+
# @param as [Symbol, nil] (nil)
|
|
1419
|
+
# The target attribute name.
|
|
1420
|
+
# @param default [Object, nil] (nil)
|
|
1421
|
+
# The default value.
|
|
1422
|
+
# @param deprecated [Boolean] (false)
|
|
1423
|
+
# Whether deprecated. Metadata included in exports.
|
|
1424
|
+
# @param description [String, nil] (nil)
|
|
1425
|
+
# The description. Metadata included in exports.
|
|
1426
|
+
# @param discriminator [Symbol, nil] (nil)
|
|
1427
|
+
# The discriminator field name. Unions only.
|
|
1428
|
+
# @param nullable [Boolean] (false)
|
|
1429
|
+
# Whether the value can be `null`.
|
|
1430
|
+
# @param required [Boolean] (false)
|
|
1431
|
+
# Whether the param is required.
|
|
1432
|
+
# @yield block defining union variants
|
|
1433
|
+
# @return [void]
|
|
1434
|
+
#
|
|
1435
|
+
# @example Optional notification preference
|
|
1436
|
+
# union? :notification, discriminator: :type do
|
|
1437
|
+
# variant tag: 'email' do
|
|
1438
|
+
# object do
|
|
1439
|
+
# string :address
|
|
1440
|
+
# end
|
|
1441
|
+
# end
|
|
1442
|
+
# variant tag: 'sms' do
|
|
1443
|
+
# object do
|
|
1444
|
+
# string :phone
|
|
1445
|
+
# end
|
|
1446
|
+
# end
|
|
1447
|
+
# end
|
|
1448
|
+
def union?(
|
|
1449
|
+
name,
|
|
1450
|
+
as: nil,
|
|
1451
|
+
default: nil,
|
|
1452
|
+
deprecated: false,
|
|
1453
|
+
description: nil,
|
|
1454
|
+
discriminator: nil,
|
|
1455
|
+
nullable: false,
|
|
1456
|
+
required: false,
|
|
1457
|
+
&block
|
|
1458
|
+
)
|
|
1459
|
+
param(
|
|
1460
|
+
name,
|
|
1461
|
+
as:,
|
|
1462
|
+
default:,
|
|
1463
|
+
deprecated:,
|
|
1464
|
+
description:,
|
|
1465
|
+
discriminator:,
|
|
1466
|
+
nullable:,
|
|
1467
|
+
required:,
|
|
1468
|
+
optional: true,
|
|
1469
|
+
type: :union,
|
|
1470
|
+
&block
|
|
1471
|
+
)
|
|
1472
|
+
end
|
|
1473
|
+
|
|
1474
|
+
# @api public
|
|
1475
|
+
# Defines a literal value.
|
|
1476
|
+
#
|
|
1477
|
+
# @param name [Symbol]
|
|
1478
|
+
# The name.
|
|
1479
|
+
# @param value [Object]
|
|
1480
|
+
# The exact value.
|
|
1481
|
+
# @param as [Symbol, nil] (nil)
|
|
1482
|
+
# The target attribute name.
|
|
1483
|
+
# @param default [Object, nil] (nil)
|
|
1484
|
+
# The default value.
|
|
1485
|
+
# @param deprecated [Boolean] (false)
|
|
1486
|
+
# Whether deprecated. Metadata included in exports.
|
|
1487
|
+
# @param description [String, nil] (nil)
|
|
1488
|
+
# The description. Metadata included in exports.
|
|
1489
|
+
# @param optional [Boolean] (false)
|
|
1490
|
+
# Whether the param is optional.
|
|
1491
|
+
# @return [void]
|
|
1492
|
+
#
|
|
1493
|
+
# @example Fixed version number
|
|
1494
|
+
# literal :version, value: '1.0'
|
|
1495
|
+
def literal(
|
|
1496
|
+
name,
|
|
1497
|
+
value:,
|
|
1498
|
+
as: nil,
|
|
1499
|
+
default: nil,
|
|
1500
|
+
deprecated: false,
|
|
1501
|
+
description: nil,
|
|
1502
|
+
optional: false
|
|
1503
|
+
)
|
|
1504
|
+
param(
|
|
1505
|
+
name,
|
|
1506
|
+
as:,
|
|
1507
|
+
default:,
|
|
1508
|
+
deprecated:,
|
|
1509
|
+
description:,
|
|
1510
|
+
optional:,
|
|
1511
|
+
value:,
|
|
1512
|
+
type: :literal,
|
|
1513
|
+
)
|
|
1514
|
+
end
|
|
1515
|
+
|
|
1516
|
+
# @api public
|
|
1517
|
+
# Defines a reference to a named type.
|
|
1518
|
+
#
|
|
1519
|
+
# @param name [Symbol]
|
|
1520
|
+
# The name.
|
|
1521
|
+
# @param to [Symbol, nil] (nil)
|
|
1522
|
+
# The target type name. Defaults to name.
|
|
1523
|
+
# @param as [Symbol, nil] (nil)
|
|
1524
|
+
# The target attribute name.
|
|
1525
|
+
# @param default [Object, nil] (nil)
|
|
1526
|
+
# The default value.
|
|
1527
|
+
# @param deprecated [Boolean] (false)
|
|
1528
|
+
# Whether deprecated. Metadata included in exports.
|
|
1529
|
+
# @param description [String, nil] (nil)
|
|
1530
|
+
# The description. Metadata included in exports.
|
|
1531
|
+
# @param nullable [Boolean] (false)
|
|
1532
|
+
# Whether the value can be `null`.
|
|
1533
|
+
# @param optional [Boolean] (false)
|
|
1534
|
+
# Whether the param is optional.
|
|
1535
|
+
# @param required [Boolean] (false)
|
|
1536
|
+
# Whether the param is required.
|
|
1537
|
+
# @return [void]
|
|
1538
|
+
#
|
|
1539
|
+
# @example Reference to customer type
|
|
1540
|
+
# reference :customer
|
|
1541
|
+
#
|
|
1542
|
+
# @example Reference with different param name
|
|
1543
|
+
# reference :billing_address, to: :address
|
|
1544
|
+
def reference(
|
|
1545
|
+
name,
|
|
1546
|
+
to: nil,
|
|
1547
|
+
as: nil,
|
|
1548
|
+
default: nil,
|
|
1549
|
+
deprecated: false,
|
|
1550
|
+
description: nil,
|
|
1551
|
+
nullable: false,
|
|
1552
|
+
optional: false,
|
|
1553
|
+
required: false
|
|
1554
|
+
)
|
|
1555
|
+
param(
|
|
1556
|
+
name,
|
|
1557
|
+
as:,
|
|
1558
|
+
default:,
|
|
1559
|
+
deprecated:,
|
|
1560
|
+
description:,
|
|
1561
|
+
nullable:,
|
|
1562
|
+
optional:,
|
|
1563
|
+
required:,
|
|
1564
|
+
type: to || name,
|
|
1565
|
+
)
|
|
1566
|
+
end
|
|
1567
|
+
|
|
1568
|
+
# @api public
|
|
1569
|
+
# Defines an optional reference to a named type.
|
|
1570
|
+
#
|
|
1571
|
+
# @param name [Symbol]
|
|
1572
|
+
# The name.
|
|
1573
|
+
# @param to [Symbol, nil] (nil)
|
|
1574
|
+
# The target type name. Defaults to name.
|
|
1575
|
+
# @param as [Symbol, nil] (nil)
|
|
1576
|
+
# The target attribute name.
|
|
1577
|
+
# @param default [Object, nil] (nil)
|
|
1578
|
+
# The default value.
|
|
1579
|
+
# @param deprecated [Boolean] (false)
|
|
1580
|
+
# Whether deprecated. Metadata included in exports.
|
|
1581
|
+
# @param description [String, nil] (nil)
|
|
1582
|
+
# The description. Metadata included in exports.
|
|
1583
|
+
# @param nullable [Boolean] (false)
|
|
1584
|
+
# Whether the value can be `null`.
|
|
1585
|
+
# @param required [Boolean] (false)
|
|
1586
|
+
# Whether the param is required.
|
|
1587
|
+
# @return [void]
|
|
1588
|
+
#
|
|
1589
|
+
# @example Optional shipping address
|
|
1590
|
+
# reference? :shipping_address, to: :address
|
|
1591
|
+
def reference?(
|
|
1592
|
+
name,
|
|
1593
|
+
to: nil,
|
|
1594
|
+
as: nil,
|
|
1595
|
+
default: nil,
|
|
1596
|
+
deprecated: false,
|
|
1597
|
+
description: nil,
|
|
1598
|
+
nullable: false,
|
|
1599
|
+
required: false
|
|
1600
|
+
)
|
|
1601
|
+
param(
|
|
1602
|
+
name,
|
|
1603
|
+
as:,
|
|
1604
|
+
default:,
|
|
1605
|
+
deprecated:,
|
|
1606
|
+
description:,
|
|
1607
|
+
nullable:,
|
|
1608
|
+
required:,
|
|
1609
|
+
optional: true,
|
|
1610
|
+
type: to || name,
|
|
1611
|
+
)
|
|
1612
|
+
end
|
|
1613
|
+
|
|
1614
|
+
def param(name, type: nil, **options, &block)
|
|
1615
|
+
raise NotImplementedError, "#{self.class} must implement #param"
|
|
1616
|
+
end
|
|
1617
|
+
end
|
|
1618
|
+
end
|