|
2 | 2 |
|
3 | 3 | # Configuration Options
|
4 | 4 |
|
5 |
| -The following configuration options can be set on `ActiveModelSerializers.config`, |
6 |
| -preferably inside an initializer. |
| 5 | +The following configuration options can be set on |
| 6 | +`ActiveModelSerializers.config`, preferably inside an initializer. |
7 | 7 |
|
8 | 8 | ## General
|
9 | 9 |
|
10 |
| -- `adapter`: The [adapter](adapters.md) to use. Possible values: `:attributes, :json, :json_api`. Default: `:attributes`. |
11 |
| -- `serializer_lookup_enabled`: When `false`, serializers must be explicitly specified. Default: `true` |
| 10 | +##### adapter |
| 11 | + |
| 12 | +The [adapter](adapters.md) to use. |
| 13 | + |
| 14 | +Possible values: |
| 15 | + |
| 16 | +- `:attributes` (default) |
| 17 | +- `:json` |
| 18 | +- `:json_api` |
| 19 | + |
| 20 | +##### serializer_lookup_enabled |
| 21 | + |
| 22 | +Enable automatic serializer lookup. |
| 23 | + |
| 24 | +Possible values: |
| 25 | + |
| 26 | +- `true` (default) |
| 27 | +- `false` |
| 28 | + |
| 29 | +When `false`, serializers must be explicitly specified. |
| 30 | + |
| 31 | +##### key_transform |
| 32 | + |
| 33 | +The [key transform](key_transform.md) to use. |
| 34 | + |
| 35 | +Possible values: |
| 36 | + |
| 37 | +- `:camel` - ExampleKey |
| 38 | +- `:camel_lower` - exampleKey |
| 39 | +- `:dashed` - example-key |
| 40 | +- `:unaltered` - the original, unaltered key |
| 41 | +- `nil` - use the adapter default |
| 42 | + |
| 43 | +Each adapter has a default key transform configured: |
| 44 | + |
| 45 | +- `Json` - `:unaltered` |
| 46 | +- `JsonApi` - `:dashed` |
| 47 | + |
| 48 | +`config.key_transform` is a global override of the adapter default. Adapters |
| 49 | +still prefer the render option `:key_transform` over this setting. |
| 50 | + |
12 | 51 |
|
13 | 52 | ## JSON API
|
14 | 53 |
|
15 |
| -- `jsonapi_resource_type`: Whether the `type` attributes of resources should be singular or plural. Possible values: `:singular, :plural`. Default: `:plural`. |
16 |
| -- `jsonapi_include_toplevel_object`: Whether to include a [top level JSON API member](http://jsonapi.org/format/#document-jsonapi-object) |
17 |
| - in the response document. |
18 |
| - Default: `false`. |
19 |
| -- Used when `jsonapi_include_toplevel_object` is `true`: |
20 |
| - - `jsonapi_version`: The latest version of the spec the API conforms to. |
21 |
| - Default: `'1.0'`. |
22 |
| - - `jsonapi_toplevel_meta`: Optional metadata. Not included if empty. |
23 |
| - Default: `{}`. |
| 54 | + |
| 55 | +##### jsonapi_resource_type |
| 56 | + |
| 57 | +Set the `type` attributes of resources to singular or plural. |
| 58 | + |
| 59 | +Possible values: |
| 60 | + |
| 61 | +- `:singular` |
| 62 | +- `:plural` (default) |
| 63 | + |
| 64 | +##### jsonapi_include_toplevel_object |
| 65 | + |
| 66 | +Include a [top level jsonapi member](http://jsonapi.org/format/#document-jsonapi-object) |
| 67 | +in the response document. |
| 68 | + |
| 69 | +Possible values: |
| 70 | + |
| 71 | +- `true` |
| 72 | +- `false` (default) |
| 73 | + |
| 74 | +##### jsonapi_version |
| 75 | + |
| 76 | +The latest version of the spec to which the API conforms. |
| 77 | + |
| 78 | +Default: `'1.0'`. |
| 79 | + |
| 80 | +*Used when `jsonapi_include_toplevel_object` is `true`* |
| 81 | + |
| 82 | +##### jsonapi_toplevel_meta |
| 83 | + |
| 84 | +Optional top-level metadata. Not included if empty. |
| 85 | + |
| 86 | +Default: `{}`. |
| 87 | + |
| 88 | +*Used when `jsonapi_include_toplevel_object` is `true`* |
| 89 | + |
24 | 90 |
|
25 | 91 | ## Hooks
|
26 | 92 |
|
27 |
| -To run a hook when ActiveModelSerializers is loaded, use `ActiveSupport.on_load(:action_controller) do end` |
| 93 | +To run a hook when ActiveModelSerializers is loaded, use |
| 94 | +`ActiveSupport.on_load(:action_controller) do end` |
0 commit comments