Skip to content

Commit

Permalink
Add patch for SQS arrays in result shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Dec 4, 2023
1 parent a8e59b6 commit 1c8d39b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Sources/SotoCodeGeneratorLib/AwsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: ".")
Expand Down
8 changes: 8 additions & 0 deletions Sources/SotoCodeGeneratorLib/Model+Patch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 1c8d39b

Please sign in to comment.