diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/DotNetNameResolver.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/DotNetNameResolver.java index 9afc90b1e..5f23f8e26 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/DotNetNameResolver.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/DotNetNameResolver.java @@ -451,6 +451,13 @@ public String isSetMethodForStructureMember(final MemberShape memberShape) { return "IsSet%s".formatted(classPropertyForStructureMember(memberShape)); } + /** + * Returns the name of the given member shape's IsSet member + */ + public String isSetMemberForStructureMember(final MemberShape memberShape) { + return "Is%sSet".formatted(classPropertyForStructureMember(memberShape)); + } + /** * Returns the name of the class property fur use as a variable name, i.e. the first letter is lower case */ diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/TypeConversionCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/TypeConversionCodegen.java index a103b79cd..9e2102041 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/TypeConversionCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/TypeConversionCodegen.java @@ -479,6 +479,24 @@ private String generateConstructorArg(final MemberShape memberShape) { nameResolver.classPropertyForStructureMember(memberShape)); } + // return false if this struct/member is one of the special ones with a IsXxxSet member + public boolean IsNormal(final MemberShape memberShape) + { + String parent = memberShape.getId().getName(); + String member = nameResolver.classPropertyForStructureMember(memberShape); + if (parent.equals("ScanInput")) { + if (member.equals("TotalSegments") || + member.equals("Segment") || + member.equals("Limit")) { + return false; + } + } + if (parent.equals("QueryInput") && member.equals("Limit")) { + return false; + } + return true; + } + /** * Returns: * "type varName = value.IsSetPropertyName() ? value.PropertyName : (type) null;" @@ -488,14 +506,25 @@ public TokenTree generateExtractOptionalMember(final MemberShape memberShape) { final String varName = nameResolver.variableNameForClassProperty(memberShape); final String propertyName = nameResolver.classPropertyForStructureMember(memberShape); if (AwsSdkNameResolverHelpers.isInAwsSdkNamespace(memberShape.getId())) { - return TokenTree.of( - type, - varName, - "= value.%s != null".formatted(propertyName), - "? value.%s :".formatted(propertyName), - "(%s) null;".formatted(type) - ); - } else { + if (IsNormal(memberShape)) { + return TokenTree.of( + type, + varName, + "= value.%s != null".formatted(propertyName), + "? value.%s :".formatted(propertyName), + "(%s) null;".formatted(type) + ); + } else { + final String isSetMethod = nameResolver.isSetMemberForStructureMember(memberShape); + return TokenTree.of( + type, + varName, + "= value.%s".formatted(isSetMethod), + "? value.%s :".formatted(propertyName), + "(%s) null;".formatted(type) + ); + } + } else { final String isSetMethod = nameResolver.isSetMethodForStructureMember(memberShape); return TokenTree.of( type,