Determines whether a field is required or not based on combination of Require, RequireAll,
and NotRequired annotations.
420444
private boolean isRequired(Field field) {
        return field.getAnnotation(Require.class) != null
                // Use the field's declaring class for RequireAll; may be a super class
                || (field.getDeclaringClass().getAnnotation(RequireAll.class) != null
                && field.getAnnotation(NotRequired.class) == null);
    }
1074061
private static function _isRequired($object, $fieldName)
    {
        $reflectionClass = new \ReflectionClass($object);
        if ($reflectionClass->hasMethod('requiredFields')) {
            return in_array($fieldName, $object->requiredFields());
        }

        return false;
    }
848757
def validate_fields(self, **kwargs):
        
        for field in self.fields:
            value = kwargs[field]
            required_type = self.fields[field]
            if type(value) != required_type:
                raise TypeError('{}.{} needs to be a {}, recieved: {}({})'.format(
                    self.name,
                    field,
                    required_type.__name__,
                    type(value).__name__,
                    value.__repr__()))
1131763
public void checkAllRequirementsSatisfied(final String currentPath) {
        StringBuilder errors = new StringBuilder();

        for (Field field: this.dependantsInJson) {
            final Collection<String> requirements = this.dependantToRequirementsMap.get(field);
            if (!requirements.isEmpty()) {
                errors.append("\n");
                String type = field.getType().getName();
                if (field.getType().isArray()) {
                    type = field.getType().getComponentType().getName() + "[]";
                }
                errors.append("\t* ").append(type).append(' ').append(field.getName()).append(" depends on ")
                        .append(requirements);
            }
        }
        Assert.equals(0, errors.length(),
                      "\nErrors were detected when analysing the @Requires dependencies of '" +
                              currentPath + "': " + errors);
    }
1170985
def required(field):
    

    def wrap(f):
        def wrappedf(*args):
            result = f(*args)
            if result is None or result == "":
                raise Exception(
                    "Config option '%s' is required." % field)
            else:
                return result
        return wrappedf
    return wrap
23553
def _validate_dependencies(self, dependencies, field, value):
        
        if isinstance(dependencies, _str_type) or not isinstance(
            dependencies, (Iterable, Mapping)
        ):
            dependencies = (dependencies,)

        if isinstance(dependencies, Sequence):
            self.__validate_dependencies_sequence(dependencies, field)
        elif isinstance(dependencies, Mapping):
            self.__validate_dependencies_mapping(dependencies, field)

        if (
            self.document_error_tree.fetch_node_from(
                self.schema_path + (field, 'dependencies')
            )
            is not None
        ):
            return True
154265
public function isRequired($field)
    {
        $parts = explode('.', $field);
        $entity = $this->entity($parts);

        $isNew = true;
        if ($entity instanceof EntityInterface) {
            $isNew = $entity->isNew();
        }

        $validator = $this->_getValidator($parts);
        $fieldName = array_pop($parts);
        if (!$validator->hasField($fieldName)) {
            return false;
        }
        if ($this->type($field) !== 'boolean') {
            return $validator->isEmptyAllowed($fieldName, $isNew) === false;
        }

        return false;
    }
117883
def requires(self, require=None):
		

		# If require is None, this is a getter
		if require is None:
			return self._requires

		# If it's not a valid dict
		if not isinstance(require, dict):
			raise ValueError('__require__')

		# Go through each key and make sure it goes with a field
		for k,v in iteritems(require):

			# If the field doesn't exist
			if k not in self._nodes:
				raise ValueError('__require__[%s]' % str(k))

			# If the value is a string
			if isinstance(v, basestring):
				v = [v]

			# Else if it's not a list type
			elif not isinstance(v, (tuple,list)):
				raise ValueError('__require__[%s]' % str(k))

			# Make sure each required field also exists
			for s in v:
				if s not in self._nodes:
					raise ValueError('__require__[%s]: %s' % (str(k), str(v)))

			# If it's all good
			self._requires[k] = v
883277
public void checkLonelyValidatorAnnotation(Field field, Map<String, Class<?>> genericMap) {
        doCheckLonelyValidatorAnnotation(field, deriveFieldType(field, genericMap));
    }
192093
public function isRequired()
    {
        $isRequired = false;

        // see if on the first level of fields we have a required=true in the definition
        foreach ($this->fields as $field) {
            if ($field instanceof JsonDefinitionField &&
                $field->getDef() instanceof Field &&
                $field->getDef()->getRequired() === true
            ) {
                $isRequired = true;
            }
        }

        return $isRequired;
    }
1321535
def check_field(field, value)
      ### get the field defs for this PeriphType, omitting the leading nil
      @field_defs ||= JSS::PeripheralType.fetch(:name => @type, api: @api).fields.compact

      ### we must have the right number of fields, and they must have the same names
      ### as the definition
      required_fields = @field_defs.map{|f| f[:name]}
      raise JSS::InvalidDataError, "Peripherals of type '#{@type}' doesn't have a field '#{field}', they only have: #{required_fields.join(', ')}" unless required_fields.include? field

      ### any menu fields can only have values as defined by the type.
      menu_flds = @field_defs.select{|f| f[:type] == "menu" }
      menu_flds.each do |mf|
        next unless mf[:name] == field
        raise JSS::InvalidDataError, "The value for field '#{field}' must be one of: #{mf[:choices].join(', ')}" unless mf[:choices].include? value
      end #if menu_flds.include? field

    end
1247969
final public static function validatePresence (array $requiredFields=[], string $option=NULL) : bool
	{
		$option 			= static::checkGlobal($option);
		$fieldsWithError 	= "";
		foreach ($requiredFields as $field):
			if (!isset($option[$field]) || !static::hasValue($option[$field])) 
				$fieldsWithError .= "'".fieldNameAsText($field)."', ";
		endforeach;
		static::setError($fieldsWithError);
		return static::checkError();
	}
378277
public function isRequired($field_key)
    {
        $field = (is_array($field_key)) ? $field_key : $this->getField($field_key);
        return (is_array($field) && array_key_exists('required', $field) && $field['required']);
    }
210670
def _validate_overriden_fields_are_not_defined_in_superclasses(class_to_field_type_overrides,
                                                               schema_graph):
    """"""
    for class_name, field_type_overrides in six.iteritems(class_to_field_type_overrides):
        for superclass_name in schema_graph.get_inheritance_set(class_name):
            if superclass_name != class_name:
                superclass = schema_graph.get_element_by_class_name(superclass_name)
                for field_name in field_type_overrides:
                    if field_name in superclass.properties:
                        raise AssertionError(
                            u'Attempting to override field "{}" from class "{}", but the field is '
                            u'defined in superclass "{}"'
                            .format(field_name, class_name, superclass_name))
578397
def _validate_annotation(self, annotation):
        ''''''
        required_keys = set(self._required_keys)
        keys = set(key for key, val in annotation.items() if val)
        missing_keys = required_keys.difference(keys)
        if missing_keys:
            error = 'Annotation missing required fields: {0}'.format(
                missing_keys)
            raise AnnotationError(error)
1281879
@Override
    public boolean validate(Field f) throws RuleValidationException
    {

        boolean checkvalidation = true;
        for (Annotation annotate : f.getDeclaredAnnotations())
        {
            RelationType eruleType = getRuleType(annotate.annotationType().getSimpleName());

            if (eruleType != null)
            {

                switch (eruleType)
                {
                case MANY_TO_MANY:
                    checkvalidation = validateManyToMany(f, annotate);
                    break;
                case MANY_TO_ONE:
                    checkvalidation = validateManyToOne(f, annotate);
                    break;
                case ONE_TO_MANY:
                    checkvalidation = validateOneToMany(f, annotate);
                    break;
                case ONE_TO_ONE:
                    checkvalidation = validateOneToOne(f, annotate);
                    break;

                }

            }
        }

        return checkvalidation;
    }
976531
private function isRequired($field, $value) {
		
		if(true === isset($this -> required[$field])) {
			
			$empty = true;

			if(true === is_array($value)) {

				foreach($value as $val) {

					if(strlen(trim($val)) > 0) {
						$empty = false;
					}
				}
			}

			if(true === is_string($value) && strlen(trim($value)) > 0) {
				$empty = false;
			}

			if(false === $this -> required[$field] && $empty) {
			    return true;
			}
		}

		return false;
	}