From 1c8d39bfc4b3affa7efd60b78f3d0227faa7d8c1 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Mon, 4 Dec 2023 17:15:38 +0000 Subject: [PATCH] Add patch for SQS arrays in result shapes --- Sources/SotoCodeGeneratorLib/AwsService.swift | 20 +++++++++++++++++++ .../SotoCodeGeneratorLib/Model+Patch.swift | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/Sources/SotoCodeGeneratorLib/AwsService.swift b/Sources/SotoCodeGeneratorLib/AwsService.swift index 3879c08..27bfbd4 100644 --- a/Sources/SotoCodeGeneratorLib/AwsService.swift +++ b/Sources/SotoCodeGeneratorLib/AwsService.swift @@ -450,6 +450,26 @@ struct AwsService { } } + /// The JSON decoder requires an array to exist, even if it is empty so we have to make + /// all arrays in output shapes optional + func removeRequiredTraitFromOutputCollections(_ model: Model) { + guard self.serviceProtocolTrait is AwsProtocolsAwsJson1_0Trait || + self.serviceProtocolTrait is AwsProtocolsAwsJson1_1Trait || + self.serviceProtocolTrait is AwsProtocolsRestJson1Trait else { return } + + for shape in model.shapes { + guard shape.value.hasTrait(type: SotoOutputShapeTrait.self) else { continue } + guard let structure = shape.value as? StructureShape else { continue } + guard let members = structure.members else { continue } + for member in members.values { + let shape = model.shape(for: member.target) + if shape is ListShape || shape is SetShape || shape is MapShape { + member.remove(trait: RequiredTrait.self) + } + } + } + } + /// convert paginator token to KeyPath func toKeyPath(token: String, structure: StructureShape) -> String { var split = token.split(separator: ".") diff --git a/Sources/SotoCodeGeneratorLib/Model+Patch.swift b/Sources/SotoCodeGeneratorLib/Model+Patch.swift index 56fde36..4517a11 100644 --- a/Sources/SotoCodeGeneratorLib/Model+Patch.swift +++ b/Sources/SotoCodeGeneratorLib/Model+Patch.swift @@ -148,6 +148,14 @@ extension Model { AddTraitPatch(trait: SotoExtensibleEnumTrait()), ]), ], + "SQS": [ + "com.amazonaws.sqs#ChangeMessageVisibilityBatchResult$Successful": RemoveTraitPatch(trait: RequiredTrait.self), + "com.amazonaws.sqs#ChangeMessageVisibilityBatchResult$Failed": RemoveTraitPatch(trait: RequiredTrait.self), + "com.amazonaws.sqs#DeleteMessageBatchResult$Successful": RemoveTraitPatch(trait: RequiredTrait.self), + "com.amazonaws.sqs#DeleteMessageBatchResult$Failed": RemoveTraitPatch(trait: RequiredTrait.self), + "com.amazonaws.sqs#SendMessageBatchResult$Successful": RemoveTraitPatch(trait: RequiredTrait.self), + "com.amazonaws.sqs#SendMessageBatchResult$Failed": RemoveTraitPatch(trait: RequiredTrait.self), + ], "SageMaker": [ // pagination tokens in response shouldnt be required "com.amazonaws.sagemaker#ListFeatureGroupsResponse$NextToken": RemoveTraitPatch(trait: RequiredTrait.self),