Skip to content

Commit cd47bde

Browse files
committed
use FlattenNamespaces instead of hacking our own via renameShapes
1 parent a4220bc commit cd47bde

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
package com.dwolla.config.smithy
22

3-
import cats.syntax.all.*
3+
import software.amazon.smithy.build.transforms.FlattenNamespaces
44
import software.amazon.smithy.build.{ProjectionTransformer, TransformContext}
55
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
107

118
class ShadeNamespace extends ProjectionTransformer {
129
override def getName: String = "com.dwolla.config.smithy.ShadeNamespace"
1310

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"
2414

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+
}
2728
}

0 commit comments

Comments
 (0)