Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Better .NET type conversion encapsulation #728

Open
wants to merge 7 commits into
base: main-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,30 @@ private Set<ShapeId> findInitialShapeIdsToConvert() {
.map(unionShape -> unionShape.getId())
.collect(Collectors.toSet());

// Collect map shapes
final Set<ShapeId> mapShapes = model
.getMapShapes()
.stream()
.map(Shape::getId)
.filter(this::isInServiceNamespace)
.collect(Collectors.toSet());

// Collect list shapes
final Set<ShapeId> listShapes = model
.getListShapes()
.stream()
.map(Shape::getId)
.filter(this::isInServiceNamespace)
.collect(Collectors.toSet());

// Collect structure shapes
final Set<ShapeId> structureShapes = model
.getStructureShapes()
.stream()
.map(Shape::getId)
.filter(this::isInServiceNamespace)
.collect(Collectors.toSet());

// TODO add smithy v2 Enums
// Collect enum shapes
final Set<ShapeId> enumShapes = model
Expand All @@ -258,6 +282,9 @@ private Set<ShapeId> findInitialShapeIdsToConvert() {
orderedSet.addAll(unionShapes);
orderedSet.addAll(errorStructures);
orderedSet.addAll(enumShapes);
orderedSet.addAll(mapShapes);
orderedSet.addAll(listShapes);
orderedSet.addAll(structureShapes);
return orderedSet;
}

Expand Down Expand Up @@ -1984,9 +2011,9 @@ protected TypeConverter buildConverterFromMethodBodies(
// This is more controlled than exposing
// the NativeWrapper and the Dafny wrapped type.
final boolean isDependantModuleType =
ModelUtils.isReferenceDependantModuleType(
ModelUtils.isDependantModuleType(
shape,
nameResolver.namespaceForService()
nameResolver.serviceShape.getId().getNamespace()
);

// Make all converters public, because most need to be and it's not worth the trouble to hide the remaining few.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,19 @@ public static Boolean isReferenceDependantModuleType(
final String namespace
) {
if (shape.hasTrait(ReferenceTrait.class)) {
return !namespace.equalsIgnoreCase(shape.getId().getNamespace());
return isDependantModuleType(shape, namespace);
} else {
return false;
}
}

public static Boolean isDependantModuleType(
final Shape shape,
final String namespace
) {
final String shapeNamespace = shape.getId().getNamespace();
if (!shapeNamespace.toLowerCase().startsWith("smithy.api") && !namespace.equalsIgnoreCase(shapeNamespace)) {
return true;
} else {
return false;
}
Expand Down
Loading