Skip to content

JSON API adapter's "include" option not translating dasherized keys to underscored #1725

Open
@chrisdpeters

Description

@chrisdpeters

Expected behavior vs actual behavior

If I run a URL like this against my API with a dasherized key in the include param:

https://api.example.com/themes/1234?include=content-templates

I get no included section in the JSON API payload.

However, I do get the included section if I use the conventional Ruby underscored naming:

https://api.example.com/themes/1234?include=content_templates

The related code within the Rails controller is simple enough:

theme = current_site.themes.find(params[:id])
render json: theme, include: params[:include]

It seems to me like it should be translating the dasherized key to underscored under the hood.

Environment

ActiveModelSerializers Version (commit ref if not on tag):
0.10.0.rc5

Output of ruby -e "puts RUBY_DESCRIPTION":
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

OS Type & Version:
Dockerized Debian 8.4

Integrated application and version (e.g., Rails, Grape, etc):
Rails 4.2.6

Backtrace

(e.g., provide any applicable backtraces from your application)

Additonal helpful information

(e.g., Gemfile.lock, configurations, PR containing a failing test, git bisect results)

I started poking around with this commit but felt like I was a tad out of my element. I think what I did with line #21 was appropriate (but now realize I should have been using #tr instead of #gsub). But now I suspect that my change for line #52 may not even make sense if you're starting with a hash instead of a string.

If you can help me clear that up, I'm sure I could clean it up and submit a PR. Let me know.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions