# data-annotations-schema-validator

> A set of helpers that load and validate data models against an DataAnnotation-generated schema from .NET.

Latest version **0.1.1** (published 2015-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install data-annotations-schema-validator
pnpm add data-annotations-schema-validator
yarn add data-annotations-schema-validator
bun add data-annotations-schema-validator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2015-04-01 |
| First published | 2015-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | André Carvalho |
| Maintainers | redroserade |
| Keywords | validation, schema, model validation, .net |

## Links

- npm: https://www.npmjs.com/package/data-annotations-schema-validator
- Repository: https://github.com/RedRoserade/asp-mvc-react
- Issues: https://github.com/RedRoserade/asp-mvc-react/issues
- npm.io page: https://npm.io/package/data-annotations-schema-validator

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2015-04-01
- 0.1.0 — 2015-04-01

## README

# DataAnnotation validator

This package contains a set of helper functions that validate a data model against a schema generated using .NET's `System.ComponentModel.DataAnnotations`.

## Usage

### Installing:

`npm install --save data-annotations-schema-validator`

### Use it:

```javascript
var schemaValidator = require('data-annotations-schema-validator');
```

## Functions

### `validate(model: object, schema: object) => object`

Validates `model` against `schema`, and returns the result as an object.

The generated object contains, for each property, the type errors `typeErrors` (for example, when a field has a string and should have a number) and the content errors `contentErrors` (value range, required, etc).

The returned object also contains a field, `valid`, which tells the validity of the tested `model`.

If the property is an object, a `propertyErrors` object is added, which follows the same structure. For arrays, an `itemErrors` array is added. For each item in the `model`'s array, an item in the resulting array is added, which follows the structure above.

Example output:
```
{
    valid: boolean,
    modelState: {
        <property>: {
            typeErrors: array,
            contentErrors: array,
            valid: boolean
        },
        (...)
    }
}
```

### `validateAsync(model: object, schemaName: string, cb: function (err, result)) => void`

Asynchronous version of `validate`. This version asynchronously loads the schema from the server and then validates `model`.

### `loadSchema(schemaName: string, cb: function (err, schema)) => void`

Asynchonously loads the schema with the specified name from the server, parses it to find more schemas (which are then loaded into cache), and then returns the schema in the callback, `cb`.

---
_Source: https://npm.io/package/data-annotations-schema-validator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
