I created a route which serializes an entity to a JSON:API argument. This worked great until I installed JSON:API Schema.

This is due to the route generation to try and create the describedby link

    else {
      $resource_type_name = explode('.', $this->currentRouteMatch->getRouteName())[1];
      $schema_route_name = "jsonapi_schema.{$resource_type_name}." . static::$schemaRouteType;
    }

In my case the route was called mymodule_jsonapi.json_view. This returned the rendered JSON in a modal.

The code in JSON:API Schema caused this route to fail as it tried to look up a route called jsonapi_schema.json_view.item, which is not a valid route. All JSON:API routes should have resource_type in their route per

    // Add the resource type as a parameter to every resource route.
    foreach ($routes as $route) {
      static::addRouteParameter($route, static::RESOURCE_TYPE_KEY, ['type' => ResourceTypeConverter::PARAM_TYPE_ID]);
      $route->addDefaults([static::RESOURCE_TYPE_KEY => $resource_type->getTypeName()]);
    }

So maybe we could fetch that from the route if it exists versus magically grabbing it from the route name.

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review
StatusFileSize
new1.84 KB
new339.23 KB

Here is a patch which supports normalization off of the main route, but the resulting JSON still has the describedby links

mglaman’s picture

Issue tags: +API-First Initiative

This is a blocker for Commerce API and prevents the module from installing.

gabesullice’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Thanks for the detailed issue description and patch, that made this easy to review! The problem makes sense, the fix makes sense. LGTM.

  • gabesullice committed ed3e018 on 8.x-1.x authored by mglaman
    Issue #3093033 by mglaman: TopLevelSchemaLinkProviderBase::getLink...
gabesullice’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.