Upgrading
View SourceInstructions 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.exfiles with one of:@derive {JSONAPIPlug.Resource, ...options...}in the module defining your structs.require ProtocolandProtocol.derive(JSONAPIPlug.Resource, MyStruct, ...options...)if you prefer to keep it in the_json.exmodules.- 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
pathoption fromJSONAPIPlug.Resourceoptions toJSONAPIPlug.Plugoptions in your controllers. JSONAPIPlug.Resourceattribute optionsserializeanddeserializenow only support a boolean value. Remove all function references passed toserializeanddeserializeand provide an implementation of theJSONAPIPlug.Resource.Attributeprotocol for your resource to do custom serialization/deserialization.- If overridden, replace the
JSONAPIPlug.Resource.linkscallback with an implementation of theJSONAPIPlug.Resource.Linksprotocol for your resource to add per-resourceJSON:APIlinks. - If overridden, replace the
JSONAPIPlug.Resource.metacallback with an implementation of theJSONAPIPlug.Resource.Metaprotocol for your resource to add per-resourceJSON:APImeta. - If you use phonenix, either call
JSONAPIPlug.render/5in your controllers or adduse MyAppWeb, :json_apito your_json.exmodules and callrender/3. See the README for complete instructions. - If you are sending resource
idsinincludedfor resource create requests, this is now forbidden unless theclient_generated_idsoption is configured on yourJSONAPIPlug.API. You can however useJSON:API 1.1lidin relationships and included resources if you whish to create resources with included resources atomically. Please note that this works even though the reportedJSON:APIversion is still1.0, because the library still does not support the fullJSON:API 1.1specification yet, onlylidis supported for now.