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
The JSON API media type should only work with a JSON API handler #23712
The JSON API media type should only work with a JSON API handler #23712
Conversation
r? @senny (@rails-bot has picked a reviewer for you, use r? to override) |
Thanks for this, @bf4. It's a step in the right direction.
I agree. To go further, I don't think the mime type should be registered at all without an appropriate corresponding renderer.
We are actually looking to switch to I've been talking with @lgebhardt about proposing a more pluggable rendering solution for mime types, that could cover the base mime types as well as custom registrations. We'll review with @bf4 and others here soon. |
If we're looking for pluggable renderers it might be best to remove the json-api mime type and DEFAULT_PARSERS entries. These could be registered as part of the specific library supporting json-api. |
Perhaps the pr should remove the jsonapi code and maybe update the guides with how to add to custom json media type B mobile phone
|
👍. Let's remove it and introduce back only when we have defined the proper API for the handlers. |
sounds good to me 👍 |
Since the media type 'application/vnd.api+json' is a spec, it is inappropriate to handle it with the JSON renderer. This PR removes support for a JSON API media type. I would recommend the media type be registered on its own as `jsonapi` when a jsonapi Renderer and deserializer (Http::Parameters::DEFAULT_PARSERS) are added. Is related to work in rails#21496
6f73b19
to
c4d90b7
Compare
assert_parses( | ||
{"person" => {"name" => "David"}}, | ||
{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept this test around both in case anyone is looking for json api support, and because I didn't see the behavior tested elsewhere.
However, I removed the test for rootless JSON as it duplicates what I left here and also isn't relevant to JSON API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Make sense 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha, that was quick! you merged it right before I revised the commit message from 'I' to 'we' and fixed a typo. :) Thanks!
…ot_render_spec The JSON API media type should only work wih a JSON API handler
@@ -37,9 +37,9 @@ def teardown | |||
) | |||
end | |||
|
|||
test "parses json params for application/vnd.api+json" do | |||
test "does not parses unregistered media types such as application/vnd.api+json" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelfranca typo does not parses
should be does not parse
. Just leave it for someone else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change it quickly, but if you want to make a PR go ahead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's cleaner if you just fix it, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
@bf4 Can we add some documentation about how to register the |
@ianks I spiked a first step in 6f73b19#diff-6a80fa5836403509e86a81c2117af391R12 or did you mean in the guides? |
Nevermind my comment :) |
I've been developing on a greenfield API project using edge, and have found that the commit in this PR has broken initializers: # active_model_initializer.rb
ActiveModelSerializers.config.adapter = :json_api
# wrap_parameters.rb
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json, :api_json]
end
I'm not sure (@bf4, @rafaelfranca), should this be broken right now?... is it pending some development, or should I submit an app or tests for reproduction for the failure to build a good parameters object? |
I went ahead and generated an app for demoing the problem: Repo is here /cc @bf4, @rafaelfranca |
Yes it is a "breaking change" by design. That feature was never released officially do we just removed it. If you need it in your application you can register the mime type. |
@rafaelfranca I attempted that last night to no avail. Confirmed in the demo app that it still does not work, even having registered the mime type: link to change |
As you can see in c4d90b7 the only thing made was to remove |
@rafaelfranca something must be awry... On rails master, the following does not work as expected:
Reverting c4d90b7 resolves the issue (assuming I also remove the above initializer). I appreciate your time, and I'll continue looking into this. Thanks again @rafaelfranca |
Could you open a new issue with a way to reproduce it? |
@rthbound would you mind opening an issue in ams, as well, so we can add a test there? Also to confirm docs are up to date. |
The tests introduced in https://github.com/rails/rails/pull/23816/files#diff-384a5a15d8d53de799fb6541688ea5f9R153 register the JSON API media type `application/vnd.api+json` with `Mime[:json]`. The JSON API media type should not be registered with `Mime[:json]`, as discussed in rails#23712. Moreover, since the actual mime type used in the test is incidental, I've changed this to a valid, but fictional `applcation/vnd.rails+json`. These tests were causing failures in rails#25050 (comment) where `Mime[:jsonapi]` is being added, so that JSON API request params are parsed with the JSONAPI gem.
Revises behavior introduced in #20329 #21251
Since the media type 'application/vnd.api+json' is a spec,
it is inappropriate to handle it with the JSON renderer.
Updated Description per discussion
This PR removes support for the JSON API media type.
We recommend the media type be registered on its own as
jsonapi
when a jsonapi Renderer and deserializer (Http::Parameters::DEFAULT_PARSERS) are added.Original Description
This PR adds support for a JSON API media type.
here.
retained the example for test continuity. I'd like to change that as
well.
I've chosen to register JSON API as
api_json
perJSONAPI-resources,
one of the more mature Rails+JSON API gems out there. An alternate name
could be
jsonapi
. In both cases, I would recommend the renderer benamed after the registered mime type.
Is related to work in #21496
cc @dgeb