-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(codegen): wip AddCompressionDependency
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...src/main/java/software/amazon/smithy/aws/typescript/codegen/AddCompressionDependency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters