dotCMS / dotCMS/core

fix: Container REST API — hostId ignored, containerStructures broken, and missing @Schema annotations

Open
#34,914 1 comment 0 reactions 1 assignee View on GitHub

@fmontes is already working on this.

Since Mar 9, 2026.

Team : Falcon Type : Task
Dominant language
Java
Stars
970
Forks
486
Avg merge
3d 33m
Merged PRs (30d)
170

Description

The Container REST API (/api/v1/containers) has three bugs discovered during AI agent integration testing via the OpenAPI spec:

Bug 1: hostId field is accepted but silently ignored

  • ContainerForm accepts hostId and the OpenAPI spec advertises it
  • But ContainerResource.saveNew() (line 779) and update() (line 874) never read containerForm.getHostId()
  • Both endpoints get the host from WebAPILocator.getHostWebAPI().getCurrentHostNoThrow(request) instead
  • The _copy endpoint has the same issue (line 1424)
  • Result: site assignment cannot be controlled via the API — containers always land on the current request's site

Bug 2: containerStructures causes Hibernate session error on POST and PUT

  • Sending containerStructures array in the request body causes HTTP 400 with a Hibernate error
  • Root cause: The Hibernate mapping (DotCMSId.hbm.xml:457) uses unsaved-value="" on the id field — if the client sends an id value, Hibernate tries an UPDATE on a non-existent row instead of INSERT
  • The saveContainerStructures() method (ContainerAPIImpl.java:551) calls HibernateUtil.save() with these detached/misidentified objects
  • Workaround: use top-level structureInode + code fields instead

Bug 3: ContainerForm has no @Schema annotations

  • None of the fields on ContainerForm or its Builder have @Schema annotations
  • The OpenAPI spec auto-generates with no descriptions, making it unclear that friendlyName is the "description" field
  • Fields like hostId and containerStructures appear usable in the spec but are broken/ignored

Affected files

  • dotCMS/src/main/java/com/dotcms/rest/api/v1/container/ContainerResource.java
  • dotCMS/src/main/java/com/dotcms/rest/api/v1/container/ContainerForm.java
  • dotCMS/src/main/java/com/dotmarketing/portlets/containers/business/ContainerAPIImpl.java
  • dotCMS/src/main/java/com/dotmarketing/beans/ContainerStructure.java
  • dotCMS/src/main/resources/com/dotmarketing/beans/DotCMSId.hbm.xml
  • dotCMS/src/main/webapp/WEB-INF/openapi/openapi.yaml

Acceptance Criteria

  • POST/PUT /api/v1/containers uses hostId from the request body (when provided) to determine the container's site, falling back to the current request site if not set
  • POST/PUT /api/v1/containers correctly saves containerStructures sent in the request body without Hibernate errors
  • ContainerForm fields have @Schema annotations with descriptions (especially friendlyName documented as "description", and hostId documented with its behavior)
  • The generated OpenAPI spec accurately reflects which fields are functional
  • Existing container creation/update flows (UI, integrations) continue to work

Root Cause Summary

# Issue Root Cause Location Category
1 hostId silently ignored ContainerResource.java:779,874,1424 — never reads containerForm.getHostId() Java bug (dead field)
2 containerStructures Hibernate error ContainerAPIImpl.java:551 + DotCMSId.hbm.xml:457unsaved-value="" treats JSON-supplied id as existing entity Java bug / Hibernate mapping
3 No @Schema on ContainerForm ContainerForm.java — field friendlyName serves as "description" but no annotations document this Missing documentation

Priority

Medium

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.