Skip to content

Commit

Permalink
Filter event stream members from IO shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
JordonPhillips committed Dec 20, 2024
1 parent b2735a6 commit 9f2f144
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -242,18 +242,23 @@ private void writeClassDocs(boolean isError) {
}
}

private List<MemberShape> filterMessageMembers(List<MemberShape> members) {
// Only apply this to structures that are errors.
private List<MemberShape> filterPropertyMembers(List<MemberShape> 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.
Expand Down

0 comments on commit 9f2f144

Please sign in to comment.