diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddCompressionDependency.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddCompressionDependency.java new file mode 100644 index 000000000000..346134fe8bb5 --- /dev/null +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddCompressionDependency.java @@ -0,0 +1,88 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.smithy.aws.typescript.codegen; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Consumer; +import java.util.logging.Logger; + +import software.amazon.smithy.aws.traits.ServiceTrait; +import software.amazon.smithy.aws.typescript.codegen.extensions.AwsRegionExtensionConfiguration; +import software.amazon.smithy.codegen.core.SymbolProvider; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.knowledge.TopDownIndex; +import software.amazon.smithy.model.shapes.OperationShape; +import software.amazon.smithy.model.shapes.ServiceShape; +import software.amazon.smithy.model.traits.RequestCompressionTrait; +import software.amazon.smithy.typescript.codegen.LanguageTarget; +import software.amazon.smithy.typescript.codegen.TypeScriptDependency; +import software.amazon.smithy.typescript.codegen.TypeScriptSettings; +import software.amazon.smithy.typescript.codegen.TypeScriptWriter; +import software.amazon.smithy.typescript.codegen.extensions.ExtensionConfigurationInterface; +import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; +import software.amazon.smithy.utils.MapUtils; +import software.amazon.smithy.utils.SmithyInternalApi; + +/** + * Adds compression dependencies if needed. + */ +@SmithyInternalApi +public final class AddCompressionDependency implements TypeScriptIntegration { + + private static final Logger LOGGER = Logger.getLogger(AddAwsRuntimeConfig.class.getName()); + + @Override + public Map> getRuntimeConfigWriters( + TypeScriptSettings settings, + Model model, + SymbolProvider symbolProvider, + LanguageTarget target + ) { + if (!hasRequestCompressionTrait(model, settings.getService(model))) { + return Collections.emptyMap(); + } + + switch (target) { + case NODE: + + default: + return Collections.emptyMap(); + } + } + + // return true if operation shape is decorated with `httpChecksum` trait. + private static boolean hasRequestCompressionTrait(OperationShape operation) { + return operation.hasTrait(RequestCompressionTrait.class); + } + + private static boolean hasRequestCompressionTrait( + Model model, + ServiceShape service + ) { + TopDownIndex topDownIndex = TopDownIndex.of(model); + Set operations = topDownIndex.getContainedOperations(service); + for (OperationShape operation : operations) { + if (hasRequestCompressionTrait(operation)) { + return true; + } + } + return false; + } +} diff --git a/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration b/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration index 698cd2777c67..5caff9b93bb7 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration +++ b/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration @@ -30,3 +30,4 @@ software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AwsSdkCustom software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AddAwsDefaultSigningName software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AddSTSAuthCustomizations software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AwsSdkCustomizeEndpointRuleSetHttpAuthSchemeProvider +software.amazon.smithy.aws.typescript.codegen.AddCompressionDependency