-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON API dasherize property names #173
Comments
Yes, here you go: http://trailblazer.to/gems/representable/3.0/api.html#defaults |
Thank you for pointing me to defaults. I had forgotten that I had tried it a week or two ago. It didn't seem be inherited in nested properties and has_one. Maybe it isn't supposed to. To give a complete example of what I have, without calling defaults: require 'roar/decorator'
require 'roar/json/json_api'
module PlaytimeTube
module Representers
class Playback < Roar::Decorator
include Roar::JSON::JSONAPI
type :playbacks
property :id
property :starts_at, as: 'starts-at', render_nil: true
property :duration_in_seconds, as: 'duration-in-seconds'
property :type
property :recording do
property :local_id, as: 'local-id'
# more properties
property :artist_name, as: 'artist-name'
end
has_one :playtime_report, as: 'playtime-report' do
type 'playtime-reports'
property :id
# more properties
property :archive_url, as: 'archive-url'
end
end
end
end If i provide I can call |
Defaults are not "inherited" into nested representers. I need to think about if that's a good idea or if we should introduce a Will let you know tomorrow! |
Oki, thank you. I solved it for now by doing: DASHERIZE_NAME = -> (name, options) { {as: dasherize-the-string(name) } }
defaults &DASHERIZE_NAME And reuse that block of code in the nested representers. |
This issue was moved to trailblazer/roar-jsonapi#13 |
Hi,
I wasn't able to figure this one out myself. Given the following:
Is there a way to make the serialised version of a user to have property named
full-name
?I can solve it by using
#property
'sas
-option, but I'd like to dasherize all property names automatically.The text was updated successfully, but these errors were encountered: