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 :)
Issue fork openapi_jsonapi-3118198
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
Comment #1
Anonymous (not verified) commentedsundflux created an issue. See original summary.
Comment #2
avpadernoComment #3
bradjones1Indeed, the problem here is that
openapi_jsonapi'sJsonApiGeneratorcalls 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 returnsNULLfor 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.
Comment #4
bradjones1Comment #5
bradjones1Comment #7
bradjones1Leaving this as active, however this MR disables this incompatible functionality, for now.
Comment #8
bradjones1Comment #9
bradjones1Marking this active as the newly-opened majors of openapi and this module will target OpenAPI 3.x.
No longer PP.