@@ -20,19 +20,41 @@ import Foundation
20
20
/// [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema).
21
21
public class Schema {
22
22
/// Modifiers describing the expected format of a string `Schema`.
23
- public enum StringFormat {
23
+ public struct StringFormat : EncodableProtoEnum {
24
+ // This enum is currently only used to conform `StringFormat` to `ProtoEnum`, which requires
25
+ // `associatedtype Kind: RawRepresentable<String>`.
26
+ enum Kind : String {
27
+ // Providing a case resolves the error "An enum with no cases cannot declare a raw type".
28
+ case unused // TODO: Remove `unused` case when we have at least one specific string format.
29
+ }
30
+
24
31
/// A custom string format.
25
- case custom( String )
32
+ public static func custom( _ format: String ) -> StringFormat {
33
+ return self . init ( rawValue: format)
34
+ }
35
+
36
+ let rawValue : String
26
37
}
27
38
28
39
/// Modifiers describing the expected format of an integer `Schema`.
29
- public enum IntegerFormat {
40
+ public struct IntegerFormat : EncodableProtoEnum {
41
+ enum Kind : String {
42
+ case int32
43
+ case int64
44
+ }
45
+
30
46
/// A 32-bit signed integer.
31
- case int32
47
+ public static let int32 = IntegerFormat ( kind: . int32)
48
+
32
49
/// A 64-bit signed integer.
33
- case int64
50
+ public static let int64 = IntegerFormat ( kind: . int64)
51
+
34
52
/// A custom integer format.
35
- case custom( String )
53
+ public static func custom( _ format: String ) -> IntegerFormat {
54
+ return self . init ( rawValue: format)
55
+ }
56
+
57
+ let rawValue : String
36
58
}
37
59
38
60
let dataType : DataType
@@ -311,45 +333,3 @@ extension Schema: Encodable {
311
333
case requiredProperties = " required "
312
334
}
313
335
}
314
-
315
- // MARK: - RawRepresentable Conformance
316
-
317
- extension Schema . IntegerFormat : RawRepresentable {
318
- public init ? ( rawValue: String ) {
319
- switch rawValue {
320
- case " int32 " :
321
- self = . int32
322
- case " int64 " :
323
- self = . int64
324
- default :
325
- self = . custom( rawValue)
326
- }
327
- }
328
-
329
- public var rawValue : String {
330
- switch self {
331
- case . int32:
332
- return " int32 "
333
- case . int64:
334
- return " int64 "
335
- case let . custom( format) :
336
- return format
337
- }
338
- }
339
- }
340
-
341
- extension Schema . StringFormat : RawRepresentable {
342
- public init ? ( rawValue: String ) {
343
- switch rawValue {
344
- default :
345
- self = . custom( rawValue)
346
- }
347
- }
348
-
349
- public var rawValue : String {
350
- switch self {
351
- case let . custom( format) :
352
- return format
353
- }
354
- }
355
- }
0 commit comments