@@ -21,13 +21,13 @@ ensuring that data complies with an expected format before it is used, which red
21
21
| 🚧 Null Safety | Full support for nullable and optional fields |
22
22
| ⚙️ Composable | Compiled and reusable schemas |
23
23
| ⚡ Fast Performance | ~ 29 000 000 ops/s |
24
- | 📦 Extremely small size | Package size ` < 20kb ` |
24
+ | 📦 Extremely small size | Package size ` < 21kb ` |
25
+ | 🚀 OpenApi reporter | Export your schemas as OpenApi spec |
25
26
26
27
## 🚀 Usage
27
28
28
29
Vine is a data structure validation library for Dart. You may use it to validate the HTTP request body or any data in
29
- your
30
- backend applications.
30
+ your backend applications.
31
31
32
32
### Built for validating form data and JSON payloads
33
33
@@ -57,13 +57,13 @@ import 'package:vine/vine.dart';
57
57
58
58
void main() {
59
59
final validator = vine.compile(
60
- vine.object({
61
- 'username': vine.string().minLength(3).maxLength(20),
62
- 'email': vine.string().email(),
63
- 'age': vine.number().min(18).optional(),
64
- 'isAdmin': vine.boolean(),
65
- 'features': vine.array(vine.string()),
66
- }));
60
+ vine.object({
61
+ 'username': vine.string().minLength(3).maxLength(20),
62
+ 'email': vine.string().email(),
63
+ 'age': vine.number().min(18).optional(),
64
+ 'isAdmin': vine.boolean(),
65
+ 'features': vine.array(vine.string()),
66
+ }));
67
67
68
68
try {
69
69
final payload = {
@@ -82,6 +82,29 @@ void main() {
82
82
}
83
83
```
84
84
85
+ ### OpenAPI reporter
86
+
87
+ Vine can generate an OpenAPI schema from your validation schemas.
88
+ This feature is useful when you want to document your API
89
+
90
+ ``` dart
91
+ final schema = vine.object({
92
+ 'stringField': vine.string().minLength(3).maxLength(20),
93
+ 'emailField': vine.string().email(),
94
+ 'numberField': vine.number().min(18).max(100),
95
+ 'booleanField': vine.boolean(),
96
+ 'enumField': vine.enumerate(MyEnum.values),
97
+ 'arrayField': vine.array(vine.string().minLength(3).maxLength(20)).minLength(1),
98
+ 'unionField': vine.union([
99
+ vine.string().minLength(3).maxLength(20),
100
+ vine.number().min(10).max(20),
101
+ ]),
102
+ });
103
+
104
+ final reporter = vine.openApi.report(schemas: {'MySchema': schema});
105
+ print(reporter);
106
+ ```
107
+
85
108
## ❤️ Credit
86
109
87
110
I would like to thank [ Harminder Virk] ( https://github.com/thetutlage ) for all his open-source work on Adonis.js and for
0 commit comments