1
1
import Vapor
2
2
3
- fileprivate protocol _OptionalCustomDocumentationNamed {
4
- static var _documentationNameType : Any . Type { get }
5
- }
6
-
7
- extension Optional : _OptionalCustomDocumentationNamed {
8
- static var _documentationNameType : Any . Type {
9
- ( Wrapped . self as? _OptionalCustomDocumentationNamed . Type) ? . _documentationNameType ?? Wrapped . self
10
- }
11
- }
12
-
13
3
public struct DocumentationType : Codable , Equatable , CustomStringConvertible , Sendable {
14
4
public let typeDescription : TypeDescription
15
5
public let customName : String ?
@@ -20,21 +10,10 @@ public struct DocumentationType: Codable, Equatable, CustomStringConvertible, Se
20
10
21
11
public var description : String { defaultName }
22
12
23
- init ( _ type: Any . Type ) {
24
- typeDescription = . init( any: type)
25
- let docNameType = ( type as? _OptionalCustomDocumentationNamed . Type) ? . _documentationNameType ?? type
26
- customName = ( docNameType as? CustomDocumentationNamed . Type) ? . documentationName
27
- }
28
-
29
- init < T> ( _ type: T . Type ) {
30
- typeDescription = . init( type)
31
- let docNameType = ( type as? _OptionalCustomDocumentationNamed . Type) ? . _documentationNameType ?? type
32
- customName = ( docNameType as? CustomDocumentationNamed . Type) ? . documentationName
33
- }
34
-
35
- init < T: CustomDocumentationNamed > ( _ type: T . Type ) {
36
- typeDescription = . init( type)
37
- customName = type. documentationName
13
+ fileprivate init ( parsing type: Any . Type ) {
14
+ let actualType = _leafType ( of: _openOptionals ( in: type) )
15
+ typeDescription = . init( any: actualType)
16
+ customName = ( actualType as? CustomDocumentationNamed . Type) ? . documentationName
38
17
}
39
18
}
40
19
@@ -294,8 +273,8 @@ extension EndpointDocumentation.Object {
294
273
}
295
274
296
275
private init ( documentation: DocumentationObject ) {
297
- let actualType = ( documentation . type as? AnyTypeWrapping . Type ) ? . leafType ?? documentation. type
298
- self . init ( type : DocumentationType ( actualType ) , body: . init( documentation: documentation. body) )
276
+ self . init ( type: DocumentationType ( parsing : documentation. type) ,
277
+ body: . init( documentation: documentation. body) )
299
278
}
300
279
}
301
280
@@ -313,9 +292,9 @@ extension EndpointDocumentation.Object.Body {
313
292
314
293
extension EndpointDocumentation . Object . Body . Field {
315
294
fileprivate init ( name: String , documentation: DocumentationObject ) {
316
- let optionalCleanedType = ( documentation . type as? AnyOptionalType . Type ) ? . anyWrappedType ?? documentation . type
317
- let leafType = ( optionalCleanedType as? AnyTypeWrapping . Type ) ? . leafType ?? optionalCleanedType
318
- self . init ( name : name , type : DocumentationType ( leafType ) , isOptional: documentation. isOptional)
295
+ self . init ( name : name ,
296
+ type : DocumentationType ( parsing : documentation . type ) ,
297
+ isOptional: documentation. isOptional)
319
298
}
320
299
}
321
300
@@ -331,3 +310,11 @@ fileprivate extension RangeReplaceableCollection where Element: Equatable {
331
310
append ( element)
332
311
}
333
312
}
313
+
314
+ fileprivate func _openOptionals( in type: Any . Type ) -> Any . Type {
315
+ ( type as? AnyOptionalType . Type) . map { _openOptionals ( in: $0. anyWrappedType) } ?? type
316
+ }
317
+
318
+ fileprivate func _leafType( of type: Any . Type ) -> Any . Type {
319
+ ( type as? AnyTypeWrapping . Type) ? . leafType ?? type
320
+ }
0 commit comments