If you have configured an endpoint for a content type and remove a field, it will still be on the form in JSONAPI config. I had to manually edit the config file to fully remove.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

    Comments

    mortona2k created an issue. See original summary.

    e0ipso’s picture

    Ugh! That's pretty annoying. Is there any chance you can provide a patch for this?

    Thanks for reporting.

    wim leers’s picture

    Status: Active » Needs work
    Issue tags: +API-First Initiative, +Configuration system, +config dependency
    StatusFileSize
    new595 bytes

    I also reported this problem a long time ago.

    The root cause: \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig::onDependencyRemoval() is missing. Here's a start.

    e0ipso’s picture

    This makes sense. Thanks @mortona2k and @Wim Leers. I won't have availability to work on this, but I'll leave this here to see if anyone else has the time to work on a patch for this.

    wim leers’s picture

    Title: JSONAPI field config sticks when field is removed » JSON:API Extras field config sticks when field is removed
    Issue tags: +Novice
    nginex’s picture

    Issue tags: +LutskGCW20

    Tagging for Drupal Global Contribution Weekend

    dsdeiz’s picture

    Would this happen to still be applicable? I've manually tested it by adding a field on "Article" content type, overwritten the resource type "node--article", and then removed the newly added field. I checked the form "node--article resource config" and the removed field is not listed anymore.

    dmitry.korhov’s picture

    StatusFileSize
    new1.75 KB
    new152.12 KB

    Found that adding fields as dependencies for JsonapiResourceConfig leads to placing configuration to "delete" block.
    Investigations for make it as "update" are required. Probably separation jsonapi_extras resource config to per field configs are required to make this config update work correctly.
    Let's continue with this patch.

    bbrala’s picture

    Any chance the work here can continue? Seems like a worthy issue.

    rohit.rawat619’s picture

    Assigned: Unassigned » rohit.rawat619
    Status: Needs work » Active
    rohit.rawat619’s picture

    Assigned: rohit.rawat619 » Unassigned
    Status: Active » Needs review
    StatusFileSize
    new7.77 KB
    bbrala’s picture

    bbrala’s picture

    Status: Needs review » Active
    jrockowitz’s picture

    I was experimenting with this patch and a bunch of update hooks failed with the below error

    LogicException: withRelatableResourceTypes() must be called before getting relatable resource types. in Drupal\jsonapi\ResourceType\ResourceTypeRelationship->getRelatableResourceTypes() (line 48 of /var/www/html/docroot/core/modules/jsonapi/src/ResourceType/ResourceTypeRelationship.php) #0 /var/www/html/docroot/core/modules/jsonapi/src/ResourceType/ResourceType.php(406): Drupal\jsonapi\ResourceType\ResourceTypeRelationship->getRelatableResourceTypes()

    Sorry, I can't provide more details.

    virag.jain’s picture

    Update on the issue:

    An initial attempt was made to fix this by implementing \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig::onDependencyRemoval(), as pointed out by @Wim Leers, with the goal of cleaning up deleted fields from the resourceFields array. However, it turned out that the method onDependencyRemoval() wasn’t being triggered at all when a field was removed.

    Upon further investigation, it appears the root cause is that \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig::calculateDependencies() only adds the only adds the bundle (e.g. node.type.*) as a dependency; it doesn’t include individual field configs like field.storage.node.field_foo. Without those dependencies, the entity system doesn’t invoke onDependencyRemoval() when fields are deleted.

    Proposed solution:

    The plan is to update calculateDependencies() to explicitly add each field listed in resourceFields as a dependency (e.g., field.storage.node.field_foo). With that in place, onDependencyRemoval() will be properly triggered when a field is deleted.

    Inside onDependencyRemoval(), any removed fields will be automatically cleaned out of the override config. This prevents stale field entries from lingering in the YAML and eliminates the need for manual cleanup.

    Just wanted to check in and see if this approach makes sense before finalising the patch. Let me know your thoughts!

    virag.jain’s picture

    Assigned: Unassigned » virag.jain
    virag.jain’s picture

    Assigned: virag.jain » Unassigned
    bbrala’s picture

    Status: Active » Closed (duplicate)

    Now that this issue is closed, review the contribution record.

    As a contributor, attribute any organization that helped you, or if you volunteered your own time.

    Maintainers, credit people who helped resolve this issue.