I'm using JSONAPI::Serializable::Resource::KeyFormat for camel-cased keys. However this breaks inclusion of relationships when the relationship's name is subject to key transformation:
# app/resources/contact_resource.rb
class ContactResource < JSONAPI::Serializable::Resource
extend JSONAPI::Serializable::Resource::KeyFormat
type 'contacts'
key_format ->(key) { key.to_s.camelize(:lower) }
has_many :contact_groups
attributes :name, :email # ...
end
# app/controllers/contacts_controller.rb
class ContactsController < ApplicationController
def index
render jsonapi: Contact.all, include: [:contact_groups]
end
end
I'm using
JSONAPI::Serializable::Resource::KeyFormat
for camel-cased keys. However this breaks inclusion of relationships when the relationship's name is subject to key transformation:Results in
Without using the
key_format
it works as expected: