@@ -317,12 +317,12 @@ class Endpoint {
317317
318318 /**
319319 * @var string|null $sort_by
320- * Sets the default value for the `sort_by` field in the request data. This value is used to control the sorting of
320+ * Sets the default value(s) for the `sort_by` field in the request data. This value is used to control the sorting of
321321 * the Model objects returned by this Endpoint. This value can be overridden by the client in the request data. Use
322322 * caution when assigning this value as it may force objects to be sorted in this order when they are written to the
323323 * configuration file.
324324 */
325- public ? string $ sort_by = null ;
325+ public string | array | null $ sort_by = null ;
326326
327327 /**
328328 * @var string $sort_order
@@ -794,20 +794,28 @@ class Endpoint {
794794 {
795795 # Only validate this field if the client specifically requested it in the request data
796796 if (isset ($ this ->request_data ['sort_by ' ])) {
797- # Ensure value is a string
798- if (!is_string ($ this ->request_data ['sort_by ' ])) {
799- throw new ValidationError (
800- message: 'Field `sort_by` must be of type `string`. ' ,
801- response_id: 'ENDPOINT_SORT_BY_FIELD_INVALID_TYPE ' ,
802- );
803- }
797+ # Ensure value is an array
798+ $ this ->request_data ['sort_by ' ] = is_array ($ this ->request_data ['sort_by ' ])
799+ ? $ this ->request_data ['sort_by ' ]
800+ : [$ this ->request_data ['sort_by ' ]];
801+
802+ # Check each field in the array
803+ foreach ($ this ->request_data ['sort_by ' ] as $ sort_by ) {
804+ # Ensure value is a string
805+ if (!is_string ($ sort_by )) {
806+ throw new ValidationError (
807+ message: 'Field `sort_by` must be of type `string`. ' ,
808+ response_id: 'ENDPOINT_SORT_BY_FIELD_INVALID_TYPE ' ,
809+ );
810+ }
804811
805- # Ensure the field is a valid field in the Model
806- if (!in_array ($ this ->request_data ['sort_by ' ], $ this ->model ->get_fields ())) {
807- throw new ValidationError (
808- message: 'Field `sort_by` must be a valid field in the Model. ' ,
809- response_id: 'ENDPOINT_SORT_BY_FIELD_NON_EXISTENT_FIELD ' ,
810- );
812+ # Ensure the field is a valid field in the Model
813+ if (!in_array ($ sort_by , $ this ->model ->get_fields ())) {
814+ throw new ValidationError (
815+ message: 'Field `sort_by` must be a valid field in the Model. ' ,
816+ response_id: 'ENDPOINT_SORT_BY_FIELD_NON_EXISTENT_FIELD ' ,
817+ );
818+ }
811819 }
812820
813821 # Update the sort_by property to use the client's requested value and remove it from the request data
0 commit comments