From a61bf716fcab229b36e88ba6add46e8bcdd71c7c Mon Sep 17 00:00:00 2001 From: George Fu Date: Mon, 15 Apr 2024 12:18:21 -0400 Subject: [PATCH] fix(codegen): add doc trait conditionally (#6002) --- .../smithy/aws/typescript/codegen/AddS3Config.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3Config.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3Config.java index 478d972ca11f..857159effa70 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3Config.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3Config.java @@ -23,6 +23,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.function.Consumer; import java.util.logging.Logger; @@ -158,7 +159,11 @@ public Model preprocessModel(Model model, TypeScriptSettings settings) { String memberName = entry.getKey(); MemberShape memberShape = entry.getValue(); - if (memberShape.getTarget().equals(expiresShape.getId())) { + Optional httpHeader = memberShape.getTrait(HttpHeaderTrait.class); + Optional doc = memberShape.getTrait(DocumentationTrait.class); + + if (memberShape.getTarget().equals(expiresShape.getId()) + && httpHeader.isPresent()) { structureShapeBuilder .removeMember(memberName) .addMember( @@ -167,7 +172,7 @@ public Model preprocessModel(Model model, TypeScriptSettings settings) { (m) -> { m .addTrait(new DocumentationTrait("Deprecated in favor of ExpiresString.")) - .addTrait(memberShape.getTrait(HttpHeaderTrait.class).get()) + .addTrait(httpHeader.get()) .addTrait(DeprecatedTrait.builder().build()); } ) @@ -175,9 +180,8 @@ public Model preprocessModel(Model model, TypeScriptSettings settings) { "ExpiresString", expiresStringShape.getId(), (m) -> { - m - .addTrait(memberShape.getTrait(DocumentationTrait.class).get()) - .addTrait(new HttpHeaderTrait("ExpiresString")); + m.addTrait(new HttpHeaderTrait("ExpiresString")); + doc.ifPresent(m::addTrait); } ); } else {