Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions lib/jsonapi/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ module JSONAPI
#
# @param [Hash] params
# @option [(#jsonapi_id, #jsonapi_type, #jsonapi_related, #as_jsonapi),
# Array<(#jsonapi_id, #jsonapi_type, #jsonapi_related, #as_jsonapi)>,
# Array<(#jsonapi_id, #jsonapi_type, #jsonapi_related,
# #as_jsonapi)>,
# nil] data Primary resource(s) to be rendered.
# @option [Array<#jsonapi_id>] errors Errors to be rendered.
# @option [String, Hash{Symbol => Hash}] include Relationships to be
# included.
# @option [Hash{Symbol, Array<Symbol>}] fields List of requested fields
# for some or all of the resource types.
# @option include Relationships to be included. See
# JSONAPI::IncludeDirective.
# @option [Hash{Symbol, Array<Symbol>}, Hash{String, Array<String>}] fields
# List of requested fields for some or all of the resource types.
# @option [Hash] meta Non-standard top-level meta information to be
# included.
# @option [Hash] links Top-level links to be included.
Expand Down
8 changes: 7 additions & 1 deletion lib/jsonapi/renderer/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(params = {})
@errors = params.fetch(:errors, [])
@meta = params.fetch(:meta, nil)
@links = params.fetch(:links, {})
@fields = params.fetch(:fields, {})
@fields = _symbolize_fields(params.fetch(:fields, {}))
@jsonapi = params.fetch(:jsonapi, nil)
@include = JSONAPI::IncludeDirective.new(params.fetch(:include, {}))
end
Expand Down Expand Up @@ -48,6 +48,12 @@ def errors_hash
hash[:errors] = @errors.map(&:as_jsonapi)
end
end

def _symbolize_fields(fields)
fields.each_with_object({}) do |(k, v), h|
h[k.to_sym] = v.map(&:to_sym)
end
end
end
end
end