Skip to content

Commit

Permalink
auto commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rishav-karanjit committed Jan 17, 2025
1 parent 07f9ba6 commit 5d56ad9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,7 @@ public void generateOrphanShapeSerializer(
final Set<ShapeId> alreadyVisited,
ServiceShape serviceShape
) {
if (alreadyVisited.contains(shape.toShapeId())) {
return;
}
// We don't need type conversion for operation shape and resource shape
if (shape.isOperationShape() || shape.isResourceShape()) {
if (GoCodegenUtils.shapeShouldHaveConversionFunction(shape) == false || alreadyVisited.contains(shape.toShapeId())) {
return;
}
if (shape.hasTrait(UnitTypeTrait.class)) {
Expand Down Expand Up @@ -952,10 +948,7 @@ public void generateOrphanShapeDeserializer(
final Set<ShapeId> alreadyVisited,
ServiceShape serviceShape
) {
if (alreadyVisited.contains(shape.toShapeId())) {
return;
}
if (shape.isOperationShape() || shape.isResourceShape()) {
if (GoCodegenUtils.shapeShouldHaveConversionFunction(shape) == false || alreadyVisited.contains(shape.toShapeId())) {
return;
}
if (shape.hasTrait(UnitTypeTrait.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import software.amazon.polymorph.smithygo.codegen.SymbolUtils;
import software.amazon.polymorph.smithygo.localservice.nameresolver.DafnyNameResolver;
import software.amazon.polymorph.smithygo.localservice.nameresolver.SmithyNameResolver;
import software.amazon.polymorph.smithypython.awssdk.nameresolver.AwsSdkNameResolver;
import software.amazon.smithy.model.traits.ErrorTrait;
import software.amazon.polymorph.traits.PositionalTrait;
import software.amazon.polymorph.traits.ReferenceTrait;
import software.amazon.smithy.aws.traits.ServiceTrait;
Expand Down Expand Up @@ -188,4 +190,34 @@ private static String getInputOrOutputName(
);
}
}

/**
* Returns true if a conversion function should be written for the shape, false otherwise.
* Conversion functions are only written for "complex" shapes:
* - StructureShapes ("complex" because StructureShapes can be recursive)
* - except for non-AWS SDK StructureShapes with ErrorTrait; these aren't "complex"
* - UnionShapes ("complex" because the conversion is not a one-liner)
* - EnumShapes or StringShapes with EnumTrait ("complex" because the conversion is not a one-liner)
* @param shape
* @return
*/
public static boolean shapeShouldHaveConversionFunction(Shape shape) {
if (shape.isStructureShape()) {
if (
!SmithyNameResolver.isShapeFromAWSSDK(shape) &&
shape.hasTrait(ErrorTrait.class)
) {
return false;
}
return true;
} else if (shape.isUnionShape()) {
return true;
} else if (
(shape.isStringShape() && shape.hasTrait(EnumTrait.class)) ||
shape.isEnumShape()
) {
return true;
}
return false;
}
}

0 comments on commit 5d56ad9

Please sign in to comment.