NeighborVisitor extends ShapeVisitor.Default<List<Relationship>> implements NeighborProvider { @Override public List<Relationship> unionShape(UnionShape shape) { return shape.getAllMembers().values().stream() .map(member -> Relationship.create(shape, RelationshipType.UNION_MEMBER, member)) .collect(Collectors.toList()); } NeighborVisitor(Model model); @Override List<Relationship> getNeighbors(Shape shape); @Override List<Relationship> getDefault(Shape shape); @Override List<Relationship> serviceShape(ServiceShape shape); @Override List<Relationship> resourceShape(ResourceShape shape); @Override List<Relationship> operationShape(OperationShape shape); @Override List<Relationship> memberShape(MemberShape shape); @Override List<Relationship> listShape(ListShape shape); @Override List<Relationship> setShape(SetShape shape); @Override List<Relationship> mapShape(MapShape shape); @Override List<Relationship> structureShape(StructureShape shape); @Override List<Relationship> unionShape(UnionShape shape);  }
@Test public void unionShape() { Shape variant1Shape = StringShape.builder().id("ns.foo#V1String").build(); Shape variant2Shape = StringShape.builder().id("ns.foo#V2String").build(); UnionShape union = UnionShape.builder() .id("ns.foo#name") .addMember(MemberShape.builder() .id("ns.foo#name$tag1") .target(variant1Shape.getId()) .build()) .addMember(MemberShape.builder() .id("ns.foo#name$tag2") .target(variant2Shape.getId()) .build()) .build(); MemberShape v1Target = union.getMember("tag1").get(); MemberShape v2Target = union.getMember("tag2").get(); Model model = Model.builder() .addShape(union) .addShape(variant1Shape) .addShape(variant2Shape) .addShape(v1Target) .addShape(v2Target) .build(); NeighborVisitor neighborVisitor = new NeighborVisitor(model); List<Relationship> relationships = union.accept(neighborVisitor); assertThat(relationships, containsInAnyOrder( Relationship.create(union, RelationshipType.UNION_MEMBER, v1Target), Relationship.create(union, RelationshipType.UNION_MEMBER, v2Target))); }