@@ -102,6 +102,25 @@ public class Schema {
102
102
self . requiredProperties = requiredProperties
103
103
}
104
104
105
+ /// Returns a `Schema` representing a string value.
106
+ ///
107
+ /// This schema instructs the model to produce data of type ``DataType/string``, which is suitable
108
+ /// for decoding as a Swift `String` (or `String?`, if ``nullable`` is set to `true`).
109
+ ///
110
+ /// > Tip: If a specific set of string values should be generated by the model (for example,
111
+ /// > "north", "south", "east", or "west"), use ``enumeration(values:description:nullable:)``
112
+ /// > instead to constrain the generated values.
113
+ ///
114
+ /// - Parameters:
115
+ /// - description: An optional description of what the string should contain or represent; may
116
+ /// use Markdown format.
117
+ /// - nullable: If `true`, instructs the model that it *may* generate `null` instead of a
118
+ /// string; defaults to `false`, enforcing that a string value is generated.
119
+ /// - format: An optional modifier describing the expected format of the string. Currently no
120
+ /// formats are officially supported for strings but custom values may be specified using
121
+ /// ``StringFormat/custom(_:)``, for example `.custom("email")` or `.custom("byte")`; these
122
+ /// provide additional hints for how the model should respond but are not guaranteed to be
123
+ /// adhered to.
105
124
public static func string( description: String ? = nil , nullable: Bool = false ,
106
125
format: StringFormat ? = nil ) -> Schema {
107
126
return self . init (
@@ -112,6 +131,27 @@ public class Schema {
112
131
)
113
132
}
114
133
134
+ /// Returns a `Schema` representing an enumeration of string values.
135
+ ///
136
+ /// This schema instructs the model to produce data of type ``DataType/string`` with the
137
+ /// ``format`` `"enum"`. This data is suitable for decoding as a Swift `String` (or `String?`,
138
+ /// if ``nullable`` is set to `true`), or an `enum` with strings as raw values.
139
+ ///
140
+ /// **Example:**
141
+ /// The values `["north", "south", "east", "west"]` for an enumation of directions.
142
+ /// ```
143
+ /// enum Direction: String, Decodable {
144
+ /// case north, south, east, west
145
+ /// }
146
+ /// ```
147
+ ///
148
+ /// - Parameters:
149
+ /// - values: The list of string values that may be generated by the model.
150
+ /// - description: An optional description of what the `values` contain or represent; may use
151
+ /// Markdown format.
152
+ /// - nullable: If `true`, instructs the model that it *may* generate `null` instead of one of
153
+ /// the strings specified in `values`; defaults to `false`, enforcing that one of the string
154
+ /// values is generated.
115
155
public static func enumeration( values: [ String ] , description: String ? = nil ,
116
156
nullable: Bool = false ) -> Schema {
117
157
return self . init (
@@ -123,6 +163,21 @@ public class Schema {
123
163
)
124
164
}
125
165
166
+ /// Returns a `Schema` representing a single-precision floating-point number.
167
+ ///
168
+ /// This schema instructs the model to produce data of type ``DataType/number`` with the
169
+ /// ``format`` `"float"`, which is suitable for decoding as a Swift `Float` (or `Float?`, if
170
+ /// ``nullable`` is set to `true`).
171
+ ///
172
+ /// > Important: This `Schema` provides a hint to the model that it should generate a
173
+ /// > single-precision floating-point number, a `float`, but only guarantees that the value will
174
+ /// > be a number.
175
+ ///
176
+ /// - Parameters:
177
+ /// - description: An optional description of what the number should contain or represent; may
178
+ /// use Markdown format.
179
+ /// - nullable: If `true`, instructs the model that it may generate `null` instead of a number;
180
+ /// defaults to `false`, enforcing that a number is generated.
126
181
public static func float( description: String ? = nil , nullable: Bool = false ) -> Schema {
127
182
return self . init (
128
183
type: . number,
@@ -132,6 +187,21 @@ public class Schema {
132
187
)
133
188
}
134
189
190
+ /// Returns a `Schema` representing a double-precision floating-point number.
191
+ ///
192
+ /// This schema instructs the model to produce data of type ``DataType/number`` with the
193
+ /// ``format`` `"double"`, which is suitable for decoding as a Swift `Double` (or `Double?`, if
194
+ /// ``nullable`` is set to `true`).
195
+ ///
196
+ /// > Important: This `Schema` provides a hint to the model that it should generate a
197
+ /// > double-precision floating-point number, a `double`, but only guarantees that the value will
198
+ /// > be a number.
199
+ ///
200
+ /// - Parameters:
201
+ /// - description: An optional description of what the number should contain or represent; may
202
+ /// use Markdown format.
203
+ /// - nullable: If `true`, instructs the model that it may return `null` instead of a number;
204
+ /// defaults to `false`, enforcing that a number is returned.
135
205
public static func double( description: String ? = nil , nullable: Bool = false ) -> Schema {
136
206
return self . init (
137
207
type: . number,
@@ -141,6 +211,26 @@ public class Schema {
141
211
)
142
212
}
143
213
214
+ /// Returns a `Schema` representing an integer value.
215
+ ///
216
+ /// This schema instructs the model to produce data of type ``DataType/integer``, which is
217
+ /// suitable for decoding as a Swift `Int` (or `Int?`, if ``nullable`` is set to `true`) or other
218
+ /// integer types (such as `Int32`) based on the expected size of values being generated.
219
+ ///
220
+ /// > Important: If a ``format`` of ``IntegerFormat/int32`` or ``IntegerFormat/int64`` is
221
+ /// > specified, this provides a hint to the model that it should generate 32-bit or 64-bit
222
+ /// > integers but this `Schema` only guarantees that the value will be an integer. Therefore, it
223
+ /// > is *possible* that decoding as an `Int32` could overflow even if a ``format`` of
224
+ /// > ``IntegerFormat/int32`` is specified.
225
+ ///
226
+ /// - Parameters:
227
+ /// - description: An optional description of what the integer should contain or represent; may
228
+ /// use Markdown format.
229
+ /// - nullable: If `true`, instructs the model that it may return `null` instead of an integer;
230
+ /// defaults to `false`, enforcing that an integer is returned.
231
+ /// - format: An optional modifier describing the expected format of the integer. Currently the
232
+ /// formats ``IntegerFormat/int32`` and ``IntegerFormat/int64`` are supported; custom values
233
+ /// may be specified using ``IntegerFormat/custom(_:)`` but may be ignored by the model.
144
234
public static func integer( description: String ? = nil , nullable: Bool = false ,
145
235
format: IntegerFormat ? = nil ) -> Schema {
146
236
return self . init (
0 commit comments