I wasn't sure whether to file this as a bug report or a feature request. Also this may actually belong in the Schemata module issue queue instead.

We are using the Schemata module to generate JSON Schemas of our data models. This works well with JSON API module by default for generating Schemas that reflect those endpoints. However, once we turn on JSON API Extras module and begin making customizations, the schemas generated by Schemata do not reflect these customizations and are therefore no longer valid with our live endpoints.

This is likely also affecting the OpenAPI module, but I have not yet confirmed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrjmd created an issue. See original summary.

e0ipso’s picture

Version: » 8.x-1.x-dev
Status: Active » Needs work

The schemata module normalizes the entity types. That means that any changes on top of that need to be maintained manually.

That is why all the enhancers need a method to declare the new schema.

public function getJsonSchema() {

The remaining task is to merge the schema for that particular field with the new schema from the enhancer.

e0ipso’s picture

Priority: Normal » Major
Status: Needs work » Active

Bumping priority.

dpolant’s picture

Status: Active » Needs review
FileSize
4.97 KB

Attached is my first pass at this.

I've added overridden normalizers for Schemata's FieldDefinitionNormalizer (for adding enhancer special schemas) and SchemataSchemaNormalizer (for implementing top-level field name changes/removals).

e0ipso’s picture

This looks great. Only a minor change.

+++ b/src/Normalizer/FieldDefinitionNormalizer.php
@@ -0,0 +1,52 @@
+    // @TODO is getJsonSchema going to be required in the interface?

Yes. getJsonSchema will be required. Enhancers should be explicit about the output.

Also, we should merge the existing schema with the schema from the enhancer. Otherwise we will lose information about the field instance like the description, allowed values, …


I realize that schemata is not outputting the schema for type and ID, but that doesn't impact this ticket.

e0ipso’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
3.56 KB
5.54 KB

I think this is a great start. I'm going to merge this and we can iron out any other wrinkle that appears.

  • e0ipso committed 58f2e00 on 8.x-1.x authored by dpolant
    feat(Schema): Support schema generation with customizations (#2874642 by...
e0ipso’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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