Support service renames
This commit is contained in:
parent
6c916f0f99
commit
e50ba97bb7
|
@ -164,9 +164,18 @@ public final class FlattenNamespaces extends ConfigurableProjectionTransformer<F
|
|||
return shapeWalker.walkShapes(service).stream()
|
||||
.filter(FunctionalUtils.not(Prelude::isPreludeShape))
|
||||
.map(shape -> Pair.of(shape.getId(), updateNamespace(shape.getId(), config.getNamespace())))
|
||||
.map(pair -> applyServiceRenames(pair, service))
|
||||
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
|
||||
}
|
||||
|
||||
private Pair<ShapeId, ShapeId> applyServiceRenames(Pair<ShapeId, ShapeId> pair, ServiceShape service) {
|
||||
if (!service.getRename().containsKey(pair.getLeft())) {
|
||||
return pair;
|
||||
}
|
||||
ShapeId newId = ShapeId.fromParts(pair.getRight().getNamespace(), service.getRename().get(pair.getLeft()));
|
||||
return Pair.of(pair.getLeft(), newId);
|
||||
}
|
||||
|
||||
private Set<ShapeId> getTaggedShapesToInclude(Set<String> tags, Model model) {
|
||||
return model.shapes()
|
||||
.filter(FunctionalUtils.not(Prelude::isPreludeShape))
|
||||
|
|
|
@ -116,6 +116,33 @@ public class FlattenNamespacesTest {
|
|||
"ns.baz#MyOperationOutput$foo", "ns.qux#UnconnectedFromService")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsRenamesOnService() throws Exception {
|
||||
Model model = Model.assembler()
|
||||
.addImport(Paths.get(getClass().getResource("flatten-namespaces-with-renames.json").toURI()))
|
||||
.assemble()
|
||||
.unwrap();
|
||||
ObjectNode config = Node.objectNode()
|
||||
.withMember("namespace", Node.from("ns.qux"))
|
||||
.withMember("service", Node.from("ns.foo#MyService"));
|
||||
TransformContext context = TransformContext.builder()
|
||||
.model(model)
|
||||
.settings(config)
|
||||
.build();
|
||||
Model result = new FlattenNamespaces().transform(context);
|
||||
List<String> ids = result.shapes()
|
||||
.filter(FunctionalUtils.not(Prelude::isPreludeShape))
|
||||
.map(Shape::getId)
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(ids, containsInAnyOrder("ns.qux#MyService", "ns.qux#GetSomething", "ns.qux#GetSomethingOutput",
|
||||
"ns.qux#GetSomethingOutput$widget1", "ns.qux#GetSomethingOutput$fooWidget", "ns.qux#Widget",
|
||||
"ns.qux#FooWidget"));
|
||||
assertThat(ids, not(containsInAnyOrder("ns.foo#MyService", "ns.foo#GetSomething", "ns.foo#GetSomethingOutput",
|
||||
"ns.bar#Widget", "foo.example#Widget")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void throwsWhenServiceIsNotConfigured() {
|
||||
Model model = Model.assembler()
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"smithy": "1.0",
|
||||
"shapes": {
|
||||
"ns.foo#MyService": {
|
||||
"type": "service",
|
||||
"version": "2017-02-11",
|
||||
"operations": [
|
||||
{
|
||||
"target": "ns.foo#GetSomething"
|
||||
}
|
||||
],
|
||||
"rename": {
|
||||
"foo.example#Widget": "FooWidget"
|
||||
}
|
||||
},
|
||||
"ns.foo#GetSomething": {
|
||||
"type": "operation",
|
||||
"output": {
|
||||
"target": "ns.foo#GetSomethingOutput"
|
||||
}
|
||||
},
|
||||
"ns.foo#GetSomethingOutput": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"widget1": {
|
||||
"target": "ns.bar#Widget"
|
||||
},
|
||||
"fooWidget": {
|
||||
"target": "foo.example#Widget"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ns.bar#Widget": {
|
||||
"type": "structure"
|
||||
},
|
||||
"foo.example#Widget": {
|
||||
"type": "structure"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue