src/Schema.php
protected function validateField($value, ValidationField $field) {
        $validated = false;
        $result = $value = $this->filterField($value, $field, $validated);

        if ($validated) {
            return $result;
        } elseif ($field->getField() instanceof Schema) {
            try {
                $result = $field->getField()->validate($value, $field->getOptions());
            } catch (ValidationException $ex) {
                // The validation failed, so merge the validations together.
                $field->getValidation()->merge($ex->getValidation(), $field->getName());
            }
        } elseif (($value === null || ($value === '' && !$field->hasType('string'))) && ($field->val('nullable') || $field->hasType('null'))) {
            $result = null;
        } else {
            // Look for a discriminator.
            if (!empty($field->val('discriminator'))) {
                $field = $this->resolveDiscriminator($value, $field);
            }

            if ($field !== null) {
                if($field->hasAllOf()) {
                    $result = $this->validateAllOf($value, $field);
                } else {
                    // Validate the field's type.
                    $type = $field->getType();
                    if (is_array($type)) {
                        $result = $this->validateMultipleTypes($value, $type, $field);
                    } else {
                        $result = $this->validateSingleType($value, $type, $field);
                    }

                    if (Invalid::isValid($result)) {
                        $result = $this->validateEnum($result, $field);
                    }
                }
            } else {
                $result = Invalid::value();
            }
        }

        // Validate a custom field validator.
        if (Invalid::isValid($result)) {
            $this->callValidators($result, $field);
        }

        return $result;
    }
protected function validateField($value, ValidationField $field) {
        $validated = false;
        $result = $value = $this->filterField($value, $field, $validated);

        if ($validated) {
            return $result;
        } elseif ($field->getField() instanceof Schema) {
            try {
                $result = $field->getField()->validate($value, $field->getOptions());
            } catch (ValidationException $ex) {
                // The validation failed, so merge the validations together.
                $field->getValidation()->merge($ex->getValidation(), $field->getName());
            }
        } elseif (($value === null || ($value === '' && !$field->hasType('string'))) && ($field->val('nullable') || $field->hasType('null'))) {
            $result = null;
        } else {
            // Look for a discriminator.
            if (!empty($field->val('discriminator'))) {
                $field = $this->resolveDiscriminator($value, $field);
            }

            if ($field !== null) {
                if($field->hasAllOf()) {
                    $result = $this->validateAllOf($value, $field);
                } else {
                    // Validate the field's type.
                    $type = $field->getType();
                    if (is_array($type)) {
                        $result = $this->validateMultipleTypes($value, $type, $field);
                    } else {
                        $result = $this->validateSingleType($value, $type, $field);
                    }

                    if (Invalid::isValid($result)) {
                        $result = $this->validateEnum($result, $field);
                    }
                }
            } else {
                $result = Invalid::value();
            }
        }

        // Validate a custom field validator.
        if (Invalid::isValid($result)) {
            $this->callValidators($result, $field);
        }

        return $result;
    }
protected function validateField ( $ value , ValidationField $ field ) { $ validated = false ; $ result = $ value = $ this -> filterField ( $ value , $ field , $ validated ) ; if ( $ validated ) { return $ result ; } elseif ( $ field -> getField ( ) instanceof Schema ) { try { $ result = $ field -> getField ( ) -> validate ( $ value , $ field -> getOptions ( ) ) ; } catch ( ValidationException $ ex ) { // The validation failed, so merge the validations together. $ field -> getValidation ( ) -> merge ( $ ex -> getValidation ( ) , $ field -> getName ( ) ) ; } } elseif ( ( $ value === null || ( $ value === '' && ! $ field -> hasType ( 'string' ) ) ) && ( $ field -> val ( 'nullable' ) || $ field -> hasType ( 'null' ) ) ) { $ result = null ; } else { // Look for a discriminator. if ( ! empty ( $ field -> val ( 'discriminator' ) ) ) { $ field = $ this -> resolveDiscriminator ( $ value , $ field ) ; } if ( $ field !== null ) { if ( $ field -> hasAllOf ( ) ) { $ result = $ this -> validateAllOf ( $ value , $ field ) ; } else { // Validate the field's type. $ type = $ field -> getType ( ) ; if ( is_array ( $ type ) ) { $ result = $ this -> validateMultipleTypes ( $ value , $ type , $ field ) ; } else { $ result = $ this -> validateSingleType ( $ value , $ type , $ field ) ; } if ( Invalid :: isValid ( $ result ) ) { $ result = $ this -> validateEnum ( $ result , $ field ) ; } } } else { $ result = Invalid :: value ( ) ; } } // Validate a custom field validator. if ( Invalid :: isValid ( $ result ) ) { $ this -> callValidators ( $ result , $ field ) ; } return $ result ; }
Validate a field.

@param mixed $value The value to validate.
@param ValidationField $field A validation object to add errors to.
@return mixed|Invalid Returns a clean version of the value with all extra fields stripped out or invalid if the value
is completely invalid.
@throws RefNotFoundException Throws an exception when a schema `$ref` is not found.
Validate a field .