Skip to content

Commit

Permalink
Add additional default semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Oct 2, 2023
1 parent 5129c1f commit 9e7b6c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ class BuilderGenerator(
")?",
) { missingRequiredField(memberName) }
}
} else if (member.isRequired && default != null) {
rust(".or_else(|| Some((#T)()))", default.expr)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,24 @@ internal class BuilderGeneratorTest {
@default(true)
@required
defaultDocument: Document
@clientOptional
@required
@default([])
requiredButOptional: StringList
@default(1)
@clientOptional
@required
reqOptInt: OneDefault
}
list StringList {
member: String
}
@default(1)
integer OneDefault
""".asSmithyModel(smithyVersion = "2.0")

val provider = testSymbolProvider(
Expand All @@ -207,6 +219,7 @@ internal class BuilderGeneratorTest {
assert_eq!(s.an_actually_required_field(), 5);
assert_eq!(s.no_default(), None);
assert_eq!(s.default_document().as_bool().unwrap(), true);
assert_eq!(s.required_but_optional, Some(vec![]));
""",
"Struct" to provider.toSymbol(shape),
)
Expand Down

0 comments on commit 9e7b6c1

Please sign in to comment.