|
1 | 1 | package com.dwolla.config.smithy
|
2 | 2 |
|
3 |
| -import cats.syntax.all.* |
| 3 | +import software.amazon.smithy.build.transforms.FlattenNamespaces |
4 | 4 | import software.amazon.smithy.build.{ProjectionTransformer, TransformContext}
|
5 | 5 | import software.amazon.smithy.model.Model
|
6 |
| -import software.amazon.smithy.model.shapes.Shape |
7 |
| - |
8 |
| -import java.util.stream.Collectors |
9 |
| -import scala.collection.JavaConverters.* |
| 6 | +import software.amazon.smithy.model.node.ObjectNode |
10 | 7 |
|
11 | 8 | class ShadeNamespace extends ProjectionTransformer {
|
12 | 9 | override def getName: String = "com.dwolla.config.smithy.ShadeNamespace"
|
13 | 10 |
|
14 |
| - private val namespacesToRename: Set[String] = Set("com.amazonaws.kms") |
15 |
| - |
16 |
| - override def transform(context: TransformContext): Model = { |
17 |
| - val renames = |
18 |
| - context.getModel |
19 |
| - .shapes().collect(Collectors.toList[Shape]).asScala.toList |
20 |
| - .map(_.getId) |
21 |
| - .filter(id => namespacesToRename.contains(id.getNamespace)) |
22 |
| - .fproduct(id => id.withNamespace(s"com.dwolla.config.smithy_shaded.${id.getNamespace}")) |
23 |
| - .toMap.asJava |
| 11 | + val sourceService: String = "TrentService" |
| 12 | + val sourceNamespace: String = "com.amazonaws.kms" |
| 13 | + val targetNamespacePrefix: String = "com.dwolla.config.smithy_shaded" |
24 | 14 |
|
25 |
| - context.getTransformer.renameShapes(context.getModel, renames) |
26 |
| - } |
| 15 | + override def transform(context: TransformContext): Model = |
| 16 | + new FlattenNamespaces().transform { |
| 17 | + context |
| 18 | + .toBuilder |
| 19 | + .projectionName(getName) |
| 20 | + .settings { |
| 21 | + ObjectNode.builder() |
| 22 | + .withMember("namespace", s"$targetNamespacePrefix.$sourceNamespace") |
| 23 | + .withMember("service", s"$sourceNamespace#$sourceService") |
| 24 | + .build() |
| 25 | + } |
| 26 | + .build() |
| 27 | + } |
27 | 28 | }
|
0 commit comments