Uncovered in #3084914: Support non-entity bundle types. The commerce_payment_method entity crashes OpenAPI because it uses bundle plugins.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review
FileSize
5.54 KB

This adds support for all bundles defined for a content entity type.

larowlan’s picture

Issue tags: +Needs tests

Looks good to me, but should probably add to the existing tests to demonstrate why this is a bug

mglaman’s picture

Project: OpenAPI » OpenAPI for JSON:API
Version: 8.x-1.x-dev » 8.x-2.x-dev

This code was moved into a new project.

mglaman’s picture

Status: Needs review » Needs work

Needs a reroll. Here's what I added to my swapped class

  /**
   * {@inheritdoc}
   *
   * @todo remove after https://www.drupal.org/project/openapi_jsonapi/issues/3091299
   */
  public function getDefinitions() {
    static $definitions = [];
    if (!$definitions) {
      foreach ($this->entityTypeManager->getDefinitions() as $entity_type) {
        if (!$entity_type instanceof ContentEntityTypeInterface) {
          continue;
        }
        $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type->id());
        foreach ($bundles as $bundle_name => $bundle) {
          if ($this->includeEntityTypeBundle($entity_type->id(), $bundle_name)) {
            $definition_key = $this->getEntityDefinitionKey($entity_type->id(), $bundle_name);
            $json_schema = $this->getJsonSchema('api_json', $entity_type->id(), $bundle_name);
            $json_schema = $this->fixReferences($json_schema, '#/definitions/' . $definition_key);
            $definitions[$definition_key] = $json_schema;
          }
        }
      }
    }
    return $definitions;
  }
skyredwang’s picture

Status: Needs work » Needs review
FileSize
5.26 KB

damn, I didn't find this issue and @mglaman's fix until I wrote the patch. But, I am glad that the patch looks exactly like the one @mglaman has

e0ipso’s picture

Status: Needs review » Fixed

Thank you for the contributions. This looks good!

e0ipso’s picture

  • e0ipso committed 07ccdda on 3.x authored by skyredwang
    Issue #3091299 by mglaman, skyredwang, e0ipso, larowlan: Support...
  • e0ipso committed b1359b6 on 3.x authored by mglaman
    Issue #3091299 by mglaman, skyredwang, e0ipso, larowlan: Support...
e0ipso’s picture

I had to re-roll. I gave authorship credit to both patch authors.

Status: Fixed » Closed (fixed)

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