Skip to content
Merged
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
12 changes: 12 additions & 0 deletions codegen/core/src/it/resources/META-INF/smithy/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ structure Defaults {
@required
requiredDefaultBlob: Blob = "c3BhbQ=="

defaultNullBlob: Blob = null

// timestamp
@required
requiredTimestamp: Timestamp
Expand All @@ -400,6 +402,8 @@ structure Defaults {
@required
requiredDefaultTimestamp: Timestamp = 4.2

defaultNullTimestamp: Timestamp = null

@required
requiredList: StringList

Expand All @@ -420,6 +424,14 @@ structure Defaults {
@required
requiredDefaultMap: StringMap = {}

defaultEnum: StringYesNo = "YES"

defaultNullEnum: StringYesNo = null

defaultIntEnum: IntYesNo = 1

defaultNullIntEnum: IntYesNo = null

@required
requiredDocument: Document

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ private String getDefaultValue(PythonWriter writer, MemberShape member) {
// see: https://smithy.io/2.0/spec/type-refinement-traits.html#smithy-api-default-trait
var defaultNode = member.expectTrait(DefaultTrait.class).toNode();
var target = model.expectShape(member.getTarget());
// A null default marks the member nullable and resolves to None. Documents are
// excluded since their null default is a non-None Document(None) (see the branch below).
if (!target.isDocumentShape() && defaultNode.isNullNode()) {
return "None";
}
if (target.isTimestampShape()) {
ZonedDateTime value = CodegenUtils.parseTimestampNode(model, member, defaultNode);
return CodegenUtils.getDatetimeConstructor(writer, value);
Expand Down Expand Up @@ -318,8 +323,8 @@ private String getDefaultValue(PythonWriter writer, MemberShape member) {
});
}

// A null default is handled by the guard above, so it can't reach here.
return switch (defaultNode.getType()) {
case NULL -> "None";
case BOOLEAN -> defaultNode.expectBooleanNode().getValue() ? "True" : "False";
// These will be given to a default_factory in field. They're inherently empty, so no need to
// worry about any potential values.
Expand Down
Loading