Type Annotation
Prerequisites
Including the Anchor::SchemaSerializable
concern adds an optional second argument to JSONAPI::Resource.attribute
and JSONAPI::Resource.relationship
to enable annotations.
The type signatures of .attribute
and .relationship
are unchanged otherwise, i.e.
- if the annotation is included, the options hash becomes the third argument
- if the annotation is not included, the signatures remain the same
Attributes
In cases where the type of an attribute is not inferable (or incorrectly inferred) you may need to annotate the type.
Example
name
is not inferable because a method was defined on the resource.
See Anchor::Types
for all type annotation options.
Exhaustive Example
Relationships
Relationships should generally be inferred correctly, but there still may be cases where you want to override the inferred type.
Example
A belongs_to
association is optional but functionally non-null via other methods in your application.
See Anchor::Types::Relationship
for all options.