Refactor field enhancer schema generation

Created on 31 July 2021, over 3 years ago
Updated 16 February 2023, almost 2 years ago

Problem/Motivation

ResourceFieldEnhancerInterface::getOutputJsonSchema() is called in field definition normalizers to decorate/change/enhance the json schema generated by schemata module (e.g., if you're using openapi_jsonapi)

Field enhancers for "attributes" (non-relationship fields) can generate a schema that is pretty well atomic/independent of the parent normalizer. For relationships, the definition is more complex (e.g., includes an enum for the referenced entity type name) and this data may vary based on, say, renamed json:api property names. See #3224754: Make schema normalizer overrides module-agnostic (support jsonapi_schema as well as Schemata/OpenAPI) β†’ for missing implementation of schema collection for relationship fields.

Steps to reproduce

Try to generate an appropriate JSON schema for a relationship field; it's very easy to clobber the parent normalizer's type definition, complete with enum array.

Proposed resolution

Refactor the json schema generation for field enhancers to merge the returned array into the parent's. Or, at least, pass the parent definition to the field enhancer and let it decide which keys to adjust/preserve/reject.

Remaining tasks

User interface changes

API changes

This is likely a breaking change.

Data model changes

🌱 Plan
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • e0ipso Can Picafort

    I suppose we could somehow stick the un-enhanced schema into like, the context and somehow flow that through? Feels janky, however.

    I think this is a good match for the context object. There are many variables at play that may be needed by the enhancer, it is impossible to anticipate. The context object is a fancy $options array.

Production build 0.71.5 2024