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

chore: Update to Smithy 1.53.0 #866

Merged
merged 3 commits into from
Dec 19, 2024
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kotlin.code.style=official
# config

# codegen
smithyVersion=1.52.1
smithyVersion=1.53.0
smithyGradleVersion=0.6.0

# kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import software.amazon.smithy.model.traits.EnumTrait
import software.amazon.smithy.model.traits.StreamingTrait
import software.amazon.smithy.swift.codegen.model.hasTrait
import software.amazon.smithy.swift.codegen.model.toMemberNames
import software.amazon.smithy.swift.codegen.swiftmodules.FoundationTypes
import software.amazon.smithy.swift.codegen.swiftmodules.SmithyStreamsTypes
import software.amazon.smithy.swift.codegen.swiftmodules.SmithyTimestampsTypes
import software.amazon.smithy.swift.codegen.swiftmodules.SmithyTypes
Expand Down Expand Up @@ -160,11 +161,12 @@ class ShapeValueGenerator(
}
ShapeType.BLOB -> {
if (shape.hasTrait<StreamingTrait>()) {
writer.writeInline(".stream(\$N(data: ", SmithyStreamsTypes.Core.BufferedStream)
".data(using: .utf8)!, isClosed: true))"
writer.writeInline(".stream(\$N(data: \$N(", SmithyStreamsTypes.Core.BufferedStream, FoundationTypes.Data)
".utf8), isClosed: true))"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little code cleanup & converted to using Swift string's utf8 view to create data.

} else {
// TODO: properly handle this optional with an unwrapped statement before it's passed as a value to a shape.
".data(using: .utf8)!"
writer.writeInline("\$N(", FoundationTypes.Data)
".utf8)"
}
}
else -> { "" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,14 @@ class SwiftSymbolProvider(private val model: Model, val swiftSettings: SwiftSett
if (shape.hasTrait<StreamingTrait>()) {
{ writer ->
writer.format(
"\$N.data(\$N(\"$literal\".utf8))",
"\$N.data(\$N(base64Encoded: \"$literal\"))",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smithy blob default values are always base64-encoded strings so the default is decoded here.

SmithyTypes.ByteStream,
FoundationTypes.Data
)
}
} else {
{ writer ->
writer.format("\$N(\"$literal\".utf8)", FoundationTypes.Data)
writer.format("\$N(base64Encoded: \"$literal\")", FoundationTypes.Data)
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,16 @@ open class MemberShapeDecodeGenerator(
writer.addImport(FoundationTypes.Data)
return if (targetShape.hasTrait<StreamingTrait>()) {
writer.format(
" ?? \$N.data(\$N(\"$value\".utf8))",
" ?? \$N.data(\$N(base64Encoded: \$S))",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same fixes here: decode the blob default string from base64 before using.

SmithyTypes.ByteStream,
FoundationTypes.Data
FoundationTypes.Data,
value,
)
} else {
writer.format(
" ?? \$N(\"$value\".utf8)",
FoundationTypes.Data
" ?? \$N(base64Encoded: \$S)",
FoundationTypes.Data,
value,
)
}
}
Expand Down
Loading