There was some discussion recently in Drupal Slack over the role/future of Schemata vs. other modules in the same ecosystem. Schemata integrates with various modules either as a dependency or peer: Docson, OpenAPI, OpenAPI JSON:API, etc...

Particularly as regards json:api, there is significant duplicated logic between schemata and jsonapi_schema. These two modules serve different purposes, e.g., you may wish to generate an OpenAPI spec (requires schemata) and also surface json-schema alongside json:api (jsonapi_schema). The latter was forked off with significant Schemata code in it, so bugs that affect one likely affect the other. This particularly pertains to normalizers.

Some key quotes from Slack:

@richgerdes: I wouldn't say that schemata was deprecated, but the jsonapi portion of openapi is definitely not being actively worked on. I also haven't had time to work on the schemata and openapi stuff in general, so its definitely a bit stale.
...
I personally don't think the jsonapi schema system fully replaces the need for openapi, since openapi makes the requests library agnostic, where the jsonapi schema system still requires the client to know that the platform is based on jsonapi and how the various endpoints work.

Rich was generous enough to add me as a maintainer to openapi/openapi_jsonapi and jsonapi_schema, and I've been moving the latter forward in particular.

There is, however, significant spillover from schemata into other modules, like jsonapi_extras. Extras has schemata integration, so customization (e.g., enhancers) made with extras will be reflected in openapi, but not jsonapi_schema, which doesn't depend on schemata.

@richgerdes: I think that the jsonapi_schema stuff should have been built on schemata in the first place, since the schema is all json schema. When Gabe first started on the implementation he didn't want to have extra unnecessary dependencies, and since schemata had support for both rest and jsonapi, it didn't make sense. Ideally, we should probably have created a "jsonschema" module, and made openapi and jsonapi depend on that, or at least moved the platform specific code to separate sub modules? Who knows? Hindsight is always clearer. I think its a little awkward to add the dependency now, but maybe the openapi side of the house could just work off of the jsonapi_schema system instead and schemata can be left for more general entity schema and rest? I don't want to duplicate efforts, but at the same time changing either system my complicate things

@e0ipso: Dropping Schemata was one of the main drivers behind splitting openapi in openapi_jsonapi and openapi_rest. If we restrict ourselves to openapi_jsonapi, I believe Schemata should not be used. Sadly, that is still not the case. But instead of adding more onto Schemata, I would invest that effort into moving away from it.

Honestly, I (@bradjones1) don't really know where this leave us as far as a plan. I wasn't originally involved with the API-first initiative and it seems to be pretty much sunset at this point, but these various parts of the ecosystem are rather intertwined and not actively coordinated. My preference would be to do something along the lines of an audit of the various "schema" modules, their role and responsibilities, and determine what can be agreed upon as common dependencies. For my part, I would prefer a module or library that centralizes the field definition normalization logic and could be shared in all cases where json:api schema is needed. I have #3224754: Make schema normalizer overrides module-agnostic (support jsonapi_schema as well as Schemata/OpenAPI) open against jsonapi_extras which helps to illustrate the problem by way of a concrete example.

Comments

bradjones1 created an issue. See original summary.

bradjones1’s picture

Linking two issues from the old json:api contrib queue, which I've moved to core. Basically the idea between them is to move schema information into the resource definitions/json:api core. I think that would get hashed out here, as it were, in contrib-land, much like json:api itself.

bradjones1’s picture

After hacking away at this on my project all night today, I think the near-term win on this front would be:

Have a single set of normalizers (probably pulled from jsonapi_schema, it's been slightly better maintained) - basically the set I'm moving into json_schema_api - in a single module so that it can be maintained independent of how the data is presented (e.g., jsonapi_schema's dedicated URLs, or in an openapi document.)

I _think_ the key to unlocking the composability here will be to borrow the $describedFormat idea from schemata; the core normalizers will do normalization for schema_json format, but a module that needs to add "more" to the mix can define a normalizer with preferential weight that can match on a more specific format key (what's now called the "described format," which I don't necessarily love but it works.)

bradjones1’s picture

A few related notes on difficulties encountered using json-schema from Drupal: https://tech.kinksters.dating/posts/2022-01-11-client-side-jsonapi-resou...

e0ipso’s picture

In all honesty, I think all efforts in this realm should go towards:

Which is plenty of work. The old API-First Initiative team devised a plan to have JSON:API produce schemas reliably and statically (no need to pass an instance of a $node to determine its schema, instead just pass EntityType and bundle).

We do not need to implement this plan in core directly, that is why JSON:API Schema, and JSON:API Hypermedia are separate contrib projects. We could start implementing those there. However, some key parts may be impossible to implement in contrib and will need to go to core instead.

REST is so far behind in this respect with regards to JSON:API (you can output anything in a REST-in-core resource). There is nothing solid to grab to generate the schemas (except maybe some of the entity resources if one could ensure no one overrides a single normalizer). That is why we are moving away from generic modules (like Schemata) that are set for failure on the REST part.

I would love to devote my time to this, but I have not found anyone willing to sponsor my work on this feature. Let me know if you know of anything :-P

See also #3056005: API-First Initiative: top priorities for Drupal 8.8.x for the last Top Priorities post. And #2575761: Discuss a better system for discovering and selecting normalizers may also be clarifiying.

e0ipso’s picture

I also spoke my mind about schemas a while ago, before any of these issues were ever written: https://www.lullabot.com/articles/decoupled-drupal-hard-problems-schemas (take it with a grain of salt, it might have aged).

bradjones1’s picture

Thank you... I think #3056005: API-First Initiative: top priorities for Drupal 8.8.x is a great summary of next steps in a variety of areas.

Absent an active API-first initiative, what's the best path forward for organizing efforts?

bradjones1’s picture

bradjones1’s picture