@@ -24,15 +24,15 @@ extension TypesFileTranslator {
2424 /// - Returns: A declaration of the server variables namespace, or `nil` if no
2525 /// variables are declared.
2626 func translateServerVariables( index: Int , server: OpenAPI . Server , generateAsEnum: Bool ) -> [ any ServerVariableGenerator ] {
27- return server. variables. map { ( key, variable) in
27+ return server. variables. map { key, variable in
2828 guard generateAsEnum, let enumValues = variable. enum else {
2929 return RawStringTranslatedServerVariable (
3030 key: key,
3131 variable: variable,
3232 context: context
3333 )
3434 }
35-
35+
3636 return GeneratedEnumTranslatedServerVariable (
3737 key: key,
3838 variable: variable,
@@ -47,9 +47,8 @@ extension TypesFileTranslator {
4747
4848 /// Represents a server variable and the function of generation that should be applied.
4949 protocol ServerVariableGenerator {
50- /// Returns the declaration (enum) that should be added to the `Variables.Server#`
51- /// namespace. If the server variable does not require any codegen then it should
52- /// return `nil`.
50+ /// Returns the declaration (enum) that should be added to the server's namespace.
51+ /// If the server variable does not require any codegen then it should return `nil`.
5352 var declaration : Declaration ? { get }
5453
5554 /// Returns the description of the parameter that will be used to define the variable
@@ -64,22 +63,39 @@ extension TypesFileTranslator {
6463 /// the server's static method.
6564 var functionComment : ( name: String , comment: String ? ) { get }
6665 }
67-
66+
6867 /// Represents a variable that is required to be represented as a `Swift.String`.
6968 private struct RawStringTranslatedServerVariable : ServerVariableGenerator {
69+ /// The key of the variable defined in the Open API document.
7070 let key : String
71+
72+ /// The ``key`` after being santized for use as an identifier.
7173 let swiftSafeKey : String
74+
75+ /// The server variable information.
7276 let variable : OpenAPI . Server . Variable
7377
78+ /// Create a generator for an Open API "Server Variable Object" that is represented
79+ /// by a `Swift.String` in the generated output.
80+ ///
81+ /// - Parameters:
82+ /// - key: The key of the variable defined in the Open API document.
83+ /// - variable: The server variable information.
84+ /// - context: The translator context the generator should use to create
85+ /// Swift safe identifiers.
7486 init ( key: String , variable: OpenAPI . Server . Variable , context: TranslatorContext ) {
7587 self . key = key
7688 swiftSafeKey = context. asSwiftSafeName ( key)
7789 self . variable = variable
7890 }
7991
80- /// A variable being represented by a `Swift.String` does not have a declaration that needs to
81- /// be added to the `Variables.Server#` namespace.
82- var declaration : Declaration ? { nil }
92+ /// Returns the declaration (enum) that should be added to the server's namespace.
93+ /// If the server variable does not require any codegen then it should return `nil`.
94+ var declaration : Declaration ? {
95+ // A variable being represented by a `Swift.String` does not have a declaration that needs to
96+ // be added to the server's namespace.
97+ return nil
98+ }
8399
84100 /// Returns the description of the parameter that will be used to define the variable
85101 /// in the static method for a given server.
@@ -114,32 +130,53 @@ extension TypesFileTranslator {
114130 }
115131 }
116132
117- /// Represents a variable that will be generated as an enum and added to the `Variables.Server#`
118- /// namespace. The enum will contain a `default` static case which returns the default defined in
119- /// the OpenAPI Document.
133+ /// Represents an Open API "Server Variable Object" that will be generated as an enum and added
134+ /// to the server's namespace.
120135 private struct GeneratedEnumTranslatedServerVariable : ServerVariableGenerator {
136+ /// The key of the variable defined in the Open API document.
121137 let key : String
138+
139+ /// The ``key`` after being santized for use as an identifier.
122140 let swiftSafeKey : String
141+
142+ /// The ``key`` after being santized for use as the enum identifier.
123143 let enumName : String
144+
145+ /// The server variable information.
124146 let variable : OpenAPI . Server . Variable
147+
148+ /// The 'enum' values of the variable as defined in the Open API document.
125149 let enumValues : [ String ]
126150
151+ /// The access modifier to use for generated declarations.
127152 let accessModifier : AccessModifier
153+
154+ /// The translator context the generator should use to create Swift safe identifiers.
128155 let context : TranslatorContext
129156
157+ /// Create a generator for an Open API "Server Variable Object" that is represented
158+ /// by an enumeration in the generated output.
159+ ///
160+ /// - Parameters:
161+ /// - key: The key of the variable defined in the Open API document.
162+ /// - variable: The server variable information.
163+ /// - enumValues: The 'enum' values of the variable as defined in the Open API document.
164+ /// - accessModifier: The access modifier to use for generated declarations.
165+ /// - context: The translator context the generator should use to create
166+ /// Swift safe identifiers.
130167 init ( key: String , variable: OpenAPI . Server . Variable , enumValues: [ String ] , accessModifier: AccessModifier , context: TranslatorContext ) {
131168 self . key = key
132169 swiftSafeKey = context. asSwiftSafeName ( key)
133170 enumName = context. asSwiftSafeName ( key. localizedCapitalized)
134171 self . variable = variable
135172 self . enumValues = enumValues
136-
173+
137174 self . context = context
138175 self . accessModifier = accessModifier
139176 }
140177
141- /// Returns the declaration (enum) that should be added to the `Variables.Server#`
142- /// namespace .
178+ /// Returns the declaration (enum) that should be added to the server's namespace.
179+ /// If the server variable does not require any codegen then it should return `nil` .
143180 var declaration : Declaration ? {
144181 let description : String = if let description = variable. description {
145182 description + " \n \n "
@@ -204,11 +241,7 @@ extension TypesFileTranslator {
204241 /// - Returns: A declaration of an enum case.
205242 private func translateVariableCase( _ name: String ) -> Declaration {
206243 let caseName = context. asSwiftSafeName ( name)
207- if caseName == name {
208- return . enumCase( name: caseName, kind: . nameOnly)
209- } else {
210- return . enumCase( name: caseName, kind: . nameWithRawValue( . string( name) ) )
211- }
244+ return . enumCase( name: caseName, kind: caseName == name ? . nameOnly : . nameWithRawValue( . string( name) ) )
212245 }
213246 }
214247}
0 commit comments