Thanks so much for this module.
I am working on the OpenAPI module. Currently it has some code I copied over from the previous version of this module but I would like to remove it and rely on this module.
#2870393: Remove openapi_json_schema submodule and add dependency on Schemata module
I can almost use this module expect that you can longer produce schema for just and entity type if the entity also supports bundles.

This is needed when creating the OpenAPI spec because the REST resources don't really point to specific bundle(unlike JSON API).

This patch will add a route for all entity types regardless of whether they also supports bundles.

I am attaching Open API JSON file produced with patch to this module.
If look at the definitions section of this json you will see a definition for node, node:article and node:page. This is possible with changes to this module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tedbow created an issue. See original summary.

tedbow’s picture

Status: Active » Needs review
Grayside’s picture

Status: Needs review » Needs work

I have reviewed the PR, and there were a couple minor bits that need work.

tedbow’s picture

Status: Needs work » Needs review

@Grayside thanks for looking at the PR. I update the PR and pushed new commits that address your concerns I think.

jludwig’s picture

There is discussion in the PR about whether to add a new route for each bundle or to change it to one or two routes with paths like this:

/schemata/{entity_type}/{bundle}

What is in the current PR works fine, and whether to change that or not requires a discussion because it may affect things like local tasks. This is important issue so my suggestion would be to get this PR in first and open another issue to discuss whether to use a dynamic path and less routes.

Grayside’s picture

Agreed, handling the routes more dynamically is a separate issue.

Grayside’s picture

Status: Needs review » Needs work
Grayside’s picture

FileSize
150.48 KB

Copied the patch version of the Github PR to see if I can get the tests to run.

Grayside’s picture

Grayside’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 9: 15.patch, failed testing.

Grayside’s picture

Grayside’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: 2870904.patch, failed testing.

tedbow’s picture

Status: Needs work » Needs review
FileSize
25.9 KB

Ok here is patch from that same PR.

tedbow’s picture

Namespace was wrong in RequestTest so test was not found.

Status: Needs review » Needs work

The last submitted patch, 16: 2870904-16.patch, failed testing.

tedbow’s picture

Status: Needs work » Needs review

Retesting against core 8.3.x.
8.4.x will not work until #2871167: Replace rest.link_manager with hal.link_manager and add a dependency on hal is fixed.

UPDATE: actually that change was in 8.3.x too so testing against 8.2.x

tedbow’s picture

Version: 8.x-1.0-alpha1 » 8.x-1.x-dev
FileSize
42.55 KB
88.52 KB

Ok not that #2871167: Replace rest.link_manager with hal.link_manager and add a dependency on hal is hopefully close to be done.

Here a patch that adds test changes from that issue and also adds the expectations for the new routes created by this issue.

Uploading 2 patches. 1 with both issues changes to get the tests to pass and 1 with just this issues changes.

dawehner’s picture

+++ b/src/Routing/Routes.php
@@ -71,29 +71,79 @@ class Routes implements ContainerInjectionInterface {
+      // If this entity type supports bundles then add a route for each bundle.
+      if ($entity_type->getBundleEntityType()) {

Well, technically every entity type supports bundles, just some of them don't have an entity type connected to it, see \Drupal\Core\Entity\EntityTypeBundleInfo::getAllBundleInfo. Is this restriction strictly needed?

tedbow’s picture

@dawehner thanks for the review

+++ b/src/Routing/Routes.php
@@ -71,29 +71,79 @@ class Routes implements ContainerInjectionInterface {
-      $has_bundle = (bool) $entity_type->getBundleEntityType();

The previous code was still using $entity_type->getBundleEntityType() to determine which entity types should get a route for every bundle so the this functionality remains the same.

I will update that comment though to be more accurate.

tedbow’s picture

tedbow’s picture

Created new pull request https://github.com/phase2/schemata/pull/22 , sorry for inconvience

e0ipso’s picture

Status: Needs review » Reviewed & tested by the community

I reviewed this in GitHub already, forgot to update here too.

Grayside’s picture

Status: Reviewed & tested by the community » Fixed

Awesome to see test coverage continue to expand on this.

  • I manually tested that the schemas generate with and without a bundle, and all looks green there as well as the automated tests here.
  • I merged the Github PR.

Per the comment near the bottom of the Github PR, there are a couple issues in the backlog for automated schema validation:

Grayside’s picture

Another potentially relevant follow-up is #2798019: Deduplicate property names and centralize entity properties, wherein we consider the value of modifying schema output for entities with bundles to leverage a separate schema for common elements.

Grayside’s picture

Another closely related issue, custom fields attached to user entity (a no-bundle situation) do not show up in the schema.

Status: Fixed » Closed (fixed)

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