File tree Expand file tree Collapse file tree
Sources/SotoCodeGeneratorLib Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -320,14 +320,23 @@ struct AwsService {
320320
321321 /// get service protocol from service
322322 static func getServiceProtocol( _ service: ServiceShape ) throws -> AwsServiceProtocol {
323- if let traits = service. traits {
324- for trait in traits {
325- if let protocolTrait = trait as? AwsServiceProtocol {
326- return protocolTrait
327- }
328- }
323+ guard let traits = service. traits else {
324+ throw Error ( reason: " No service protocol trait " )
325+ }
326+ let serviceTraits = traits. compactMap { $0 as? AwsServiceProtocol }
327+ // prefer JSON protocols over other
328+ if let restJson1 = serviceTraits. first ( where: { $0 is AwsProtocolsRestJson1Trait } ) {
329+ return restJson1
330+ } else if let json1_1 = serviceTraits. first ( where: { $0 is AwsProtocolsAwsJson1_1Trait } ) {
331+ return json1_1
332+ } else if let json1_0 = serviceTraits. first ( where: { $0 is AwsProtocolsAwsJson1_0Trait } ) {
333+ return json1_0
329334 }
330- throw Error ( reason: " No service protocol trait " )
335+ guard let trait = serviceTraits. first else {
336+ throw Error ( reason: " No service protocol trait " )
337+ }
338+ return trait
339+
331340 }
332341
333342 /// Get list operations service uses. Slightly more complex than just asking for all the operation shapes in the fle. Instead to do
You can’t perform that action at this time.
0 commit comments