@@ -22,7 +22,7 @@ struct OptionTypeSchama {
22
22
var defaultValue : String ?
23
23
}
24
24
25
- struct Object {
25
+ struct Struct {
26
26
var name : String
27
27
/// Properties of the object, preserving the order of declaration
28
28
var properties : [ Property ]
@@ -45,7 +45,7 @@ struct OptionTypeSchama {
45
45
case string
46
46
indirect case array( value: OptionTypeSchama )
47
47
indirect case dictionary( value: OptionTypeSchama )
48
- case object ( Object )
48
+ case `struct` ( Struct )
49
49
case `enum`( Enum )
50
50
}
51
51
@@ -60,37 +60,41 @@ struct OptionTypeSchama {
60
60
/// Accesses the property schema by name
61
61
subscript( _ key: String ) -> OptionTypeSchama ? {
62
62
get {
63
- guard case . object ( let object ) = kind else {
63
+ guard case . struct ( let structInfo ) = kind else {
64
64
return nil
65
65
}
66
- return object . properties. first { $0. name == key } ? . type
66
+ return structInfo . properties. first { $0. name == key } ? . type
67
67
}
68
68
set {
69
- guard case . object ( var object ) = kind else {
69
+ guard case . struct ( var structInfo ) = kind else {
70
70
fatalError ( " Cannot set property on non-object type " )
71
71
}
72
- guard let index = object . properties. firstIndex ( where: { $0. name == key } ) else {
72
+ guard let index = structInfo . properties. firstIndex ( where: { $0. name == key } ) else {
73
73
fatalError ( " Property not found: \( key) " )
74
74
}
75
75
guard let newValue = newValue else {
76
76
fatalError ( " Cannot set property to nil " )
77
77
}
78
- object . properties [ index] . type = newValue
79
- kind = . object ( object )
78
+ structInfo . properties [ index] . type = newValue
79
+ kind = . struct ( structInfo )
80
80
}
81
81
}
82
82
}
83
83
84
84
/// Context for resolving option schema from Swift syntax nodes
85
85
struct OptionSchemaContext {
86
- let typeNameResolver : TypeDeclResolver
86
+ private let typeNameResolver : TypeDeclResolver
87
+
88
+ init ( typeNameResolver: TypeDeclResolver ) {
89
+ self . typeNameResolver = typeNameResolver
90
+ }
87
91
88
92
/// Builds a schema from a type declaration
89
93
func buildSchema( from typeDecl: TypeDeclResolver . TypeDecl ) throws -> OptionTypeSchama {
90
94
switch DeclSyntax ( typeDecl) . as ( DeclSyntaxEnum . self) {
91
95
case . structDecl( let decl) :
92
96
let structInfo = try buildStructProperties ( decl)
93
- return OptionTypeSchama ( kind: . object ( structInfo) )
97
+ return OptionTypeSchama ( kind: . struct ( structInfo) )
94
98
case . enumDecl( let decl) :
95
99
let enumInfo = buildEnumCases ( decl)
96
100
return OptionTypeSchama ( kind: . enum( enumInfo) )
@@ -165,7 +169,7 @@ struct OptionSchemaContext {
165
169
return . init( name: typeName, cases: cases)
166
170
}
167
171
168
- private func buildStructProperties( _ node: StructDeclSyntax ) throws -> OptionTypeSchama . Object {
172
+ private func buildStructProperties( _ node: StructDeclSyntax ) throws -> OptionTypeSchama . Struct {
169
173
var properties : [ OptionTypeSchama . Property ] = [ ]
170
174
for member in node. memberBlock. members {
171
175
// Skip computed properties
0 commit comments