1313//===----------------------------------------------------------------------===//
1414import  OpenAPIKit
1515
16+ /// Represents a server variable and the function of generation that should be applied.
17+ protocol  ServerVariableGenerator  { 
18+     /// Returns the declaration (enum) that should be added to the server's namespace.
19+     /// If the server variable does not require any codegen then it should return `nil`.
20+     var  declaration :  Declaration ?   {  get  } 
21+ 
22+     /// Returns the description of the parameter that will be used to define the variable
23+     /// in the static method for a given server.
24+     var  parameter :  ParameterDescription  {  get  } 
25+ 
26+     /// Returns an expression for the variable initializer that is used in the body of a server's
27+     /// static method by passing it along to the URL resolver.
28+     var  initializer :  Expression  {  get  } 
29+ 
30+     /// Returns the description of this variables documentation for the function comment of
31+     /// the server's static method.
32+     var  functionComment :  ( name:  String ,  comment:  String ? )  {  get  } 
33+ } 
34+ 
1635extension  TypesFileTranslator  { 
1736    /// Returns a declaration of a namespace (enum) for a specific server and will define
1837    /// one enum member for each of the server's variables in the OpenAPI Document.
@@ -25,16 +44,13 @@ extension TypesFileTranslator {
2544    ///   only `RawStringTranslatedServerVariable` generators will be returned.
2645    /// - Returns: A declaration of the server variables namespace, or `nil` if no
2746    /// variables are declared.
28-     func  translateServerVariables( index:  Int ,  server:  OpenAPI . Server ,  generateAsEnum:  Bool )  ->  [ any  ServerVariableGenerator ]  { 
29-         return  server. variables. map  {  key,  variable in 
47+     func  translateServerVariables( index:  Int ,  server:  OpenAPI . Server ,  generateAsEnum:  Bool ) 
48+         ->  [ any  ServerVariableGenerator ] 
49+     { 
50+         server. variables. map  {  key,  variable in 
3051            guard  generateAsEnum,  let  enumValues =  variable. enum else  { 
31-                 return  RawStringTranslatedServerVariable ( 
32-                     key:  key, 
33-                     variable:  variable, 
34-                     context:  context
35-                 ) 
52+                 return  RawStringTranslatedServerVariable ( key:  key,  variable:  variable,  context:  context) 
3653            } 
37-             
3854            return  GeneratedEnumTranslatedServerVariable ( 
3955                key:  key, 
4056                variable:  variable, 
@@ -46,26 +62,7 @@ extension TypesFileTranslator {
4662    } 
4763
4864    // MARK: Generators
49-     
50-     /// Represents a server variable and the function of generation that should be applied.
51-     protocol  ServerVariableGenerator  { 
52-         /// Returns the declaration (enum) that should be added to the server's namespace.
53-         /// If the server variable does not require any codegen then it should return `nil`.
54-         var  declaration :  Declaration ?   {  get  } 
55- 
56-         /// Returns the description of the parameter that will be used to define the variable
57-         /// in the static method for a given server.
58-         var  parameter :  ParameterDescription  {  get  } 
59- 
60-         /// Returns an expression for the variable initializer that is used in the body of a server's
61-         /// static method by passing it along to the URL resolver.
62-         var  initializer :  Expression  {  get  } 
6365
64-         /// Returns the description of this variables documentation for the function comment of
65-         /// the server's static method.
66-         var  functionComment :  ( name:  String ,  comment:  String ? )  {  get  } 
67-     } 
68-     
6966    /// Represents a variable that is required to be represented as a `Swift.String`.
7067    private  struct  RawStringTranslatedServerVariable :  ServerVariableGenerator  { 
7168        /// The key of the variable defined in the Open API document.
@@ -96,17 +93,13 @@ extension TypesFileTranslator {
9693        var  declaration :  Declaration ?   { 
9794            // A variable being represented by a `Swift.String` does not have a declaration that needs to
9895            // be added to the server's namespace.
99-             return   nil 
96+             nil 
10097        } 
10198
10299        /// Returns the description of the parameter that will be used to define the variable
103100        /// in the static method for a given server.
104101        var  parameter :  ParameterDescription  { 
105-             return  . init( 
106-                 label:  swiftSafeKey, 
107-                 type:  . init( TypeName . string) , 
108-                 defaultValue:  . literal( variable. default) 
109-             ) 
102+             . init( label:  swiftSafeKey,  type:  . init( TypeName . string) ,  defaultValue:  . literal( variable. default) ) 
110103        } 
111104
112105        /// Returns an expression for the variable initializer that is used in the body of a server's
@@ -117,19 +110,16 @@ extension TypesFileTranslator {
117110                . init( label:  " value " ,  expression:  . identifierPattern( swiftSafeKey) ) , 
118111            ] 
119112            if  let  allowedValues =  variable. enum { 
120-                 arguments. append ( . init( 
121-                     label:  " allowedValues " , 
122-                     expression:  . literal( . array( allowedValues. map  {  . literal( $0)  } ) ) 
123-                 ) ) 
113+                 arguments. append ( 
114+                     . init( label:  " allowedValues " ,  expression:  . literal( . array( allowedValues. map  {  . literal( $0)  } ) ) ) 
115+                 ) 
124116            } 
125117            return  . dot( " init " ) . call ( arguments) 
126118        } 
127119
128120        /// Returns the description of this variables documentation for the function comment of
129121        /// the server's static method.
130-         var  functionComment :  ( name:  String ,  comment:  String ? )  { 
131-             ( name:  swiftSafeKey,  comment:  variable. description) 
132-         } 
122+         var  functionComment :  ( name:  String ,  comment:  String ? )  {  ( name:  swiftSafeKey,  comment:  variable. description)  } 
133123    } 
134124
135125    /// Represents an Open API "Server Variable Object" that will be generated as an enum and added
@@ -166,30 +156,33 @@ extension TypesFileTranslator {
166156        ///   - accessModifier: The access modifier to use for generated declarations.
167157        ///   - context: The translator context the generator should use to create
168158        ///   Swift safe identifiers.
169-         init ( key:  String ,  variable:  OpenAPI . Server . Variable ,  enumValues:  [ String ] ,  accessModifier:  AccessModifier ,  context:  TranslatorContext )  { 
159+         init ( 
160+             key:  String , 
161+             variable:  OpenAPI . Server . Variable , 
162+             enumValues:  [ String ] , 
163+             accessModifier:  AccessModifier , 
164+             context:  TranslatorContext 
165+         )  { 
170166            self . key =  key
171167            swiftSafeKey =  context. asSwiftSafeName ( key) 
172168            enumName =  context. asSwiftSafeName ( key. localizedCapitalized) 
173169            self . variable =  variable
174170            self . enumValues =  enumValues
175-             
176171            self . context =  context
177172            self . accessModifier =  accessModifier
178173        } 
179174
180175        /// Returns the declaration (enum) that should be added to the server's namespace.
181176        /// If the server variable does not require any codegen then it should return `nil`.
182177        var  declaration :  Declaration ?   { 
183-             let  description :  String  =  if  let  description =  variable. description { 
184-                 description +  " \n \n " 
185-             }  else  { 
186-                 " " 
187-             } 
178+             let  description :  String  =  if  let  description =  variable. description {  description +  " \n \n "  }  else  {  " "  } 
188179
189180            return  . commentable( 
190-                 . doc( """ 
191-                  \( description) The  " \( key) "  variable defined in the OpenAPI document. The default value is  " \( variable. default) " . 
192-                  """ ) , 
181+                 . doc( 
182+                     """ 
183+                      \( description) The  " \( key) "  variable defined in the OpenAPI document. The default value is  " \( variable. default) " . 
184+                      """ 
185+                 ) , 
193186                . enum( 
194187                    isFrozen:  true , 
195188                    accessModifier:  accessModifier, 
@@ -203,7 +196,7 @@ extension TypesFileTranslator {
203196        /// Returns the description of the parameter that will be used to define the variable
204197        /// in the static method for a given server.
205198        var  parameter :  ParameterDescription  { 
206-             return   . init( 
199+             . init( 
207200                label:  swiftSafeKey, 
208201                type:  . member( [ enumName] ) , 
209202                defaultValue:  . memberAccess( . dot( context. asSwiftSafeName ( variable. default) ) ) 
@@ -213,22 +206,19 @@ extension TypesFileTranslator {
213206        /// Returns an expression for the variable initializer that is used in the body of a server's
214207        /// static method by passing it along to the URL resolver.
215208        var  initializer :  Expression  { 
216-             . dot( " init " ) . call ( 
217-                 [ 
209+             . dot( " init " ) 
210+                 . call ( [ 
218211                    . init( label:  " name " ,  expression:  . literal( key) ) , 
219-                     . init( label:  " value " ,  expression:  . memberAccess( . init( 
220-                         left:  . identifierPattern( swiftSafeKey) , 
221-                         right:  " rawValue " 
222-                     ) ) ) , 
223-                 ] 
224-             ) 
212+                     . init( 
213+                         label:  " value " , 
214+                         expression:  . memberAccess( . init( left:  . identifierPattern( swiftSafeKey) ,  right:  " rawValue " ) ) 
215+                     ) , 
216+                 ] ) 
225217        } 
226218
227219        /// Returns the description of this variables documentation for the function comment of
228220        /// the server's static method.
229-         var  functionComment :  ( name:  String ,  comment:  String ? )  { 
230-             ( name:  swiftSafeKey,  comment:  variable. description) 
231-         } 
221+         var  functionComment :  ( name:  String ,  comment:  String ? )  {  ( name:  swiftSafeKey,  comment:  variable. description)  } 
232222
233223        /// Returns an enum case declaration for a raw string enum.
234224        ///
0 commit comments