@travetto/schema
Advanced tools
Comparing version 0.4.9 to 0.4.10
@@ -7,8 +7,8 @@ { | ||
"dependencies": { | ||
"@travetto/config": "^0.4.5", | ||
"@travetto/registry": "^0.4.3" | ||
"@travetto/config": "^0.4.6", | ||
"@travetto/registry": "^0.4.4" | ||
}, | ||
"description": "Data type registry for runtime validation, reflection and binding. ", | ||
"devDependencies": { | ||
"@travetto/test": "^0.4.5" | ||
"@travetto/test": "^0.4.6" | ||
}, | ||
@@ -36,4 +36,4 @@ "optionalExtensionDependencies": { | ||
}, | ||
"version": "0.4.9", | ||
"gitHead": "c723494714573aef32891181519ccceb988b3f41" | ||
"version": "0.4.10", | ||
"gitHead": "cd17462f7331b7a5a74181cfa9a1573b7cd26f9e" | ||
} |
travetto: Schema | ||
=== | ||
**Install: primary** | ||
```bash | ||
$ npm install @travetto/schema | ||
``` | ||
This module provide a mechanisms for registering classes and field level information as well the ability to apply that information at runtime. | ||
@@ -17,2 +22,3 @@ | ||
**Code: Sample User Schema** | ||
```typescript | ||
@@ -28,2 +34,3 @@ @Schema() | ||
**Config: User schema as yaml** | ||
```yaml | ||
@@ -81,2 +88,3 @@ User: | ||
**Code: Sub Schemas via Address** | ||
```typescript | ||
@@ -99,2 +107,3 @@ @Schema() | ||
**Code: Binding from JSON to Schema** | ||
```typescript | ||
@@ -112,2 +121,4 @@ Person.from({ | ||
and the output would be a `Person` instance with the following structure | ||
**Code: Sample data output after binding** | ||
```typescript | ||
@@ -129,2 +140,3 @@ Person( | ||
**Code: Reference Schema for Validations** | ||
```typescript | ||
@@ -146,2 +158,4 @@ @Schema() | ||
But now with an invalid json object | ||
**Code: Read Person, and validate** | ||
```typescript | ||
@@ -166,2 +180,4 @@ const person = Person.from({ | ||
would produce an exception similar to following structure | ||
**Config: Sample error output** | ||
```yaml | ||
@@ -183,3 +199,5 @@ errors: | ||
`@SchemaBody` provides the ability to convert the inbound request body into a schema bound object, and provide validation before the controller even receives the request. | ||
```typescript | ||
**Code: Using SchemaBody for POST requests** | ||
```typescript | ||
import { SearchBody } from '@travetto/schema/extension/rest'; | ||
@@ -200,5 +218,8 @@ | ||
``` | ||
`@SchemaQuery` provides the ability to convert the inbound request query into a schema bound object, and provide validation before the controller even receives the request. | ||
**Code: Using SchemaQuery for GET requests** | ||
```typescript | ||
import { SearchQuery } from '@travetto/schema/extension/rest'; | ||
import { SchemaQuery } from '@travetto/schema/extension/rest'; | ||
@@ -268,2 +289,4 @@ class SearchParams { | ||
An example of this would be: | ||
**Code: More complex Schema, used with Faker** | ||
```typescript | ||
@@ -270,0 +293,0 @@ |
51379
308
Updated@travetto/config@^0.4.6
Updated@travetto/registry@^0.4.4