Open mk6i opened 8 years ago
you are correct. Two identical names in get reference ids currently crashes api2go. I haven't looked further into this issue yet, but it is definitely an interesting point.
I have a fix, would you be interested in a pull request?
of course! That would be amazing. Preferably with a corresponding test :-)
Was this fixed? I came upon a similar problem, but with to-one heterogeneous relationships. For example, let us say the author has a mostPraisedWork
that can be either a book or a blog: this confuses api2go, which fails to call methods of the right structure. It may be a different instance of the same bug, so I am not sure whether I should open a new issue.
unfortunately it has not been fixed yet... probably it has the same cause
This problem is similar to the one described in issue #125. In this case, the program panics when a relationship is defined with multiple resource types. I've forked @tanmayambre's test repository and fixed it up to reproduce the issue. It's available at https://github.com/mkaminski1988/testapi2go.
Let's say I want to define an Author with a relationship named
works
that contains typesbooks
andblogs
. The JSON API output would resemble the following:Here's how I tried to set up the
GetReferences()
function for the author model type:The following error is produced:
It seems that this is caused by the fact that api2go generates all the relationship routes by looping over the references returned by
GetReferences()
, which may contain duplicateName
fields. The routine that generates routes should work off of a de-duped list of relationship names in order to avoid duplicate routes. I have not found a restriction in the JSON API spec that disallows multiple types in a relationship, so this functionality should be supported.