@@ -35,8 +35,10 @@ public class Schema {
3535 case custom( String )
3636 }
3737
38+ let dataType : DataType
39+
3840 /// The data type.
39- public let type : DataType
41+ public var type : String { dataType . rawValue }
4042
4143 /// The format of the data.
4244 public let format : String ?
@@ -47,58 +49,22 @@ public class Schema {
4749 /// Indicates if the value may be null.
4850 public let nullable : Bool ?
4951
50- /// Possible values of the element of type ``DataType/string`` with "enum" format.
52+ /// Possible values of the element of type "STRING" with "enum" format.
5153 public let enumValues : [ String ] ?
5254
53- /// Schema of the elements of type ``DataType/array` `.
55+ /// Schema of the elements of type `"ARRAY" `.
5456 public let items : Schema ?
5557
56- /// Properties of type ``DataType/object` `.
58+ /// Properties of type `"OBJECT" `.
5759 public let properties : [ String : Schema ] ?
5860
59- /// Required properties of type ``DataType/object` `.
61+ /// Required properties of type `"OBJECT" `.
6062 public let requiredProperties : [ String ] ?
6163
62- /// Constructs a new `Schema`.
63- ///
64- /// - Parameters:
65- /// - type: The data type.
66- /// - format: The format of the data; used only for primitive datatypes.
67- /// Supported formats:
68- /// - ``DataType/integer``: int32, int64
69- /// - ``DataType/number``: float, double
70- /// - ``DataType/string``: enum
71- /// - description: A brief description of the parameter; may be formatted as Markdown.
72- /// - nullable: Indicates if the value may be null.
73- /// - enumValues: Possible values of the element of type ``DataType/string`` with "enum" format.
74- /// For example, an enum `Direction` may be defined as `["EAST", NORTH", "SOUTH", "WEST"]`.
75- /// - items: Schema of the elements of type ``DataType/array``.
76- /// - properties: Properties of type ``DataType/object``.
77- /// - requiredProperties: Required properties of type ``DataType/object``.
78- @available ( * , deprecated, message: """
79- Use static methods `string(description:format:nullable:)`, `number(description:format:nullable:)`,
80- etc., instead.
81- """ )
82- public convenience init ( type: DataType , format: String ? = nil , description: String ? = nil ,
83- nullable: Bool ? = nil , enumValues: [ String ] ? = nil , items: Schema ? = nil ,
84- properties: [ String : Schema ] ? = nil ,
85- requiredProperties: [ String ] ? = nil ) {
86- self . init (
87- type: type,
88- format: format,
89- description: description,
90- nullable: nullable ?? false ,
91- enumValues: enumValues,
92- items: items,
93- properties: properties,
94- requiredProperties: requiredProperties
95- )
96- }
97-
9864 required init ( type: DataType , format: String ? = nil , description: String ? = nil ,
9965 nullable: Bool = false , enumValues: [ String ] ? = nil , items: Schema ? = nil ,
10066 properties: [ String : Schema ] ? = nil , requiredProperties: [ String ] ? = nil ) {
101- self . type = type
67+ dataType = type
10268 self . format = format
10369 self . description = description
10470 self . nullable = nullable
@@ -110,8 +76,8 @@ public class Schema {
11076
11177 /// Returns a `Schema` representing a string value.
11278 ///
113- /// This schema instructs the model to produce data of type ``DataType/string`` , which is suitable
114- /// for decoding into a Swift `String` (or `String?`, if `nullable` is set to `true`).
79+ /// This schema instructs the model to produce data of type `"STRING"` , which is suitable for
80+ /// decoding into a Swift `String` (or `String?`, if `nullable` is set to `true`).
11581 ///
11682 /// > Tip: If a specific set of string values should be generated by the model (for example,
11783 /// > "north", "south", "east", or "west"), use ``enumeration(values:description:nullable:)``
@@ -139,9 +105,9 @@ public class Schema {
139105
140106 /// Returns a `Schema` representing an enumeration of string values.
141107 ///
142- /// This schema instructs the model to produce data of type ``DataType/string`` with the
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.
108+ /// This schema instructs the model to produce data of type `"STRING"` with the `format` `"enum"`.
109+ /// This data is suitable for decoding into a Swift `String` (or `String?`, if `nullable` is set
110+ /// to `true`), or an `enum` with strings as raw values.
145111 ///
146112 /// **Example:**
147113 /// The values `["north", "south", "east", "west"]` for an enumeration of directions.
@@ -171,9 +137,9 @@ public class Schema {
171137
172138 /// Returns a `Schema` representing a single-precision floating-point number.
173139 ///
174- /// This schema instructs the model to produce data of type ``DataType/number`` with the
175- /// `format` ` "float"`, which is suitable for decoding into a Swift `Float` (or `Float?`, if
176- /// `nullable` is set to `true`).
140+ /// This schema instructs the model to produce data of type `"NUMBER"` with the `format`
141+ /// `"float"`, which is suitable for decoding into a Swift `Float` (or `Float?`, if `nullable` is
142+ /// set to `true`).
177143 ///
178144 /// > Important: This `Schema` provides a hint to the model that it should generate a
179145 /// > single-precision floating-point number, a `float`, but only guarantees that the value will
@@ -195,9 +161,9 @@ public class Schema {
195161
196162 /// Returns a `Schema` representing a double-precision floating-point number.
197163 ///
198- /// This schema instructs the model to produce data of type ``DataType/number`` with the
199- /// `format` ` "double"`, which is suitable for decoding into a Swift `Double` (or `Double?`, if
200- /// `nullable` is set to `true`).
164+ /// This schema instructs the model to produce data of type `"NUMBER"` with the `format`
165+ /// `"double"`, which is suitable for decoding into a Swift `Double` (or `Double?`, if `nullable`
166+ /// is set to `true`).
201167 ///
202168 /// > Important: This `Schema` provides a hint to the model that it should generate a
203169 /// > double-precision floating-point number, a `double`, but only guarantees that the value will
@@ -219,9 +185,9 @@ public class Schema {
219185
220186 /// Returns a `Schema` representing an integer value.
221187 ///
222- /// This schema instructs the model to produce data of type ``DataType/integer`` , which is
223- /// suitable for decoding into a Swift `Int` (or `Int?`, if `nullable` is set to `true`) or other
224- /// integer types (such as `Int32`) based on the expected size of values being generated.
188+ /// This schema instructs the model to produce data of type `"INTEGER"` , which is suitable for
189+ /// decoding into a Swift `Int` (or `Int?`, if `nullable` is set to `true`) or other integer types
190+ /// (such as `Int32`) based on the expected size of values being generated.
225191 ///
226192 /// > Important: If a `format` of ``IntegerFormat/int32`` or ``IntegerFormat/int64`` is
227193 /// > specified, this provides a hint to the model that it should generate 32-bit or 64-bit
@@ -249,8 +215,8 @@ public class Schema {
249215
250216 /// Returns a `Schema` representing a boolean value.
251217 ///
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`).
218+ /// This schema instructs the model to produce data of type `"BOOLEAN"` , which is suitable for
219+ /// decoding into a Swift `Bool` (or `Bool?`, if `nullable` is set to `true`).
254220 ///
255221 /// - Parameters:
256222 /// - description: An optional description of what the boolean should contain or represent; may
@@ -263,10 +229,10 @@ public class Schema {
263229
264230 /// Returns a `Schema` representing an array.
265231 ///
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.
232+ /// This schema instructs the model to produce data of type `"ARRAY"` , which has elements of any
233+ /// other data type (including nested `"ARRAY"` s). This data is suitable for decoding into many
234+ /// Swift collection types, including `Array`, holding elements of types suitable for decoding
235+ /// from the respective `items` type.
270236 ///
271237 /// - Parameters:
272238 /// - items: The `Schema` of the elements that the array will hold.
@@ -281,10 +247,10 @@ public class Schema {
281247
282248 /// Returns a `Schema` representing an object.
283249 ///
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.
250+ /// This schema instructs the model to produce data of type `"OBJECT"` , which has keys of type
251+ /// `"STRING"` and values of any other data type (including nested `"OBJECT"`s). This data is
252+ /// suitable for decoding into Swift keyed collection types, including `Dictionary`, or other
253+ /// custom `struct` or `class` types.
288254 ///
289255 /// **Example:** A `City` could be represented with the following object `Schema`.
290256 /// ```
@@ -331,34 +297,11 @@ public class Schema {
331297 }
332298}
333299
334- /// A data type.
335- ///
336- /// Contains the set of OpenAPI [data types](https://spec.openapis.org/oas/v3.0.3#data-types).
337- public enum DataType : String {
338- /// A `String` type.
339- case string = " STRING "
340-
341- /// A floating-point number type.
342- case number = " NUMBER "
343-
344- /// An integer type.
345- case integer = " INTEGER "
346-
347- /// A boolean type.
348- case boolean = " BOOLEAN "
349-
350- /// An array type.
351- case array = " ARRAY "
352-
353- /// An object type.
354- case object = " OBJECT "
355- }
356-
357300// MARK: - Codable Conformance
358301
359302extension Schema : Encodable {
360303 enum CodingKeys : String , CodingKey {
361- case type
304+ case dataType = " type "
362305 case format
363306 case description
364307 case nullable
@@ -369,8 +312,6 @@ extension Schema: Encodable {
369312 }
370313}
371314
372- extension DataType : Encodable { }
373-
374315// MARK: - RawRepresentable Conformance
375316
376317extension Schema . IntegerFormat : RawRepresentable {
0 commit comments