View Source Upgrading
Instructions to upgrade between major versions of JSONAPIPlug
.
Upgrading from 1.x to 2.0
To upgrade your application to 2.0:
- Replace all
use JSONAPIPlug.Resource, ...options...
in your_json.ex
files with one of:@derive {JSONAPIPlug.Resource, ...options...}
in the module defining your structs.require Protocol
andProtocol.derive(JSONAPIPlug.Resource, MyStruct, ...options...)
if you prefer to keep it in the_json.ex
modules.- Provide a manual implementation of
JSONAPIPlug.Resource
. This is discouraged because the derivation macro generates functions for recasing and options that are tedious to implement manually.
- Move the
path
option fromJSONAPIPlug.Resource
options toJSONAPIPlug.Plug
options in your controllers. JSONAPIPlug.Resource
attribute optionsserialize
anddeserialize
now only support a boolean value. Remove all function references passed toserialize
anddeserialize
and provide an implementation of theJSONAPIPlug.Resource.Attribute
protocol for your resource to do custom serialization/deserialization.- If overridden, replace the
JSONAPIPlug.Resource.links
callback with an implementation of theJSONAPIPlug.Resource.Links
protocol for your resource to add per-resourceJSON:API
links. - If overridden, replace the
JSONAPIPlug.Resource.meta
callback with an implementation of theJSONAPIPlug.Resource.Meta
protocol for your resource to add per-resourceJSON:API
meta. - If you use phonenix, either call
JSONAPIPlug.render/5
in your controllers or adduse MyAppWeb, :json_api
to your_json.ex
modules and callrender/3
. See the README for complete instructions. - If you are sending resource
ids
inincluded
for resource create requests, this is now forbidden unless theclient_generated_ids
option is configured on yourJSONAPIPlug.API
. You can however useJSON:API 1.1
lid
in relationships and included resources if you whish to create resources with included resources atomically. Please note that this works even though the reportedJSON:API
version is still1.0
, because the library still does not support the fullJSON:API 1.1
specification yet, onlylid
is supported for now.