marshmallow-jsonapi icon indicating copy to clipboard operation
marshmallow-jsonapi copied to clipboard

self_url_many should have a self_url_many_kwargs

Open fhriley opened this issue 4 years ago • 3 comments

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.

fhriley avatar Dec 05 '19 17:12 fhriley

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.

multimeric avatar Dec 06 '19 02:12 multimeric

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)?

pguyot avatar Dec 28 '20 21:12 pguyot

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 with self_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.

judgeaxl avatar Mar 21 '22 07:03 judgeaxl