Problem/Motivation

In #2821554: [FEATURE] Deprecate jsonapi_docson in favor of Schemata. we lost the schemas for our resources. We should go back and have that information added back with the new schemas generated via the Schemata module.

Proposed resolution

Have a contrib module that has support for the JSON API specification using the Schemata module (or a similar technique). The use the reverse patch that removed the schema support in #2821554: [FEATURE] Deprecate jsonapi_docson in favor of Schemata. to add the information back to the resource info.

Additionally we should add a link to the schema in the output as a sibiling of self.

Comments

e0ipso created an issue. See original summary.

Wim Leers’s picture

Isn't this a duplicate of #2917260: Validate against specific JSON Schemas if Schemata is present?

Assigning to @e0ipso to find out.

gabesullice’s picture

Assigned: e0ipso » Unassigned

This is not a duplicate. This is about exposing schemas via the API itself. For example, we might have a link like /jsonapi/node/article/schema, which would return the schema for node articles.

This is important for generic JSON API clients to interact with our API without any foreknowledge of our specific implementation.

Wim Leers’s picture

Issue tags: +API-First Initiative

Oh, interesting! That'd be powerful for https://www.drupal.org/project/openapi!

e0ipso’s picture

This should be "simple" since we're already generating the schemas when validating against them if schemata is present.

For clarity, there is already a way to download / access the schema via a URL using the Schemata module. We could issue a 3xx or respond directly.

Wim Leers’s picture

This would only work when the Schemata module is installed, right?

e0ipso’s picture

This would only work when the Schemata module is installed, right?

Yes.

Wim Leers’s picture

Then perhaps 3xx redirects with URLs generated using internal: rather than using Schemata's routes would work. That way, we don't depend on Schemata at all, and the 3xx response will point to a 404 response, but upon installing the Schemata module, those 404s would become 200s.

e0ipso’s picture

Yeah, that would further simplify the implentation.

+1

Wim Leers’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Wim Leers’s picture

FYI: this is being discussed in the JSON API spec project: https://github.com/json-api/json-api/issues/1281

e0ipso’s picture

That's really interesting @Wim Leers, thanks for linking that issue. Schema autodiscovery & integration would be a killer feature indeed.

Wim Leers’s picture

No problem, I should've linked it a month ago or so, when I first saw it! Sorry for not doing it sooner.

Wim Leers’s picture

Title: [FEATURE] Add information about the schema in the resource » [PP-1] Add information about the schema in the resource
Status: Active » Postponed
bradjones1’s picture

Title: [PP-1] Add information about the schema in the resource » [PP-1] Add information about the schema in the json:api resource
Project: JSON:API » Drupal core
Version: 8.x-2.x-dev » 9.4.x-dev
Component: Code » jsonapi.module

Moving to core.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.