Open API tries to upcast the resource_type parameter, which JSON:API Resource routes do not attach. This causes a crash in Open API. One thing we could do is take the first _jsonapi_resource_types value and set that as the default. It isn't perfect, and still causes issues for custom resource types. But it prevents Open API from crashing.

CommentFileSizeAuthor
#2 3109873-2.patch1.4 KBmglaman

Comments

mglaman created an issue. See original summary.

mglaman’s picture

StatusFileSize
new1.4 KB

I'm not sold on the idea. But here's a patch to at least make it work as a bandaid.

bradjones1’s picture

Title: Provide a `resource_type` route parameter for OpenAPI integration » Provide a `resource_type` route parameter (e.g. for openapi, jsonapi_schema)
Related issues: +#3179685: Resource type on route defaults is a string, may not be set at all

This also unlocks jsonapi_schema hypermedia links with jsonapi_hypermedia.

bradjones1’s picture

Status: Active » Needs work
dmitry.korhov’s picture

JSON:API by its specification allows to use polymorphic collections but how can we add it to a custom resource?
Right now only the first type from an array is used.
Can we add callback, somehow, instead of string with resource_type that will construct schema for us? Or multiple describedby strings are possible?

bradjones1’s picture

Status: Needs work » Postponed

OpenAPI for JSON:API is getting a complete rewrite so I think this may no longer be necessary.

ptmkenny’s picture

Something to consider: while debugging #3114758: Support JSON:API filters and trying to filter a resource, I was getting lots of errors until I realized that the first element of the array is used as the resource type, as noted in #5. Since _jsonapi_resource_types is an array, I had (wrongly) assumed that order didn't matter and put all the types in alphabetical order.

It would be great to find a way to make this more clear to devs.

andrewsizz’s picture

Any update here?

bradjones1’s picture

If there are updates they will be posted here.