Skip to content

Commit a890307

Browse files
committed
docs: add schema generation documentation
1 parent 19d4f43 commit a890307

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

docs/advanced/schema.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Schemas
2+
3+
The library can **generate schema definitions** for all converters that support it and can **also regenerate**
4+
'materialize' **structures** from those **schema definitions**. The schema definition format is JSON-based and a
5+
subset of **JSON Schema** with some custom framework-specific extensions, primarily used for styling in the Flutter
6+
integration.
7+
8+
## API Examples
9+
10+
```{ .dart title="Export a Schema" }
11+
// This config fully expands all references for use in other tools
12+
final schemaConfig = SchemaConfig(useReferences: false);
13+
14+
final schema = dogs.describe<User>(config: schemaConfig);
15+
final exported = schema.toJson();
16+
```
17+
18+
```{ .dart title="Define a schema using the dsl" }
19+
final schema = object({
20+
"name": string(),
21+
"age": integer().min(0),
22+
});
23+
```
24+
25+
```{ .dart title="Load a converter from a JSON schema" }
26+
final schema = parseSchema([...]);
27+
final converter = dogs.materialize(schema);
28+
// Use the proxy methods of the converter
29+
```
30+
31+
```{ .dart title="Import a json schema into the global dogs instance" }
32+
final schema = parseSchema([...]);
33+
final typeReference = dogs.importSchema(schema);
34+
// Use the returned type reference like a type tree
35+
```
36+
37+
## Supported JSON Schema Properties
38+
39+
- `type: string | number | integer | boolean | null`
40+
- `enum: [string]`
41+
- `default: any`
42+
43+
List/Array specific:
44+
45+
- `minItems: int`
46+
- `maxItems: int`
47+
- `uniqueItems: bool`
48+
49+
Object specific:
50+
`required: [String]` (Only written, for reading only unions with `null` make fields optional)
51+
52+
Number specific:
53+
54+
- `minimum: number`
55+
- `maximum: number`
56+
- `exclusiveMinimum: number`
57+
- `exclusiveMaximum: number`
58+
59+
String specific:
60+
61+
- `minLength: int`
62+
- `maxLength: int`
63+
- `pattern: string`

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ nav:
4141
- advanced/annotations.md
4242
- advanced/hooks.md
4343
- advanced/operation_modes.md
44+
- advanced/schema.md
4445
- "Flutter [dogs_flutter]":
4546
- flutter/index.md
4647
- flutter/converters.md

0 commit comments

Comments
 (0)