@@ -19,6 +19,9 @@ struct TypeMatcher {
19
19
/// A converted function from user-provided strings to strings
20
20
/// safe to be used as a Swift identifier.
21
21
var asSwiftSafeName : ( String ) -> String
22
+
23
+ /// Indication whether the uuid format should be respected.
24
+ var enableUUIDSupport : Bool
22
25
23
26
/// Returns the type name of a built-in type that matches the specified
24
27
/// schema.
@@ -43,7 +46,7 @@ struct TypeMatcher {
43
46
func tryMatchBuiltinType( for schema: JSONSchema . Schema ) -> TypeUsage ? {
44
47
Self . _tryMatchRecursive (
45
48
for: schema,
46
- test: { schema in Self . _tryMatchBuiltinNonRecursive ( for: schema) } ,
49
+ test: { schema in Self . _tryMatchBuiltinNonRecursive ( for: schema, enableUUIDSupport : enableUUIDSupport ) } ,
47
50
matchedArrayHandler: { elementType, nullableItems in
48
51
nullableItems ? elementType. asOptional. asArray : elementType. asArray
49
52
} ,
@@ -69,9 +72,12 @@ struct TypeMatcher {
69
72
try Self . _tryMatchRecursive (
70
73
for: schema. value,
71
74
test: { ( schema) -> TypeUsage ? in
72
- if let builtinType = Self . _tryMatchBuiltinNonRecursive ( for: schema) { return builtinType }
75
+ if let builtinType = Self . _tryMatchBuiltinNonRecursive ( for: schema, enableUUIDSupport: enableUUIDSupport) {
76
+ return builtinType
77
+ }
73
78
guard case let . reference( ref, _) = schema else { return nil }
74
- return try TypeAssigner ( asSwiftSafeName: asSwiftSafeName) . typeName ( for: ref) . asUsage
79
+ return try TypeAssigner ( asSwiftSafeName: asSwiftSafeName, enableUUIDSupport: enableUUIDSupport)
80
+ . typeName ( for: ref) . asUsage
75
81
} ,
76
82
matchedArrayHandler: { elementType, nullableItems in
77
83
nullableItems ? elementType. asOptional. asArray : elementType. asArray
@@ -87,14 +93,16 @@ struct TypeMatcher {
87
93
/// A referenceable schema is one of:
88
94
/// - A builtin type
89
95
/// - A reference
90
- /// - Parameter schema: The schema to match a referenceable type for.
96
+ /// - Parameters:
97
+ /// - schema: The schema to match a referenceable type for.
98
+ /// - enableUUIDSupport: Indication whether the uuid format should be respected.
91
99
/// - Returns: `true` if the schema is referenceable; `false` otherwise.
92
- static func isReferenceable( _ schema: JSONSchema ) -> Bool {
100
+ static func isReferenceable( _ schema: JSONSchema , enableUUIDSupport : Bool ) -> Bool {
93
101
// This logic should be kept in sync with `tryMatchReferenceableType`.
94
102
_tryMatchRecursive (
95
103
for: schema. value,
96
104
test: { schema in
97
- if _tryMatchBuiltinNonRecursive ( for: schema) != nil { return true }
105
+ if _tryMatchBuiltinNonRecursive ( for: schema, enableUUIDSupport : enableUUIDSupport ) != nil { return true }
98
106
guard case . reference = schema else { return false }
99
107
return true
100
108
} ,
@@ -109,9 +117,11 @@ struct TypeMatcher {
109
117
/// A referenceable schema is one of:
110
118
/// - A builtin type
111
119
/// - A reference
112
- /// - Parameter schema: The schema to match a referenceable type for.
120
+ /// - Parameters:
121
+ /// - schema: The schema to match a referenceable type for.
122
+ /// - enableUUIDSupport: Indication whether the uuid format should be respected.
113
123
/// - Returns: `true` if the schema is referenceable; `false` otherwise.
114
- static func isReferenceable( _ schema: UnresolvedSchema ? ) -> Bool {
124
+ static func isReferenceable( _ schema: UnresolvedSchema ? , enableUUIDSupport : Bool ) -> Bool {
115
125
guard let schema else {
116
126
// fragment type is referenceable
117
127
return true
@@ -120,7 +130,7 @@ struct TypeMatcher {
120
130
case . a:
121
131
// is a reference
122
132
return true
123
- case let . b( schema) : return isReferenceable ( schema)
133
+ case let . b( schema) : return isReferenceable ( schema, enableUUIDSupport : enableUUIDSupport )
124
134
}
125
135
}
126
136
@@ -131,9 +141,13 @@ struct TypeMatcher {
131
141
///
132
142
/// In other words, a type is inlinable if and only if it is not
133
143
/// referenceable.
134
- /// - Parameter schema: The schema to match a referenceable type for.
144
+ /// - Parameters:
145
+ /// - schema: The schema to match a referenceable type for.
146
+ /// - enableUUIDSupport: Indication whether the uuid format should be respected.
135
147
/// - Returns: `true` if the schema is inlinable; `false` otherwise.
136
- static func isInlinable( _ schema: JSONSchema ) -> Bool { !isReferenceable( schema) }
148
+ static func isInlinable( _ schema: JSONSchema , enableUUIDSupport: Bool ) -> Bool {
149
+ !isReferenceable( schema, enableUUIDSupport: enableUUIDSupport)
150
+ }
137
151
138
152
/// Returns a Boolean value that indicates whether the schema
139
153
/// needs to be defined inline.
@@ -142,9 +156,13 @@ struct TypeMatcher {
142
156
///
143
157
/// In other words, a type is inlinable if and only if it is not
144
158
/// referenceable.
145
- /// - Parameter schema: The schema to match a referenceable type for.
159
+ /// - Parameters:
160
+ /// - schema: The schema to match a referenceable type for.
161
+ /// - enableUUIDSupport: Indication whether the uuid format should be respected.
146
162
/// - Returns: `true` if the schema is inlinable; `false` otherwise.
147
- static func isInlinable( _ schema: UnresolvedSchema ? ) -> Bool { !isReferenceable( schema) }
163
+ static func isInlinable( _ schema: UnresolvedSchema ? , enableUUIDSupport: Bool ) -> Bool {
164
+ !isReferenceable( schema, enableUUIDSupport: enableUUIDSupport)
165
+ }
148
166
149
167
/// Return a reference to a multipart element type if the provided schema is referenceable.
150
168
/// - Parameters:
@@ -283,10 +301,15 @@ struct TypeMatcher {
283
301
/// - Important: Optionality from the `JSONSchema` is not applied, since
284
302
/// this function takes `JSONSchema.Schema`, and optionality is defined
285
303
/// at the `JSONSchema` level.
286
- /// - Parameter schema: The schema to match a referenceable type for.
304
+ /// - Parameters:
305
+ /// - schema: The schema to match a referenceable type for.
306
+ /// - enableUUIDSupport: Indication whether the uuid format should be respected.
287
307
/// - Returns: A type usage for the schema if the schema is built-in.
288
308
/// Otherwise, returns nil.
289
- private static func _tryMatchBuiltinNonRecursive( for schema: JSONSchema . Schema ) -> TypeUsage ? {
309
+ private static func _tryMatchBuiltinNonRecursive(
310
+ for schema: JSONSchema . Schema ,
311
+ enableUUIDSupport: Bool
312
+ ) -> TypeUsage ? {
290
313
let typeName : TypeName
291
314
switch schema {
292
315
case . boolean( _) : typeName = . swift( " Bool " )
@@ -316,7 +339,7 @@ struct TypeMatcher {
316
339
default :
317
340
switch core. format {
318
341
case . dateTime: typeName = . date
319
- case . uuid: typeName = . uuid
342
+ case . uuid where enableUUIDSupport : typeName = . uuid
320
343
default : typeName = . string
321
344
}
322
345
}
0 commit comments