Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/jsonapi/request_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,21 +381,20 @@ def verify_type(type)

def parse_to_one_links_object(raw)
if raw.nil?
return {
type: nil,
id: nil
}
return link_object_hash(nil, nil)
end

if !(raw.is_a?(Hash) || raw.is_a?(ActionController::Parameters)) ||
raw.keys.length != 2 || !(raw.key?('type') && raw.key?('id'))
if !(raw.is_a?(Hash) || raw.is_a?(ActionController::Parameters)) || (raw.length != 2 && !raw.key?('meta')) || !(raw.key?('type') && raw.key?('id'))
fail JSONAPI::Exceptions::InvalidLinksObject.new
end

{
type: unformat_key(raw['type']).to_s,
id: raw['id']
}
link_object_hash(unformat_key(raw['type']).to_s, raw['id'], raw['meta'])
end

def link_object_hash(type, id, meta=nil)
link_object = {type: type, id: id}
link_object[:meta] = meta unless meta.nil?
link_object
end

def parse_to_many_links_object(raw)
Expand Down