@@ -35,6 +35,16 @@ public struct APIRequestTestSwiftGen: SwiftGenerator {
3535 . filter { !$0. context. inQuery } // for now these are handled as a block rather than each as separate args
3636 . map ( APIRequestTestSwiftGen . argument)
3737
38+ let undefinedPaarameterArgNames = Array (
39+ pathComponents. components
40+ . compactMap ( Self . urlParameterSwiftName)
41+ . filter { !parameterArgs. lazy. map ( \. name) . contains ( $0) }
42+ )
43+
44+ if !undefinedPaarameterArgNames. isEmpty {
45+ throw Error . pathParametersNotDefined ( names: undefinedPaarameterArgNames)
46+ }
47+
3848 let requestBodyTypeDef = SwiftTypeDef ( name: " RequestBody " , specializationReps: [ ] )
3949 let responseBodyTypeDef = SwiftTypeDef ( name: " ResponseBody " , specializationReps: [ ] )
4050
@@ -169,12 +179,11 @@ public struct APIRequestTestSwiftGen: SwiftGenerator {
169179 originatingAt hostUrl: URL
170180 ) -> Decl {
171181 let pathString = path. components. map { component in
172- guard component. first == " { " ,
173- component. last == " } " else {
174- return component
182+ guard let swiftName = urlParameterSwiftName ( component) else {
183+ return component
175184 }
176185 return " \\ ( "
177- + propertyCased ( String ( component . dropFirst ( ) . dropLast ( ) ) )
186+ + swiftName
178187 + " ) "
179188 } . joined ( separator: " / " )
180189
@@ -185,6 +194,18 @@ public struct APIRequestTestSwiftGen: SwiftGenerator {
185194 )
186195 }
187196
197+ /// Get a property-cased name if the given string is an OpenAPI path parameter variable
198+ /// (which means it is enclosed in brackets `{ }`). Otherwise, returns `nil`.
199+ static func urlParameterSwiftName(
200+ _ pathComponent: String
201+ ) -> String ? {
202+ guard pathComponent. first == " { " ,
203+ pathComponent. last == " } " else {
204+ return nil
205+ }
206+ return propertyCased ( String ( pathComponent. dropFirst ( ) . dropLast ( ) ) )
207+ }
208+
188209 private static func parameterSnippet( from parameter: DereferencedParameter ) throws -> Decl {
189210 let ( parameterName, parameterType) = try argument ( for: parameter)
190211
@@ -226,6 +247,8 @@ public struct APIRequestTestSwiftGen: SwiftGenerator {
226247 case parameterContentMapNotSupported
227248 case unsupportedParameterSchema
228249
250+ case pathParametersNotDefined( names: [ String ] )
251+
229252 case duplicateFunctionArgumentDetected
230253 }
231254}
0 commit comments