From 9f2f1448e10922f641087f9a5259c58bee5c0a20 Mon Sep 17 00:00:00 2001 From: JordonPhillips Date: Fri, 20 Dec 2024 18:32:03 +0100 Subject: [PATCH] Filter event stream members from IO shapes --- .../smithy/python/codegen/StructureGenerator.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java b/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java index 29714b1f..ddcd0d37 100644 --- a/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java +++ b/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java @@ -85,8 +85,8 @@ final class StructureGenerator implements Runnable { required.add(member); } } - this.requiredMembers = filterMessageMembers(required); - this.optionalMembers = filterMessageMembers(optional); + this.requiredMembers = filterPropertyMembers(required); + this.optionalMembers = filterPropertyMembers(optional); this.recursiveShapes = recursiveShapes; } @@ -242,18 +242,23 @@ private void writeClassDocs(boolean isError) { } } - private List filterMessageMembers(List members) { - // Only apply this to structures that are errors. + private List filterPropertyMembers(List members) { if (!shape.hasTrait(ErrorTrait.class)) { - return members; + return members.stream().filter(this::filterEventStreamMember).toList(); } // We replace modeled message members with a static `message` member. Serialization // and deserialization will handle assigning them properly. return members.stream() .filter(member -> !isErrorMessage(model, member)) + .filter(this::filterEventStreamMember) .collect(Collectors.toList()); } + private boolean filterEventStreamMember(MemberShape member) { + var target = model.expectShape(member.getTarget()); + return !(target.isUnionShape() && target.hasTrait(StreamingTrait.class)); + } + private String getDefaultValue(PythonWriter writer, MemberShape member) { // The default value is defined in the model is a exposed as generic // json, so we need to convert it to the proper type based on the target.