Configure Operation-Level JSON Field Ordering
Set a JSON field ordering override for a specific API operation. This determines how fields are ordered in the response body for that operation.
Overview
The FieldOrderingApplyService provides a mechanism for API publishers to set a JSON field ordering override on a per-operation basis. This service allows fine-grained control over the serialization of response bodies, which can be necessary for consumers that depend on a stable field order.
This service modifies a single API operation's configuration. It is a "single writer" service, meaning it only persists the override value for a specific operation. The logic for resolving the final field order—which checks for an override at the operation level, then a system-wide default, and finally falls back to the order defined in the API schema—is handled by the API runtime, not this service.
An override can only be applied to an operation that belongs to a service version in a draft state. It is not possible to modify the field ordering for an active, published service version.
How it Works
The service applies an override by updating the field_ordering_override property for a specific operation mapping in the database. The process is executed within a single transaction.
flowchart TD
subgraph Field Ordering Apply Service
A[Input: operationId, override] --> B{Normalize Override String};
B -- valid --> C{Load Operation Metadata};
B -- invalid --> Throw[Throw S2R-VAL-0499];
C -- not found --> Throw404_1[Throw S2R-ADM-0404];
C -- found --> D{Validate Mutability};
D -- not mutable --> Throw410[Throw S2R-ADM-0410];
D -- mutable --> E[Update s2r_operation_mapping table];
E -- 0 rows updated --> Throw404_2[Throw S2R-ADM-0404];
E -- 1+ rows updated --> F[Return ApplyResult];
endThe sequence of operations is as follows:
-
Normalize Input: The
applymethod receives anoperationIdand anoperationOverridestring. The override string is normalized:nullor whitespace-only strings are treated asnull, which clears any existing override.- The string is checked against a list of canonical and valid modes.
- If the mode is invalid, the service throws an
ApplyValidationException(S2R-VAL-0499).
-
Load Metadata: The service queries the
s2r_operationands2r_service_versiontables to retrieve metadata for the givenoperationId, including its service version status. If the operation is not found, it throws anApplyValidationException(S2R-ADM-0404). -
Validate Mutability: The service checks if the operation's associated service version is mutable. An operation is considered immutable if its service version is active (
is_active = true) or its status is notdraft. If the version is immutable, the service throws anApplyValidationException(S2R-ADM-0410). -
Persist Override: If validation passes, the service executes a SQL
UPDATEstatement to set thefield_ordering_overridecolumn in thes2r_operation_mappingtable for the specifiedoperation_id. The update only targets active mappings (is_active = true) and is scoped to the current tenant. -
Verify Update: The service checks if any rows were updated. If no rows were affected, it means no active mapping was found for the operation, and the service throws an
ApplyValidationException(S2R-ADM-0404). -
Return Result: On successful update, the service returns an
ApplyResultobject containing theoperationId, the operation'soperationKey, and the normalizedoperationOverridevalue that was persisted.
IMPORTANT
The runtime resolves field ordering by checking for an override in the following sequence:
- Operation-level override (set by this service)
- System-level default
- Schema-defined order ('as-schema')
API Reference
The service exposes a single method, apply, for setting the override.
apply
ApplyResult apply(UUID operationId, String operationOverride)
Applies a field ordering override to a single operation.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
operationId | UUID | Yes | The unique identifier for the target API operation. |
operationOverride | String | No | The field ordering mode to apply. Passing null or an empty string will clear the override. The value must be one of the platform's valid modes. The source does not list the available modes. |
Return Value
On success, the method returns an ApplyResult object with the following fields:
| Field | Type | Description |
|---|---|---|
operationId | UUID | The ID of the operation that was updated. |
operationKey | String | A key or identifier for the operation. |
operationOverride | String | The normalized override value that was written to storage. |
Example
While the source does not provide a complete, runnable example, a successful invocation would return a payload similar to the following:
{
"operationId": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"operationKey": "getUserProfile",
"operationOverride": "alphabetical"
}
Troubleshooting
When a call to the apply method fails, it throws an ApplyValidationException containing a machine-readable error code.
| Error Code | Trigger | Meaning |
|---|---|---|
S2R-VAL-0499 | The operationOverride string is not a valid mode. | The provided ordering mode is not recognized. The value must be one of the supported modes (e.g., alphabetical) or null to clear the override. |
S2R-ADM-0404 | The operationId does not correspond to a known operation. | The specified operationId could not be found. Verify that the ID is correct. |
S2R-ADM-0404 | No active mapping (is_active = true) was found for the operationId. | The operation exists, but it has no active mapping record that can be updated. This may indicate an inconsistent data state for the operation. |
S2R-ADM-0410 | The operation's service version is active or not in draft status. | The operation cannot be modified because it is part of a service version that is not in a draft state. To make changes, create a new draft service version. |
