@@ -19,13 +19,19 @@ import Foundation
1919/// These types can be objects, but also primitives and arrays. Represents a select subset of an
2020/// [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema).
2121public class Schema {
22+ /// Modifiers describing the expected format of a string `Schema`.
2223 public enum StringFormat {
24+ /// A custom string format.
2325 case custom( String )
2426 }
2527
28+ /// Modifiers describing the expected format of an integer `Schema`.
2629 public enum IntegerFormat {
30+ /// A 32-bit signed integer.
2731 case int32
32+ /// A 64-bit signed integer.
2833 case int64
34+ /// A custom integer format.
2935 case custom( String )
3036 }
3137
@@ -105,7 +111,7 @@ public class Schema {
105111 /// Returns a `Schema` representing a string value.
106112 ///
107113 /// 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`).
114+ /// for decoding into a Swift `String` (or `String?`, if `nullable` is set to `true`).
109115 ///
110116 /// > Tip: If a specific set of string values should be generated by the model (for example,
111117 /// > "north", "south", "east", or "west"), use ``enumeration(values:description:nullable:)``
@@ -134,8 +140,8 @@ public class Schema {
134140 /// Returns a `Schema` representing an enumeration of string values.
135141 ///
136142 /// 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.
143+ /// `format` `"enum"`. This data is suitable for decoding into a Swift `String` (or `String?`,
144+ /// if `nullable` is set to `true`), or an `enum` with strings as raw values.
139145 ///
140146 /// **Example:**
141147 /// The values `["north", "south", "east", "west"]` for an enumation of directions.
@@ -166,8 +172,8 @@ public class Schema {
166172 /// Returns a `Schema` representing a single-precision floating-point number.
167173 ///
168174 /// 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`).
175+ /// `format` `"float"`, which is suitable for decoding into a Swift `Float` (or `Float?`, if
176+ /// `nullable` is set to `true`).
171177 ///
172178 /// > Important: This `Schema` provides a hint to the model that it should generate a
173179 /// > single-precision floating-point number, a `float`, but only guarantees that the value will
@@ -190,8 +196,8 @@ public class Schema {
190196 /// Returns a `Schema` representing a double-precision floating-point number.
191197 ///
192198 /// 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`).
199+ /// `format` `"double"`, which is suitable for decoding into a Swift `Double` (or `Double?`, if
200+ /// `nullable` is set to `true`).
195201 ///
196202 /// > Important: This `Schema` provides a hint to the model that it should generate a
197203 /// > double-precision floating-point number, a `double`, but only guarantees that the value will
@@ -214,13 +220,13 @@ public class Schema {
214220 /// Returns a `Schema` representing an integer value.
215221 ///
216222 /// 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
223+ /// suitable for decoding into a Swift `Int` (or `Int?`, if `nullable` is set to `true`) or other
218224 /// integer types (such as `Int32`) based on the expected size of values being generated.
219225 ///
220- /// > Important: If a `` format` ` of ``IntegerFormat/int32`` or ``IntegerFormat/int64`` is
226+ /// > Important: If a `format` of ``IntegerFormat/int32`` or ``IntegerFormat/int64`` is
221227 /// > specified, this provides a hint to the model that it should generate 32-bit or 64-bit
222228 /// > 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
229+ /// > is *possible* that decoding into an `Int32` could overflow even if a `format` of
224230 /// > ``IntegerFormat/int32`` is specified.
225231 ///
226232 /// - Parameters:
@@ -241,15 +247,70 @@ public class Schema {
241247 )
242248 }
243249
250+ /// Returns a `Schema` representing a boolean value.
251+ ///
252+ /// This schema instructs the model to produce data of type ``DataType/boolean``, which is
253+ /// suitable for decoding into a Swift `Bool` (or `Bool?`, if `nullable` is set to `true`).
254+ ///
255+ /// - Parameters:
256+ /// - description: An optional description of what the boolean should contain or represent; may
257+ /// use Markdown format.
258+ /// - nullable: If `true`, instructs the model that it may return `null` instead of a boolean;
259+ /// defaults to `false`, enforcing that a boolean is returned.
244260 public static func boolean( description: String ? = nil , nullable: Bool = false ) -> Schema {
245261 return self . init ( type: . boolean, description: description, nullable: nullable)
246262 }
247263
264+ /// Returns a `Schema` representing an array.
265+ ///
266+ /// This schema instructs the model to produce data of type ``DataType/array``, which has elements
267+ /// of any other ``DataType`` (including nested ``DataType/array``s). This data is suitable for
268+ /// decoding into many Swift collection types, including `Array`, holding elements of types
269+ /// suitable for decoding from the respective `items` type.
270+ ///
271+ /// - Parameters:
272+ /// - items: The `Schema` of the elements that the array will hold.
273+ /// - description: An optional description of what the array should contain or represent; may
274+ /// use Markdown format.
275+ /// - nullable: If `true`, instructs the model that it may return `null` instead of an array;
276+ /// defaults to `false`, enforcing that an array is returned.
248277 public static func array( items: Schema , description: String ? = nil ,
249278 nullable: Bool = false ) -> Schema {
250279 return self . init ( type: . array, description: description, nullable: nullable, items: items)
251280 }
252281
282+ /// Returns a `Schema` representing an object.
283+ ///
284+ /// This schema instructs the model to produce data of type ``DataType/object``, which has keys
285+ /// of type ``DataType/string`` and values of any other ``DataType`` (including nested
286+ /// ``DataType/object``s). This data is suitable for decoding into Swift keyed collection types,
287+ /// including `Dictionary`, or other custom `struct` or `class` types.
288+ ///
289+ /// **Example:** A `City` could be represented with the following object `Schema`.
290+ /// ```
291+ /// Schema.object(properties: [
292+ /// "name" : .string(),
293+ /// "population": .integer()
294+ /// ])
295+ /// ```
296+ /// The generated data could be decoded into a Swift native type:
297+ /// ```
298+ /// struct City: Decodable {
299+ /// let name: String
300+ /// let population: Int
301+ /// }
302+ /// ```
303+ ///
304+ /// - Parameters:
305+ /// - properties: A dictionary containing the object's property names as keys and their
306+ /// respective `Schema`s as values.
307+ /// - optionalProperties: A list of property names that may be be omitted in objects generated
308+ /// by the model; these names must correspond to the keys provided in the `properties`
309+ /// dictionary and may be an empty list.
310+ /// - description: An optional description of what the object should contain or represent; may
311+ /// use Markdown format.
312+ /// - nullable: If `true`, instructs the model that it may return `null` instead of an object;
313+ /// defaults to `false`, enforcing that an object is returned.
253314 public static func object( properties: [ String : Schema ] , optionalProperties: [ String ] = [ ] ,
254315 description: String ? = nil , nullable: Bool = false ) -> Schema {
255316 var requiredProperties = Set ( properties. keys)
0 commit comments