11import "dogs_core.dart" ;
22
3+ /// Creates a schema type representing a string.
34SchemaType string () => SchemaType .string;
45
6+ /// Creates a schema type representing an integer.
57SchemaType integer () => SchemaType .integer;
68
9+ /// Creates a schema type representing a number.
710SchemaType number () => SchemaType .number;
811
12+ /// Creates a schema type representing a boolean.
913SchemaType boolean () => SchemaType .boolean;
1014
15+ /// Creates a schema type representing any value.
1116SchemaType any () => SchemaType .any;
1217
18+ /// Creates a schema type representing an object with the given properties.
1319SchemaType object (Map <String , SchemaType > properties) {
1420 return SchemaType .object (
1521 fields:
1622 properties.entries.map ((e) => SchemaField (e.key, e.value)).toList ());
1723}
1824
25+ /// Creates a schema type representing an array of the given item type.
1926SchemaType array (SchemaType itemType) {
2027 return SchemaType .array (itemType);
2128}
2229
30+ /// Creates a schema type representing a reference to another schema by its serial name.
2331SchemaType ref (String serialName) {
2432 return SchemaType .reference (serialName);
2533}
2634
35+ /// Creates a schema type representing a string-keyed map with values of the given item type.
2736SchemaType map (SchemaType itemType) {
2837 return SchemaType .map (itemType);
2938}
3039
40+ /// Creates a schema type representing an enumeration of the given string values.
3141SchemaType enumeration (List <String > values) {
3242 return SchemaType .string.property (SchemaProperties .$enum, values);
3343}
3444
45+ /// Extension methods for SchemaType to provide a fluent API for schema definitions.
3546extension SchemaTypeExtension on SchemaType {
47+
48+ /// Makes this schema type an array of itself.
3649 SchemaType array () => SchemaType .array (this );
3750
51+ /// Marks this schema type as optional (nullable).
3852 SchemaType optional () => this ..nullable = true ;
3953
54+ /// Adds a custom property to the schema.
4055 SchemaType property (String key, dynamic value) =>
4156 this ..properties[key] = value;
4257
@@ -82,6 +97,7 @@ extension SchemaTypeExtension on SchemaType {
8297 throw ArgumentError ("Max is not supported for $this " );
8398 }
8499
100+ /// Requires the value to be larger than the given value.
85101 SchemaType gt (double value) {
86102 if (type == SchemaCoreType .number || type == SchemaCoreType .integer) {
87103 return property (SchemaProperties .minimum, value)
@@ -91,6 +107,7 @@ extension SchemaTypeExtension on SchemaType {
91107 throw ArgumentError ("Gt is not supported for $this " );
92108 }
93109
110+ /// Requires the value to be larger than or equal to the given value.
94111 SchemaType gte (double value) {
95112 if (type == SchemaCoreType .number || type == SchemaCoreType .integer) {
96113 return property (SchemaProperties .minimum, value);
@@ -99,6 +116,7 @@ extension SchemaTypeExtension on SchemaType {
99116 throw ArgumentError ("Gte is not supported for $this " );
100117 }
101118
119+ /// Requires the value to be less than the given value.
102120 SchemaType lt (double value) {
103121 if (type == SchemaCoreType .number || type == SchemaCoreType .integer) {
104122 return property (SchemaProperties .maximum, value)
@@ -108,6 +126,8 @@ extension SchemaTypeExtension on SchemaType {
108126 throw ArgumentError ("Lt is not supported for $this " );
109127 }
110128
129+
130+ /// Requires the value to be less than or equal to the given value.
111131 SchemaType lte (double value) {
112132 if (type == SchemaCoreType .number || type == SchemaCoreType .integer) {
113133 return property (SchemaProperties .maximum, value);
@@ -116,18 +136,30 @@ extension SchemaTypeExtension on SchemaType {
116136 throw ArgumentError ("Lte is not supported for $this " );
117137 }
118138
139+ /// Requires the value to be a positive number (greater than 0).
119140 SchemaType positive () => gte (0 );
141+
142+ /// Requires the value to be a negative number (less than 0).
120143 SchemaType negative () => lte (0 );
144+
145+ /// Requires the value to be a non-negative number (0 or greater).
121146 SchemaType nonNegative () => gte (0 );
147+
148+ /// Requires the value to be a non-positive number (0 or less).
122149 SchemaType nonPositive () => lte (0 );
150+
151+ /// Sets both the minimum and maximum values to the given length.
123152 SchemaType length (int length) => min (length).max (length);
153+
154+ /// Requires all items in the array to be unique.
124155 SchemaType unique () {
125156 if (this is ! SchemaArray ) {
126157 throw ArgumentError ("Unique is only supported for arrays" );
127158 }
128159 return property (SchemaProperties .uniqueItems, true );
129160 }
130161
162+ /// Sets the serial name for this schema type. Only supported for objects.
131163 SchemaType serialName (String serialName) {
132164 if (this is ! SchemaObject ) {
133165 throw ArgumentError ("Serial name is only supported for objects" );
0 commit comments