Hi,

not sure if this problem with Cross Bundles itself, or OpenApi, but at least it's compability problem between the two. Reporting this at least in case someone comes up with ideas/reason why this happens, or if I or someone else can come up with solution on which side and now to fix this.

Background/reason:

As usual, people usually use many outside modules with JSON:API, like OpenAPI for generating schema, cross bundles to go around JSON:API's limitations for real world uses. So one very commonly used module is OpenAPI for generating API schema.

However, when enabling cross bundles, schema generation in OpenAPI dies with error

Error: Call to a member function getFieldStorageDefinition() on null in Drupal\openapi\Plugin\openapi\OpenApiGenerator\JsonApiGenerator->isToManyRelationship() (line 984 of modules/contrib/openapi/src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php).

Strong guess is, is that OpenAPI dies to endpoint created by Cross bundles.

Easy example here is media. Usually you want to create many media types with random fields, like Image, PDF, Video and whatever, which is extremely useful use case for Cross bundles to list all medias regardless of its type from /jsonapi/media

So to reproduce this, install OpenAPI module, create couple media types with fields, and check for generated schema in URL /openapi/jsonapi?_format=json - works beautifully. Enable cross-bundles, and it breaks.

I know neither project really has a "stable" release yet, but reporting this here as a starting point for looking for reason :)

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Anonymous’s picture

sundflux created an issue. See original summary.

avpaderno’s picture

Version: 8.x-1.0-alpha2 » 8.x-1.x-dev
Issue tags: -openapi
bradjones1’s picture

Title: Cross Bundles breaks OpenApi schema generation. » Support cross-bundle resource types: 'oneOf' response schemas
Project: JSON:API Cross Bundles » OpenAPI
Parent issue: » #2988277: [Meta] Implement OpenAPI 3.0 spec

Indeed, the problem here is that openapi_jsonapi's JsonApiGenerator calls the entity field manager to determine the schema for the response. It can (usually) depend on the resource type having bundles (or the bundle name is equal to the entity ID, for non-bundleable entity types) but not here. CrossBundlesResourceType::getBundle() explicitly returns NULL for the bundle, as you'd expect.

The correct answer here would be for this module to provide a response schema for all possible enabled bundles with oneOf (Link to Draft 04 spec, which OAPI 2.0 uses). Problem is, OpenAPI 2.0 doesn't support either of these constructs from JSON schema in its subset definition, however 3.0 does.

I think then, that this is a "won't fix" for 2.x and a relatively easy postponed feature to implement for OAPI 3.x support.

bradjones1’s picture

Project: OpenAPI » OpenAPI for JSON:API
Version: 8.x-1.x-dev » 3.0.1
bradjones1’s picture

Version: 3.0.1 » 3.x-dev

bradjones1’s picture

Leaving this as active, however this MR disables this incompatible functionality, for now.

bradjones1’s picture

Title: Support cross-bundle resource types: 'oneOf' response schemas » [PP-1] Support cross-bundle resource types: 'oneOf' response schemas
Status: Active » Postponed
bradjones1’s picture

Title: [PP-1] Support cross-bundle resource types: 'oneOf' response schemas » Support cross-bundle resource types: 'oneOf' response schemas
Version: 3.x-dev » 4.0.x-dev
Status: Postponed » Active

Marking this active as the newly-opened majors of openapi and this module will target OpenAPI 3.x.

No longer PP.