Skip to content

Commit

Permalink
chore(codegen): wip AddCompressionDependency
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Dec 29, 2023
1 parent 6d740b7 commit cdd543e
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, Consumer<TypeScriptWriter>> 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<OperationShape> operations = topDownIndex.getContainedOperations(service);
for (OperationShape operation : operations) {
if (hasRequestCompressionTrait(operation)) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cdd543e

Please sign in to comment.