---
meta:
 - name: keywords
   description: api typescript node.js documentation AjvService class
---
# AjvService - @tsed/ajv

## Usage

```typescript
import { AjvService } from "@tsed/ajv";
```

> See [/packages/specs/ajv/src/services/AjvService.ts](https://github.com/tsedio/tsed/blob/v8.27.0/packages/specs/ajv/src/services/AjvService.ts#L0-L0).

## 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;
}
```

<!-- Members -->

## 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 or `JsonSchema`.

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;
```
