Skip to content

Início / Optitravel / Helpers / ScimHelper

validateSchemas(array $data)

This method validates the schemas property of a SCIM request. It ensures that the schemas field exists, is an array, is not empty, and that each entry is a valid URN string.

If any of the validations fail, it immediately returns a standardized error response using ApiHelper::error().

Parameters

  • $data – (array) Required. The request data containing the schemas key, typically from a SCIM-compliant API payload.

Behavior

The method performs the following validations on the schemas key:

  • Presence & Type Check: Ensures schemas is present and is an array.

  • Empty Array Check: Verifies that the schemas array is not empty.

  • Value Format Checks (looped):

  • Each entry must be a string.

  • Each entry must match the URN format pattern: urn:namespace:resource[:optional].

If any check fails, a 400 Bad Request response is returned with a detailed error description.

Example

use \App\Utils\ScimHelper;

$data = [
  'schemas' => [
    'urn:ietf:params:scim:schemas:core:2.0:User'
  ]
];

ScimHelper::validateSchemas($data);

If the input is valid, nothing happens (validation passes silently). If invalid, the execution halts and a JSON error response is sent.

Example of an Invalid Input:

$data = [
  'schemas' => ['invalid-schema-format']
];

ScimHelper::validateSchemas($data);

Output:

{
    "schemas": [
        "urn:ietf:params:scim:api:messages:2.0:Error"
    ],
    "scimType": "invalidValue",
    "detail": "Formato de schema inválido",
    "status": "400"
}

(Última atualização: 14/05/2025)