Object
Block context for defining reusable object types.
Accessed via object :name do in API or contract definitions. Use type methods to define params: #string, #integer, #decimal, #boolean, #array, #object, #union, #reference.
Example: instance_eval style
object :item do
string :description
decimal :amount
endExample: yield style
object :item do |object|
object.string :description
object.decimal :amount
endInstance Methods
#array
#array(name, as: nil, default: nil, deprecated: false, description: nil, nullable: false, optional: false, required: false, &block)
Defines an array param with element type.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The param name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Yields API::Element
Example: instance_eval style
array :tags do
string
endExample: yield style
array :tags do |element|
element.string
end#array?
#array?(name, as: nil, default: nil, deprecated: false, description: nil, nullable: false, of: nil, required: false, &block)
Defines an optional array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
of | Symbol, Hash, nil | nil | The element type. Arrays only. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional array of labels
array? :labels do
string
end#binary
#binary(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, optional: false, required: false)
Defines a binary.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | String, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: File content
binary :content#binary?
#binary?(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, required: false)
Defines an optional binary.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | String, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional attachment
binary? :attachment#boolean
#boolean(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, optional: false, required: false)
Defines a boolean.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | Boolean, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Active flag
boolean :activeExample: With default
boolean :published, default: false#boolean?
#boolean?(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, required: false)
Defines an optional boolean.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | Boolean, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional notification flag
boolean? :notify, default: true#date
#date(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, optional: false, required: false)
Defines a date.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | String, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Birth date
date :birth_date#date?
#date?(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, required: false)
Defines an optional date.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | String, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional expiry date
date? :expires_on#datetime
#datetime(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, optional: false, required: false)
Defines a datetime.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | String, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Timestamp
datetime :created_at#datetime?
#datetime?(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, required: false)
Defines an optional datetime.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | String, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional deletion timestamp
datetime? :deleted_at#decimal
#decimal(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, max: nil, min: nil, nullable: false, optional: false, required: false)
Defines a decimal.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | Numeric, nil | nil | The example value. Metadata included in exports. |
max | Numeric, nil | nil | The maximum value. |
min | Numeric, nil | nil | The minimum value. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Price with minimum
decimal :amount, min: 0Example: Percentage with range
decimal :discount, min: 0, max: 100#decimal?
#decimal?(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, max: nil, min: nil, nullable: false, required: false)
Defines an optional decimal.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | Numeric, nil | nil | The example value. Metadata included in exports. |
max | Numeric, nil | nil | The maximum value. |
min | Numeric, nil | nil | The minimum value. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional tax rate
decimal? :tax_rate, min: 0, max: 1#extends
#extends(type_name = nil)
Inherits all properties from another type. Can be called multiple times to inherit from multiple types.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
type_name | Symbol, nil | nil | The type to inherit from. |
Returns
Array<Symbol>
Example: Single inheritance
object :admin do
extends :user
boolean :superuser
endExample: Multiple inheritance
object :employee do
extends :person
extends :contactable
string :employee_id
end#integer
#integer(name, as: nil, default: nil, deprecated: false, description: nil, enum: nil, example: nil, max: nil, min: nil, nullable: false, optional: false, required: false)
Defines an integer.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
enum | Array, Symbol, nil | nil | The allowed values. |
example | Integer, nil | nil | The example value. Metadata included in exports. |
max | Integer, nil | nil | The maximum value. |
min | Integer, nil | nil | The minimum value. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Basic integer
integer :quantityExample: With range constraints
integer :age, min: 0, max: 150#integer?
#integer?(name, as: nil, default: nil, deprecated: false, description: nil, enum: nil, example: nil, max: nil, min: nil, nullable: false, required: false)
Defines an optional integer.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
enum | Array, Symbol, nil | nil | The allowed values. |
example | Integer, nil | nil | The example value. Metadata included in exports. |
max | Integer, nil | nil | The maximum value. |
min | Integer, nil | nil | The minimum value. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional page number
integer? :page, min: 1, default: 1#literal
#literal(name, value:, as: nil, default: nil, deprecated: false, description: nil, optional: false)
Defines a literal value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
value | Object | The exact value. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
optional | Boolean | false | Whether the param is optional. |
Returns
void
Example: Fixed version number
literal :version, value: '1.0'#merge
#merge(type_name = nil)
Includes all properties from another type. Can be called multiple times to merge from multiple types.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
type_name | Symbol, nil | nil | The type to merge from. |
Returns
Array<Symbol>
Example
object :admin do
merge :user
boolean :superuser
end#number
#number(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, max: nil, min: nil, nullable: false, optional: false, required: false)
Defines a number.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | Numeric, nil | nil | The example value. Metadata included in exports. |
max | Numeric, nil | nil | The maximum value. |
min | Numeric, nil | nil | The minimum value. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Coordinate value
number :latitude, min: -90, max: 90#number?
#number?(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, max: nil, min: nil, nullable: false, required: false)
Defines an optional number.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | Numeric, nil | nil | The example value. Metadata included in exports. |
max | Numeric, nil | nil | The maximum value. |
min | Numeric, nil | nil | The minimum value. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional score
number? :score, min: 0, max: 100#object
#object(name, as: nil, default: nil, deprecated: false, description: nil, nullable: false, optional: false, required: false, &block)
Defines an object.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Nested address object
object :address do
string :street
string :city
string :country
end#object?
#object?(name, as: nil, default: nil, deprecated: false, description: nil, nullable: false, required: false, &block)
Defines an optional object.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional metadata
object? :metadata do
string :key
string :value
end#param
#param(name, type: nil, as: nil, default: nil, deprecated: false, description: nil, discriminator: nil, enum: nil, example: nil, format: nil, max: nil, min: nil, nullable: false, of: nil, optional: false, required: false, shape: nil, value: nil, &block)
Defines a param with explicit type.
This is the verbose form. Prefer sugar methods (string, integer, etc.) for static definitions. Use param for dynamic param generation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The param name. | |
type | Symbol<:array, :binary, :boolean, :date, :datetime, :decimal, :integer, :literal, :number, :object, :string, :time, :union, :uuid>, nil | nil | The param type. |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
discriminator | Symbol, nil | nil | The discriminator field name. Unions only. |
enum | Array, nil | nil | The allowed values. |
example | Object, nil | nil | The example value. Metadata included in exports. |
format | Symbol<:date, :datetime, :double, :email, :float, :hostname, :int32, :int64, :ipv4, :ipv6, :password, :url, :uuid>, nil | nil | Format hint for exports. Does not change the type, but exports may add validation or documentation based on it. Valid formats by type: :decimal/:number (:double, :float), :integer (:int32, :int64), :string (:date, :datetime, :email, :hostname, :ipv4, :ipv6, :password, :url, :uuid). |
max | Integer, nil | nil | The maximum. For :array: size. For :decimal, :integer, :number: value. For :string: length. |
min | Integer, nil | nil | The minimum. For :array: size. For :decimal, :integer, :number: value. For :string: length. |
nullable | Boolean | false | Whether the value can be null. |
of | Symbol, Hash, nil | nil | The element type. Arrays only. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
shape | API::Object, API::Union, nil | nil | The pre-built shape. |
value | Object, nil | nil | The literal value. |
Returns
void
Yields API::Object, API::Union, API::Element
Example: Dynamic param generation
param_type = :string
param :title, type: param_typeExample: Object with block
param :metadata, type: :object do
string :key
string :value
end#reference
#reference(name, to: nil, as: nil, default: nil, deprecated: false, description: nil, nullable: false, optional: false, required: false)
Defines a reference to a named type.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
to | Symbol, nil | nil | The target type name. Defaults to name. |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Reference to customer type
reference :customerExample: Reference with different param name
reference :billing_address, to: :address#reference?
#reference?(name, to: nil, as: nil, default: nil, deprecated: false, description: nil, nullable: false, required: false)
Defines an optional reference to a named type.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
to | Symbol, nil | nil | The target type name. Defaults to name. |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional shipping address
reference? :shipping_address, to: :address#string
#string(name, as: nil, default: nil, deprecated: false, description: nil, enum: nil, example: nil, format: nil, max: nil, min: nil, nullable: false, optional: false, required: false)
Defines a string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
enum | Array, Symbol, nil | nil | The allowed values. |
example | String, nil | nil | The example value. Metadata included in exports. |
format | Symbol<:date, :datetime, :email, :hostname, :ipv4, :ipv6, :password, :url, :uuid>, nil | nil | Format hint for exports. Does not change the type, but exports may add validation or documentation based on it. Valid formats by type: :string. |
max | Integer, nil | nil | The maximum length. |
min | Integer, nil | nil | The minimum length. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Basic string
string :nameExample: With format validation
string :email, format: :emailExample: With length constraints
string :title, min: 1, max: 100#string?
#string?(name, as: nil, default: nil, deprecated: false, description: nil, enum: nil, example: nil, format: nil, max: nil, min: nil, nullable: false, required: false)
Defines an optional string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
enum | Array, Symbol, nil | nil | The allowed values. |
example | String, nil | nil | The example value. Metadata included in exports. |
format | Symbol<:date, :datetime, :email, :hostname, :ipv4, :ipv6, :password, :url, :uuid>, nil | nil | Format hint for exports. Does not change the type, but exports may add validation or documentation based on it. Valid formats by type: :string. |
max | Integer, nil | nil | The maximum length. |
min | Integer, nil | nil | The minimum length. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional string with default
string? :nickname, default: 'Anonymous'#time
#time(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, optional: false, required: false)
Defines a time.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | String, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Opening time
time :opens_at#time?
#time?(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, required: false)
Defines an optional time.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | String, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional closing time
time? :closes_at#union
#union(name, as: nil, default: nil, deprecated: false, description: nil, discriminator: nil, nullable: false, optional: false, required: false, &block)
Defines a union.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
discriminator | Symbol, nil | nil | The discriminator field name. Unions only. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Payment method union
union :payment_method, discriminator: :type do
variant tag: 'card' do
object do
string :last_four
end
end
variant tag: 'bank' do
object do
string :account_number
end
end
end#union?
#union?(name, as: nil, default: nil, deprecated: false, description: nil, discriminator: nil, nullable: false, required: false, &block)
Defines an optional union.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
discriminator | Symbol, nil | nil | The discriminator field name. Unions only. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional notification preference
union? :notification, discriminator: :type do
variant tag: 'email' do
object do
string :address
end
end
variant tag: 'sms' do
object do
string :phone
end
end
end#uuid
#uuid(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, optional: false, required: false)
Defines a UUID.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | String, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
optional | Boolean | false | Whether the param is optional. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Primary key
uuid :id#uuid?
#uuid?(name, as: nil, default: nil, deprecated: false, description: nil, example: nil, nullable: false, required: false)
Defines an optional UUID.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The name. | |
as | Symbol, nil | nil | The target attribute name. |
default | Object, nil | nil | The default value. |
deprecated | Boolean | false | Whether deprecated. Metadata included in exports. |
description | String, nil | nil | The description. Metadata included in exports. |
example | String, nil | nil | The example value. Metadata included in exports. |
nullable | Boolean | false | Whether the value can be null. |
required | Boolean | false | Whether the param is required. |
Returns
void
Example: Optional parent reference
uuid? :parent_id