Problem/Motivation

Disabled resources are showing up in the Open API UIs. One can disable JSON API resource types in different ways, the most common being JSON API Extras. Once a resource is disabled it should not be present in the Open API definitions.

Proposed resolution

Detect the disabled resources and exclude them using the existing tools in the generator.

Remaining tasks

Void.

User interface changes

Nil.

API changes

JsonApiGeneratorson now also gets the ResourceTypeRepository service injected in its constructor.

Data model changes

Nada.

Comments

e0ipso created an issue. See original summary.

e0ipso’s picture

This can potentially fail tests. We'll see…

e0ipso’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 3000458--exclude-disabled-resource-types--2.patch, failed testing. View results

e0ipso’s picture

FYI I'm not actively working on the tests.

jaapjan’s picture

Confirming the patch works with 2.x branch of jsonapi and openapi_ui_redoc:8.x-1.0-rc2. Since jsonapi_extras doesn't work yet with jsonapi 2.x we've implemented some custom code to only allow some entities for now.

<?php
/**
 * Implements hook_entity_type_alter().
 */
function my_module_entity_type_alter(array &$entity_types) {
  $allow = [
    'comment',
    'file',
    'node',
    'user',
  ];

  /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
  foreach ($entity_types as $entity_name => $entity_type) {
    /** @var $entity_type \Drupal\Core\Entity\EntityTypeInterface */
    if (in_array($entity_name, $allow, TRUE) !== TRUE) {
      $entity_type->set('internal', TRUE);
    }
  }
}
arlina’s picture

Patch in #2 works against openapi 8.x-1.0-beta2, using jsonapi 8.x-2.4 and jsonapi_extras 8.x-3.5. It no longer shows the disabled resources.

e0ipso’s picture

I'm hoping that Rich can review this. It would be great to get this committed.

richgerdes’s picture

I was working on a related patch for excluding disabled fields in schemata (#2882269: Support for JSON API's ResourceType::getPublicName() and ResourceType::isFieldEnabled()). I think that it would be best to implement this there, since schemata is used in jsonapi (contrib) to test validity of schema, and it makes sense to pull in schema without alterations in order to provide a consistent export of schema.

I was working on the related schemata patch last week during sprints at DrupalCon Seattle. I will finish up the updated patch and work this functionality into it, since its most relevant there.

I think this may be a duplicate of #2882269: Support for JSON API's ResourceType::getPublicName() and ResourceType::isFieldEnabled(), but leaving it open for now since this one has a patch.

e0ipso’s picture

Status: Needs work » Needs review

This issue is about disabled resources, the ones linked seem to be about disabled fields.

  • richgerdes committed 22cae25 on 8.x-1.x authored by e0ipso
    Issue #3000458 by e0ipso: Exclude disabled JSON API resources
    
richgerdes’s picture

Status: Needs review » Fixed

Patch passed tests and looks good. It's been committed and pushed.

Status: Fixed » Closed (fixed)

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