From 72faecc74d67ed8ce0e87f8d4da62ed2aa825d36 Mon Sep 17 00:00:00 2001 From: George Fu Date: Tue, 8 Oct 2024 16:09:09 -0400 Subject: [PATCH] fix: add uuid types when adding uuid (#1428) --- .../smithy/typescript/codegen/TypeScriptDependency.java | 1 + .../codegen/integration/HttpBindingProtocolGenerator.java | 5 ++++- .../codegen/protocols/cbor/CborShapeSerVisitor.java | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDependency.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDependency.java index 0faaff2c523..56f92b9d615 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDependency.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDependency.java @@ -79,6 +79,7 @@ public enum TypeScriptDependency implements Dependency { NODE_CONFIG_PROVIDER("dependencies", "@smithy/node-config-provider", false), + UUID_TYPES("dependencies", "@types/uuid", "^9.0.1", false), UUID("dependencies", "uuid", "^9.0.1", false), // Conditionally added when httpChecksumRequired trait exists diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java index 1bb7046af31..fab8e968606 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java @@ -881,7 +881,9 @@ private void writeRequestQueryParam( boolean isIdempotencyToken = binding.getMember().hasTrait(IdempotencyTokenTrait.class); if (isIdempotencyToken) { - writer.addImport("v4", "generateIdempotencyToken", TypeScriptDependency.UUID); + writer + .addDependency(TypeScriptDependency.UUID_TYPES) + .addImport("v4", "generateIdempotencyToken", TypeScriptDependency.UUID); } boolean isRequired = binding.getMember().isRequired(); String idempotencyComponent = (isIdempotencyToken && !isRequired) ? " ?? generateIdempotencyToken()" : ""; @@ -1013,6 +1015,7 @@ private void writeNormalHeader(GenerationContext context, HttpBinding binding) { boolean isIdempotencyToken = binding.getMember().hasTrait(IdempotencyTokenTrait.class); if (isIdempotencyToken) { context.getWriter() + .addDependency(TypeScriptDependency.UUID_TYPES) .addImport("v4", "generateIdempotencyToken", TypeScriptDependency.UUID); } diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/protocols/cbor/CborShapeSerVisitor.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/protocols/cbor/CborShapeSerVisitor.java index 2de9043276f..da550596be8 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/protocols/cbor/CborShapeSerVisitor.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/protocols/cbor/CborShapeSerVisitor.java @@ -127,7 +127,9 @@ protected void serializeStructure(ProtocolGenerator.GenerationContext context, S boolean isUnaryCall = UnaryFunctionCall.check(valueExpression); if (memberShape.hasTrait(IdempotencyTokenTrait.class)) { - writer.addImport("v4", "generateIdempotencyToken", TypeScriptDependency.UUID); + writer + .addDependency(TypeScriptDependency.UUID_TYPES) + .addImport("v4", "generateIdempotencyToken", TypeScriptDependency.UUID); writer.write("'$L': [true, _ => _ ?? generateIdempotencyToken()],", memberName); } else {