Pip-Services-Commons-Dotnet
Public Member Functions | Protected Member Functions | Properties | List of all members
PipServices3.Commons.Validate.Schema Class Reference

Basic schema that validates values against a set of validation rules. More...

Inheritance diagram for PipServices3.Commons.Validate.Schema:
PipServices3.Commons.Validate.ArraySchema PipServices3.Commons.Validate.MapSchema PipServices3.Commons.Validate.ObjectSchema PipServices3.Commons.Validate.PropertySchema PipServices3.Commons.Validate.ProjectionParamsSchema PipServices3.Commons.Validate.SortParamsSchema PipServices3.Commons.Validate.FilterParamsSchema PipServices3.Commons.Validate.PagingParamsSchema PipServices3.Commons.Validate.SortFieldSchema

Public Member Functions

 Schema ()
 Creates a new instance of validation schema. More...
 
 Schema (bool required, List< IValidationRule > rules)
 Creates a new instance of validation schema and sets its values. More...
 
Schema MakeRequired ()
 Makes validated values always required (non-null). For null values the schema will raise errors. More...
 
Schema MakeOptional ()
 Makes validated values optional. Validation for null values will be skipped. More...
 
Schema WithRule (IValidationRule rule)
 Adds validation rule to this schema. This method returns reference to this exception to implement Builder pattern to chain additional calls. More...
 
List< ValidationResultValidate (object value)
 Validates the given value and results validation results. More...
 
void ValidateAndThrowException (string correlationId, object value, bool strict=false)
 Validates the given value and returns a ValidationException if errors were found. More...
 

Protected Member Functions

void PerformTypeValidation (string path, object type, object value, List< ValidationResult > results)
 Validates a given value to match specified type. The type can be defined as a Schema, type, a type name or TypeCode When type is a Schema, it executes validation recursively against that Schema. More...
 

Properties

bool IsRequired [get, set]
 
List< IValidationRuleRules [get, set]
 

Detailed Description

Basic schema that validates values against a set of validation rules.

This schema is used as a basis for specific schemas to validate objects, project properties, arrays and maps.

See ObjectSchema, PropertySchema, ArraySchema, MapSchema

Constructor & Destructor Documentation

◆ Schema() [1/2]

PipServices3.Commons.Validate.Schema.Schema ( )

Creates a new instance of validation schema.

◆ Schema() [2/2]

PipServices3.Commons.Validate.Schema.Schema ( bool  required,
List< IValidationRule rules 
)

Creates a new instance of validation schema and sets its values.

Parameters
required(optional) true to always require non-null values.
rules(optional) a list with validation rules.

Member Function Documentation

◆ MakeOptional()

Schema PipServices3.Commons.Validate.Schema.MakeOptional ( )

Makes validated values optional. Validation for null values will be skipped.

This method returns reference to this exception to implement Builder pattern to chain additional calls.

Returns
this validation schema

◆ MakeRequired()

Schema PipServices3.Commons.Validate.Schema.MakeRequired ( )

Makes validated values always required (non-null). For null values the schema will raise errors.

This method returns reference to this exception to implement Builder pattern to chain additional calls.

Returns
this validation schema

◆ PerformTypeValidation()

void PipServices3.Commons.Validate.Schema.PerformTypeValidation ( string  path,
object  type,
object  value,
List< ValidationResult results 
)
protected

Validates a given value to match specified type. The type can be defined as a Schema, type, a type name or TypeCode When type is a Schema, it executes validation recursively against that Schema.

Parameters
patha dot notation path to the value.
typea type to match the value type
valuea value to be validated.
resultsa list with validation results to add new results.

◆ Validate()

List<ValidationResult> PipServices3.Commons.Validate.Schema.Validate ( object  value)

Validates the given value and results validation results.

Parameters
valuea value to be validated.
Returns
a list with validation results.

◆ ValidateAndThrowException()

void PipServices3.Commons.Validate.Schema.ValidateAndThrowException ( string  correlationId,
object  value,
bool  strict = false 
)

Validates the given value and returns a ValidationException if errors were found.

Parameters
correlationId(optional) transaction id to trace execution through call chain.
valuea value to be validated.
stricttrue to treat warnings as errors.

◆ WithRule()

Schema PipServices3.Commons.Validate.Schema.WithRule ( IValidationRule  rule)

Adds validation rule to this schema. This method returns reference to this exception to implement Builder pattern to chain additional calls.

Parameters
rulea validation rule to be added.
Returns
this validation schema.

The documentation for this class was generated from the following file: