Adding ability to use resource from other namespace#893
Adding ability to use resource from other namespace#893senid231 wants to merge 1 commit intoJSONAPI-Resources:masterfrom
Conversation
|
@lgebhardt, what do you think about it? |
e27e380 to
d50d35c
Compare
…e_path method that provides path to resource
d50d35c to
cc7da24
Compare
|
My primary concerns are around edge cases. One example, we make a GET to the get :index, params: {include: 'comments,comments.author'}Here are the resources from the tests: module ApiRest
class PersonResource < BaseResource
model_name 'Person'
attributes :name, :email
attribute :date_joined, format: :date_with_timezone
has_many :comments, class_name: '::Comment'
end
end
class CommentResource < JSONAPI::Resource
attributes :body
has_one :post
has_one :author, class_name: 'Person'
has_many :tags
filters :body
end
class PersonResource < BaseResource
model_name 'Person'
attributes :name, :email
attribute :date_joined, format: :date_with_timezone
has_many :comments
endSince comments are backed by the I think technically the first option is "correct", but it's a confusing response, at least in this case. Note: this was edited to add the ::PersonResource to help with the example below. |
|
@lgebhardt , can you please add more details why you think response is confusing in this case? |
|
@Fivell In the example I gave above the request would be Without the namespace differences between comments and authors the response would return the person, their comments sideloaded, and then the author of each comment, which you would expect to be the original person, so no side loaded person data, since it's returned in the primary data. The types specified for these resource will not be decorated with the namespace. The reason the author is not side loaded if it exists in the primary data is in the spec, which states: "A compound document MUST NOT include more than one resource object for each type and id pair." However because of the namespace on The JSON API spec does not address namespace issues. I think to make it work completely we'd need to promote the namespace up into the If that's clear as mud I'll see if I can write up some example responses, but I don't have the time at the moment. |
|
@lgebhardt, I understand your concerns, but for now i think that in for this example module Api
module System
class Employee < BaseResource
model_name 'Employee'
attributes :full_name, :email
has_one :country, class_name: 'Api::Country'
end
end
class Country < BaseResource
model_name 'Country'
attributes :iso, :name
end
class Client < BaseResource
model_name 'Client'
attributes :full_name, :email, :phone_number
has_one :country, class_name: 'Country'
has_one :support, class_name: 'Api::System::Employee'
end
endsuch requests should be valid get 'api/system/employees', params: {include: 'country'}
get 'api/clients', params: {include: 'country,support'}and country relation always has link to but if we add resource module Api
module System
class Country < BaseResource
model_name 'Country'
attributes :iso, :name
end
end
endthese requests should raise some internal exception. With old behavior we can have to many duplicated endpoint get 'api/system/country'
get 'api/country'and link in country relationship will be if we add another namespace with endpoint that relates to Maybe some recommendations should be added to what do you think about this? |
|
Please review #927. |
Routing:
resource for jsonapi_resource(s), jsonapi_related_resource(s), jsonapi_link(s), jsonapi_relationships will be founded through controller
Breaking changes - application will not start if route's controller is missing
Controller:
provides resource_klass to
RequestParser(previously it was provided only forresource_serializer,RequestParserdetectedresource_klassbyparams[:controller])usage example: