Configuration
Quick Reference
Name | Type | Default |
---|---|---|
field_case | :camel | :snake | :kebab | :camel_without_inflection | nil |
ar_column_to_type | Proc | nil |
use_active_record_comment | Boolean | nil |
use_active_record_validations | Boolean | true |
infer_nullable_relationships_as_optional | Boolean | nil |
empty_relationship_type | Proc | nil |
use_type_as_schema_name | Boolean | nil |
Example
Options
field_case
- Type:
:camel | :snake | :kebab | :camel_without_inflection
- Default:
nil
Determines the format for properties of attributes
and relationships
.
nil
- no changes to key name- camel, snake, and kebab format keys as their names suggest
- camel_without_inflection - camelize the key without using inflections defined in your Rails app
- e.g. given
inflect.acronym "LOL"
and key"lol_what"
- camel:
"lol_what".camellize
=>"LOLWhat"
- camel_without_inflection:
camel_without_inflection("lol_what")
=>"LolWhat"
- camel:
- e.g. given
ar_column_to_type
- Type:
Proc
- Default:
nil
Input: ActiveRecord::Base.columns_hash[attribute]
Output: member of Anchor::Types
Example
use_active_record_comment
- Type:
Boolean
- Default:
nil
Whether to use ActiveRecord comments as the default value of the description
option. In TypeScript, this would become a comment.
use_active_record_validations
- Type:
Boolean
- Default:
true
Use ActiveModel
validations on the ActiveRecord
model to determine whether an attribute is nullable.
For example, validates :role, presence: true
will infer role
as non-null irrespective of the presence of the database's non-null constraint on the role
column.
infer_nullable_relationships_as_optional
- Type:
Boolean
- Default:
nil
true
infers nullable relationships as optional.
For example, in TypeScript, true
infers { relation?: Relation }
over { relation: Maybe<Relation> }
.
empty_relationship_type
- Type:
Proc
- Default:
nil
By default, if there are no relationships for a resource then the relationships
property is not included in the TypeScript serializer.
If this config is defined, the relationships
property will be included with the returned Anchor
type as the type.
Example
use_type_as_schema_name
- Type:
Boolean
- Default:
nil
By default, the demodulized name of the class minus "Resource" is used as the schema name for the resource, e.g. SomeModule::UserResource => User
.
When true
, the String#classify
'd type
that JSONAPI::Resource
determines from the resource will be used.