@@ -35,8 +35,10 @@ public class Schema {
35
35
case custom( String )
36
36
}
37
37
38
+ let dataType : DataType
39
+
38
40
/// The data type.
39
- public let type : DataType
41
+ public var type : String { dataType . rawValue }
40
42
41
43
/// The format of the data.
42
44
public let format : String ?
@@ -47,58 +49,22 @@ public class Schema {
47
49
/// Indicates if the value may be null.
48
50
public let nullable : Bool ?
49
51
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.
51
53
public let enumValues : [ String ] ?
52
54
53
- /// Schema of the elements of type ``DataType/array` `.
55
+ /// Schema of the elements of type `"ARRAY" `.
54
56
public let items : Schema ?
55
57
56
- /// Properties of type ``DataType/object` `.
58
+ /// Properties of type `"OBJECT" `.
57
59
public let properties : [ String : Schema ] ?
58
60
59
- /// Required properties of type ``DataType/object` `.
61
+ /// Required properties of type `"OBJECT" `.
60
62
public let requiredProperties : [ String ] ?
61
63
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
-
98
64
required init ( type: DataType , format: String ? = nil , description: String ? = nil ,
99
65
nullable: Bool = false , enumValues: [ String ] ? = nil , items: Schema ? = nil ,
100
66
properties: [ String : Schema ] ? = nil , requiredProperties: [ String ] ? = nil ) {
101
- self . type = type
67
+ dataType = type
102
68
self . format = format
103
69
self . description = description
104
70
self . nullable = nullable
@@ -110,8 +76,8 @@ public class Schema {
110
76
111
77
/// Returns a `Schema` representing a string value.
112
78
///
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`).
115
81
///
116
82
/// > Tip: If a specific set of string values should be generated by the model (for example,
117
83
/// > "north", "south", "east", or "west"), use ``enumeration(values:description:nullable:)``
@@ -139,9 +105,9 @@ public class Schema {
139
105
140
106
/// Returns a `Schema` representing an enumeration of string values.
141
107
///
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.
145
111
///
146
112
/// **Example:**
147
113
/// The values `["north", "south", "east", "west"]` for an enumeration of directions.
@@ -171,9 +137,9 @@ public class Schema {
171
137
172
138
/// Returns a `Schema` representing a single-precision floating-point number.
173
139
///
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`).
177
143
///
178
144
/// > Important: This `Schema` provides a hint to the model that it should generate a
179
145
/// > single-precision floating-point number, a `float`, but only guarantees that the value will
@@ -195,9 +161,9 @@ public class Schema {
195
161
196
162
/// Returns a `Schema` representing a double-precision floating-point number.
197
163
///
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`).
201
167
///
202
168
/// > Important: This `Schema` provides a hint to the model that it should generate a
203
169
/// > double-precision floating-point number, a `double`, but only guarantees that the value will
@@ -219,9 +185,9 @@ public class Schema {
219
185
220
186
/// Returns a `Schema` representing an integer value.
221
187
///
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.
225
191
///
226
192
/// > Important: If a `format` of ``IntegerFormat/int32`` or ``IntegerFormat/int64`` is
227
193
/// > specified, this provides a hint to the model that it should generate 32-bit or 64-bit
@@ -249,8 +215,8 @@ public class Schema {
249
215
250
216
/// Returns a `Schema` representing a boolean value.
251
217
///
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`).
254
220
///
255
221
/// - Parameters:
256
222
/// - description: An optional description of what the boolean should contain or represent; may
@@ -263,10 +229,10 @@ public class Schema {
263
229
264
230
/// Returns a `Schema` representing an array.
265
231
///
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.
270
236
///
271
237
/// - Parameters:
272
238
/// - items: The `Schema` of the elements that the array will hold.
@@ -281,10 +247,10 @@ public class Schema {
281
247
282
248
/// Returns a `Schema` representing an object.
283
249
///
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.
288
254
///
289
255
/// **Example:** A `City` could be represented with the following object `Schema`.
290
256
/// ```
@@ -331,34 +297,11 @@ public class Schema {
331
297
}
332
298
}
333
299
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
-
357
300
// MARK: - Codable Conformance
358
301
359
302
extension Schema : Encodable {
360
303
enum CodingKeys : String , CodingKey {
361
- case type
304
+ case dataType = " type "
362
305
case format
363
306
case description
364
307
case nullable
@@ -369,8 +312,6 @@ extension Schema: Encodable {
369
312
}
370
313
}
371
314
372
- extension DataType : Encodable { }
373
-
374
315
// MARK: - RawRepresentable Conformance
375
316
376
317
extension Schema . IntegerFormat : RawRepresentable {
0 commit comments