diff --git a/src/OpenApiGenerator/OpenApiGeneratorBase.php b/src/OpenApiGenerator/OpenApiGeneratorBase.php index 48beb32..176a27c 100644 --- a/src/OpenApiGenerator/OpenApiGeneratorBase.php +++ b/src/OpenApiGenerator/OpenApiGeneratorBase.php @@ -401,7 +401,7 @@ abstract class OpenApiGeneratorBase implements OpenApiGeneratorInterface { if (isset($options['entity_type_id']) && $options['entity_type_id'] !== $entity_type_id) { return FALSE; } - if (isset($options['bundle_name']) && $options['bundle_name'] !== $bundle_name) { + if (isset($bundle_name) && isset($options['bundle_name']) && $options['bundle_name'] !== $bundle_name) { return FALSE; } return TRUE; diff --git a/src/OpenApiGenerator/OpenApiRestGenerator.php b/src/OpenApiGenerator/OpenApiRestGenerator.php index fccd8d0..eb3ab50 100644 --- a/src/OpenApiGenerator/OpenApiRestGenerator.php +++ b/src/OpenApiGenerator/OpenApiRestGenerator.php @@ -161,15 +161,17 @@ class OpenApiRestGenerator extends OpenApiGeneratorBase { $entity_types = $this->getRestEnabledEntityTypes(); $tags = []; foreach ($entity_types as $entity_type) { - $tag = [ - 'name' => $entity_type->id(), - 'description' => $this->t("Entity type: @label", ['@label' => $entity_type->getLabel()]), - 'x-entity-type' => $entity_type->id(), - 'x-definition' => [ - '$ref' => '#/definitions/' . $this->getEntityDefinitionKey($entity_type->id()), - ], - ]; - $tags[] = $tag; + if ($this->includeEntityTypeBundle($options, $entity_type->id())) { + $tag = [ + 'name' => $entity_type->id(), + 'description' => $this->t("Entity type: @label", ['@label' => $entity_type->getLabel()]), + 'x-entity-type' => $entity_type->id(), + 'x-definition' => [ + '$ref' => '#/definitions/' . $this->getEntityDefinitionKey($entity_type->id()), + ], + ]; + $tags[] = $tag; + } } return $tags; } diff --git a/tests/src/Functional/RequestTest.php b/tests/src/Functional/RequestTest.php index db520d7..4ad199b 100644 --- a/tests/src/Functional/RequestTest.php +++ b/tests/src/Functional/RequestTest.php @@ -139,6 +139,8 @@ class RequestTest extends BrowserTestBase { */ public function testRequests($api_module, $options = []) { if ($api_module == 'rest') { + // Enable all the entity types each request to make sure $options is + // respected for all parts of the spec. $enable_entity_types = [ 'openapi_test_entity' => ['GET', 'POST', 'PATCH', 'DELETE'], 'openapi_test_entity_type' => ['GET'], @@ -146,10 +148,6 @@ class RequestTest extends BrowserTestBase { 'taxonomy_term' => ['GET', 'POST', 'PATCH', 'DELETE'], 'taxonomy_vocabulary' => ['GET'], ]; - // If an entity type is specified only enable that entity type. - if (isset($options['entity_type_id'])) { - $enable_entity_types = [$options['entity_type_id'] => $enable_entity_types[$options['entity_type_id']]]; - } foreach ($enable_entity_types as $entity_type_id => $methods) { foreach ($methods as $method) { $this->enableRestService("entity:$entity_type_id", $method); @@ -273,11 +271,13 @@ class RequestTest extends BrowserTestBase { // Test paths for valid tags, schema, security, and definitions. $paths = &$decoded_response['paths']; + $tag_names = array_column($tags, 'name'); + $all_method_tags = []; foreach ($paths as $path => &$methods) { foreach ($methods as $method => &$method_schema) { // Ensure all tags are defined. - $tag_names = array_column($tags, 'name'); $missing_tags = array_diff($method_schema['tags'], $tag_names); + $all_method_tags = array_merge($all_method_tags,$method_schema['tags']); $this->assertTrue(empty($missing_tags), 'Method ' . $method . ' for ' . $path . ' has invalid tag(s): ' . implode(', ', $missing_tags)); // The security and scheme indexes are not present for jsonapi. @@ -295,12 +295,17 @@ class RequestTest extends BrowserTestBase { }; } + // Remove all tested properties from method schema. unset($method_schema['tags']); unset($method_schema['schemes']); unset($method_schema['security']); } } + $all_method_tags = array_unique($all_method_tags); + asort($all_method_tags); + asort($tag_names); + $this->assertEquals(array_values($all_method_tags), array_values($tag_names), "Method tags equal tag names"); // Strip response down to only untested properties. $root_keys = ['definitions', 'paths'];