marshmallow-jsonapi
marshmallow-jsonapi copied to clipboard
self_url_many should have a self_url_many_kwargs
self_url_many
in a schema's Meta class should have a corresponding self_url_many_kwargs
. Consider the following scenario where bars
cannot exist on their own, only within foos
:
class Meta:
type_ = "bars"
self_url = "/foos/{foo_id}/bars/{bar_id}"
self_url_kwargs = {"foo_id": "<foo_id>, "bar_id": "<id>"}
self_url_many = "/foos/{foo_id}/bars"
This situation is currently impossible because there is no self_url_many_kwargs
.
Agreed. The spec says "self
: the link that generated the current response document.", so it strongly implies that any response, including a resource that has to be in a relationship, should be able to have the current URL as a self
link.
self_url_kwargs
substitutes url with values from self (item). Where would we get the values in the case of a list with self_url_many_kwargs
(foo_id
in your example), including when no data is returned (the list is empty)?
That is a good question. Additionally, even if the collection has data, which one would you pick the value from?
self_url_kwargs
substitutes url with values from self (item). Where would we get the values in the case of a list withself_url_many_kwargs
(foo_id
in your example), including when no data is returned (the list is empty)?
I've not used marshmallow enough to say if it makes sense to pass these args to dump()
or not, but as it stands the only option seem to be to dump and update, which doesn't work when dumping takes place in a wrapper, like in flask-smorest
.