Loading…
Loading…
Configure how single-element arrays are handled in SOAP responses for a specific API operation. Set an operation-level override and per-field overrides.
The ArrayCollapseApplyService provides a mechanism for API publishers to control how single-element arrays in backend SOAP responses are represented in the final transformed response. By default, the system follows a platform-wide behavior for array handling. This service allows for granular overrides at two levels for any given API operation:
soapXPath.This configuration is applied to an s2r_operation_mapping and is only possible for operations that are part of a service version in a draft, non-active state. The runtime resolution chain for array collapsing is per-field, then per-mapping (operation), then the system default. This service manages the first two levels of that chain.
The primary function of this service is the apply method, which takes an operation ID and a set of overrides, validates them, and persists them to the database.
The ArrayCollapseApplyService modifies an operation's array collapse settings within a database transaction. The process ensures that changes are atomic and are only applied if all conditions are met.
flowchart TD
subgraph "Array Collapse Configuration Flow"
A[API Publisher calls apply function] --> B{Validate operation-level override};
B -- Invalid --> F[Fail: Invalid override mode];
B -- Valid --> C[Load existing per-field overrides from DB];
C --> D[Merge new per-field overrides];
D --> E{Validate each per-field override};
E -- Invalid --> F;
E -- Valid --> G[Load operation metadata from DB];
G --> H{Is operation's service version editable?};
H -- No --> I[Fail: Service version is immutable];
H -- Yes --> J[Serialize final per-field overrides to JSON];
J --> K[Persist operation-level and per-field overrides to DB];
K --> L{Was mapping found and updated?};
L -- No --> M[Fail: Active mapping not found];
L -- Yes --> N[Return success with final configuration];
endThe apply method executes the following sequence:
operationOverride mode. The mode value is trimmed and converted to lowercase. It must be one of the system-defined valid modes.s2r_operation_mapping table to retrieve the current response_field_array_collapse JSONB content for the specified operationId.fieldOverrides list.
FieldEntry, if the mode is null or blank, the entry for that soapXPath is removed from the map, effectively clearing the override.mode is a non-blank string, it is validated. If valid, it is added to the map, creating or replacing the override for that soapXPath.mode or a missing soapXPath in a FieldEntry will halt the process and throw a validation exception.draft and is not active (is_active is false).UPDATE on the s2r_operation_mapping table to set the array_collapse_override and response_field_array_collapse columns for the given operationId. The update only targets active mappings (is_active = true) within the current tenant's scope.ApplyResult object containing the operation's ID and key, the applied operation-level override, and the complete map of final per-field overrides. If no active mapping is found to update, it throws an exception.IMPORTANT
Configuration changes can only be applied to operations belonging to a service version that is in a draft state and is not currently active. Attempts to modify an operation in an active or non-draft version will fail.
To configure array collapse overrides, you invoke the apply method with the target operation's ID and the desired overrides. The following conceptual example shows how to set an operation-level override and define two field-specific overrides.
This example sets a default behavior for the operation and then specifies a different behavior for one field (//ns1:item) while clearing any existing override for another field (//ns1:detail).
// This is a conceptual example. Actual invocation depends on the client implementation.
UUID targetOperationId = UUID.fromString("...");
String operationLevelOverride = "collapse"; // A valid mode string
List<FieldEntry> fieldLevelOverrides = List.of(
// Set a specific mode for the 'item' field
new FieldEntry("//ns1:item", "collapse"),
// Clear any existing override for the 'detail' field by passing null mode
new FieldEntry("//ns1:detail", null)
);
try {
ApplyResult result = arrayCollapseApplyService.apply(
targetOperationId,
operationLevelOverride,
fieldLevelOverrides
);
System.out.println("Successfully applied overrides for operation: " + result.operationKey());
System.out.println("Final field overrides: " + result.responseFieldOverrides());
} catch (ApplyValidationException e) {
System.err.println("Failed to apply overrides: " + e.code() + " - " + e.getMessage());
}
Expected Result
If successful, the apply method returns an ApplyResult object. The responseFieldOverrides map in the result will contain {"//ns1:item": "collapse"}. The entry for //ns1:detail will have been removed. The operation-level override will be set to collapse.
The service exposes a single method, apply, for managing overrides.
apply methodApplies operation-level and per-field array collapse overrides to an active operation mapping. The operation must belong to a mutable service version.
public ApplyResult apply(UUID operationId, String operationOverride, List<FieldEntry> fieldOverrides)
| Name | Type | Required | Description |
|---|---|---|---|
operationId | UUID | Yes | The unique identifier for the operation mapping to modify. |
operationOverride | String | No | The array collapse mode to apply to the entire operation. If null or an empty string, any existing operation-level override is cleared. Must be one of the valid modes. |
fieldOverrides | List<FieldEntry> | No | A list of field-specific overrides. If null, existing field overrides are preserved. An empty list will have no effect. |
FieldEntry RecordDefines a single per-field override.
| Field | Type | Required | Description |
|---|---|---|---|
soapXPath | String | Yes | The XPath expression that uniquely identifies the field in the original SOAP response. This field is required and cannot be blank. |
mode | String | No | The array collapse mode for this specific field. If null or blank, any existing override for this soapXPath will be removed. Otherwise, it must be one of the valid modes. |NOTE
The source does not specify the set of valid strings for the mode parameter. An invalid mode will result in an ApplyValidationException with the code S2R-VAL-0494. The error message will list the available modes.
On success, returns an ApplyResult object with the following fields:
| Field | Type | Description |
|---|---|---|
operationId | UUID | The ID of the operation that was modified. |
operationKey | String | The key of the operation that was modified. - |operationOverride | String | The normalized operation-level override mode that was applied. - |responseFieldOverrides | Map<String, String> | The complete, final map of per-field overrides (soapXPath to mode) for the operation after the merge. - |When a call to the apply method fails, it throws an ApplyValidationException containing a machine-readable code and a human-readable message.
| Error Code | Message Text | Cause |
|---|---|---|
S2R-VAL-0494 | invalid-array-collapse-mode: must be one of <modes> or null | The operationOverride or a FieldEntry.mode contained a string that is not a recognized array collapse mode. The error message lists the valid modes. |
S2R-VAL-0494 | invalid-array-collapse-field: soapXPath is required | A FieldEntry object was provided with a null or blank soapXPath. Each field override must target a specific field via its XPath. |
S2R-VAL-0494 | invalid-array-collapse-field-map: <message> | An internal error occurred while serializing the final map of field overrides to JSON before database persistence. The nested exception message provides more detail. |
S2R-ADM-0404 | operation-not-found: <operationId> | The provided operationId does not correspond to any operation in the system for the current tenant. |
S2R-ADM-0404 | no-active-operation-mapping: <operationId> | An operation was found, but it does not have an active mapping (is_active = true) to which the overrides can be applied. This can also occur if the database update affects zero rows for other reasons, such as a concurrency issue. |
S2R-ADM-0410 | mapping-immutable: the operation's service version is not editable | The operation belongs to a service version that is not in a draft state or is currently active. Configuration for such operations is immutable. - |