Skip to content

Attribute validation

Pascal Knüppel edited this page Jul 25, 2021 · 2 revisions

It is possible to set validation checks on the attributes within the resource schema declarations. You can use this feature to assure that clients will not set illegal values on your attributes.

lets consider the following schema

{
  "schemas": [
    "urn:ietf:params:scim:schemas:core:2.0:Schema"
  ],
  "id": "urn:gold:params:scim:schemas:custom:2.0:AllTypes",
  "name": "AllTypes",
  "description": "AllTypes",
  "attributes": [
    {
      "name": "string",
      "type": "string",
      "mutability": "readWrite",
      "returned": "default",
      "uniqueness": "none",
      "description": "test",
      "multiValued": false,
      "required": false,
      "caseExact": false,
      "minLength": 5,
      "maxLength": 10,
      "pattern": "[0-9]+"
    },
    {
      "name": "number",
      "type": "integer",
      "mutability": "readWrite",
      "returned": "default",
      "uniqueness": "none",
      "description": "test",
      "multiValued": false,
      "required": false,
      "caseExact": false,
      "minimum": 2,
      "maximum": 10,
      "multipleOf": 2
    },
    {
      "name": "decimal",
      "type": "decimal",
      "mutability": "readWrite",
      "returned": "default",
      "uniqueness": "none",
      "description": "test",
      "multiValued": false,
      "required": false,
      "caseExact": false,
      "minimum": 10.8,
      "maximum": 150.9,
      "multipleOf": 5.67
    },
    {
      "name": "bool",
      "type": "boolean",
      "mutability": "readWrite",
      "returned": "default",
      "uniqueness": "none",
      "description": "test",
      "multiValued": false,
      "required": false,
      "caseExact": false
    },
    {
      "name": "date",
      "type": "dateTime",
      "mutability": "readWrite",
      "returned": "default",
      "uniqueness": "none",
      "description": "test",
      "multiValued": false,
      "required": false,
      "caseExact": false,
      "notBefore": "2018-11-01T00:00:00Z",
      "notAfter": "2020-12-01T00:00:00Z"
    },
    {
      "name": "stringArray",
      "type": "string",
      "mutability": "readWrite",
      "returned": "default",
      "uniqueness": "none",
      "description": "test",
      "multiValued": true,
      "required": false,
      "caseExact": false,
      "minItems": 2,
      "maxItems": 5,
      "minLength": 5,
      "maxLength": 10,
      "pattern": "[0-9]+"
    },
    {
      "name": "numberArray",
      "type": "integer",
      "mutability": "readWrite",
      "returned": "default",
      "uniqueness": "none",
      "description": "test",
      "multiValued": true,
      "required": false,
      "caseExact": false,
      "minItems": 2,
      "maxItems": 5,
      "minimum": 2,
      "maximum": 10,
      "multipleOf": 2
    },
    {
      "name": "decimalArray",
      "type": "decimal",
      "mutability": "readWrite",
      "returned": "default",
      "uniqueness": "none",
      "description": "test",
      "multiValued": true,
      "required": false,
      "caseExact": false,
      "minItems": 3,
      "maxItems": 3,
      "minimum": 10.8,
      "maximum": 150.9,
      "multipleOf": 5.67
    },
    {
      "name": "boolArray",
      "type": "boolean",
      "mutability": "readWrite",
      "returned": "default",
      "uniqueness": "none",
      "description": "test",
      "multiValued": true,
      "required": false,
      "caseExact": false,
      "minItems": 1,
      "maxItems": 1
    },
    {
      "name": "dateArray",
      "type": "dateTime",
      "mutability": "readWrite",
      "returned": "default",
      "uniqueness": "none",
      "description": "test",
      "multiValued": true,
      "required": false,
      "caseExact": false,
      "minItems": 1,
      "maxItems": 1,
      "notBefore": "2018-11-01T00:00:00Z",
      "notAfter": "2020-12-01T00:00:00Z"
    },
    {
      "name": "multiComplex",
      "type": "complex",
      "mutability": "readWrite",
      "returned": "default",
      "uniqueness": "none",
      "description": "test",
      "multiValued": true,
      "required": false,
      "caseExact": false,
      "minItems": 2,
      "maxItems": 3,
      "subAttributes": [
        {
          "name": "string",
          "type": "string",
          "mutability": "readWrite",
          "returned": "default",
          "uniqueness": "none",
          "description": "test",
          "multiValued": false,
          "required": false,
          "caseExact": false,
          "minLength": 5,
          "maxLength": 10,
          "pattern": "[0-9]+"
        }
      ]
    }
  ]
}

this schema uses all possible validation attributes:

number type validations

  1. multipleOf: can be used for integer and decimal types
    • value must be a multiple of this value
  2. minimum: can be used for integer and decimal types
    • value must not be less than the minimum value
  3. maximum: can be used for integer and decimal types
    • value must not be greater than the maximum value

string type validations

  1. minLength: can be used for string and reference types
    • values length must not be less than the minLength
  2. maxLength: can be used for string and reference types
    • values length must not be greater than maxLength
  3. pattern: can be used for string and reference types
    • must be a valid java regular expression and the value that will be validated must match this expression

date type validations

  1. notBefore: can be used for dateTimetypes
    • must be a valid timestamp as defined in RFC7643 and the dateTime value must not be before this value
  2. notAfter: can be used for dateTimetypes
    • must be a valid timestamp as defined in RFC7643 and the dateTime value must not be after this value

array type validations

  1. minItems: can be used for all types with attribute multivalued set to true
    • array must not have less than "minItems" entries
  2. maxItems: can be used for all types with attribute multivalued set to true
    • array must not have more than "maxItems" entries