AjvService
@tsed/ajv
Usage
typescript
import { AjvService } from "@tsed/ajv";Overview
ts
class AjvService {
readonly name = "ajv";
protected errorFormatter: ErrorFormatter;
protected returnsCoercedValues: boolean | undefined;
protected ajv: Ajv;
validate<TReturn = never, TValue = unknown>(value: TValue, options: AjvValidateOptions | JsonSchema): Promise<[TReturn] extends [never] ? TValue : TReturn>;
protected mapOptions(options: AjvValidateOptions | JsonSchema): AjvValidateOptions;
protected mapErrors(errors: ErrorObject[], options: any): AjvValidationError;
protected mapClassError(error: AjvErrorObject, targetType: Type<any>): string | undefined;
}readonly name
ts
readonly name = "ajv";protected errorFormatter
ts
protected errorFormatter: ErrorFormatter;protected returnsCoercedValues
ts
protected returnsCoercedValues: boolean | undefined;protected ajv
ts
protected ajv: Ajv;validate
ts
validate<TReturn = never, TValue = unknown>(value: TValue, options: AjvValidateOptions | JsonSchema): Promise<[TReturn] extends [never] ? TValue : TReturn>;value (
TValue): Value to validate.options (
AjvValidateOptions|JsonSchema): Validation options orJsonSchema.
Validate a value against a JSON schema, a model type, or explicit AJV options.
The return type is inferred from value by default and can be overridden with an explicit generic: ajvService.validate<MyType>(value, options).
If returnsCoercedValues is enabled globally or in options, coercions performed by AJV are returned.
protected mapOptions
ts
protected mapOptions(options: AjvValidateOptions | JsonSchema): AjvValidateOptions;protected mapErrors
ts
protected mapErrors(errors: ErrorObject[], options: any): AjvValidationError;protected mapClassError
ts
protected mapClassError(error: AjvErrorObject, targetType: Type<any>): string | undefined;