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

feat!: Closure-based reader-writer serde for JSON, FormURL #696

Merged
merged 58 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3ee7e8d
Generated code builds
jbelkins Apr 5, 2024
0a6cbb5
Protocol tests now run with failures
jbelkins Apr 5, 2024
255be51
All readers/writers implemented, 74 test failures
jbelkins Apr 10, 2024
ef6afbc
Lint cleanup, codegen test fixes
jbelkins Apr 11, 2024
1b71f03
Handle sparse collections in response
jbelkins Apr 11, 2024
1042248
Error tests fixed
jbelkins Apr 12, 2024
e4958ba
Remove the detach() interface from Reader & Writer
jbelkins Apr 13, 2024
b6ea1d8
Fix protocol tests with non-JSON body, fix lint
jbelkins Apr 15, 2024
e2d41a6
Cleanup, fix codegen tests
jbelkins Apr 15, 2024
7bb92f5
Fix codegen tests
jbelkins Apr 15, 2024
9d8090f
Fix Swift tests
jbelkins Apr 15, 2024
c0be78e
Fix ktlint
jbelkins Apr 15, 2024
70eb9c7
Fix Swift tests
jbelkins Apr 15, 2024
9049fbf
Merge branch 'main' into jbe/readwrite
jbelkins Apr 15, 2024
7766c88
Add Int8, Int16 writing closures
jbelkins Apr 15, 2024
d8511a3
Add test dirs to swiftlint config
jbelkins Apr 16, 2024
ce56c31
Ignore union members without content
jbelkins Apr 16, 2024
a6f6a96
Fix codegen tests
jbelkins Apr 16, 2024
d8158b5
Merge branch 'main' into jbe/readwrite
jbelkins Apr 16, 2024
0d3ebf1
Fix test broken after merge
jbelkins Apr 16, 2024
0cb4b04
Fix Weather test project, rename & reorg serde files
jbelkins Apr 17, 2024
6ada476
Add WeatherSDK files
jbelkins Apr 17, 2024
7655987
Add protocol to base error, use base error to make unknown
jbelkins Apr 17, 2024
23248ea
Code cleanup
jbelkins Apr 17, 2024
19fb75d
Refactoring
jbelkins Apr 18, 2024
77ac55f
More refactoring and eliminating dead code
jbelkins Apr 18, 2024
8b4212f
ktlint fix, code cleanup
jbelkins Apr 18, 2024
efdabef
Fixes from code review
jbelkins Apr 18, 2024
54498c3
Add custom error to BaseError, eliminate unneeded closures
jbelkins Apr 18, 2024
73b1ae3
Fix ktlint
jbelkins Apr 18, 2024
3ec9818
Eliminated document closures
jbelkins Apr 19, 2024
74051e3
Fix tests
jbelkins Apr 19, 2024
ecd9c94
Merge branch 'main' into jbe/readwrite
jbelkins Apr 19, 2024
9b643b8
Fix writer format mismatch in marshal generation
jbelkins Apr 19, 2024
a76bed8
Eliminate Decodable method on enums
jbelkins Apr 20, 2024
a2f8612
Fix codegen tests
jbelkins Apr 20, 2024
975c2d6
Provide service error customization point
jbelkins Apr 22, 2024
a3caac2
Merge remote-tracking branch 'origin/main' into jbe/readwrite
jbelkins Apr 23, 2024
05ecd95
Fix ktlint
jbelkins Apr 23, 2024
b1d6f94
Add service error customization, adapt initial response events
jbelkins Apr 23, 2024
9a2a983
Fix codegen tests & ktlint
jbelkins Apr 23, 2024
7ca1ebf
Fix initial request & response methods
jbelkins Apr 24, 2024
70f18e1
Merge remote-tracking branch 'origin/main' into jbe/readwrite
jbelkins Apr 24, 2024
12f1ed1
Eliminate timestamp & ByteStream Codable conformance
jbelkins Apr 25, 2024
9ffbd39
Fix SmithyTestUtil
jbelkins Apr 25, 2024
8a4df3e
Merge branch 'main' into jbe/readwrite
jbelkins Apr 25, 2024
cf6b8ab
Merge branch 'main' into jbe/readwrite
jbelkins Apr 26, 2024
126195e
Remove Codable conformance from Enums & IntEnums, clean up enum defin…
jbelkins Apr 27, 2024
39e539b
Fix code review comments
jbelkins Apr 28, 2024
c8c6aa2
Merge branch 'main' into jbe/readwrite
jbelkins May 6, 2024
84721ae
Merge branch 'main' into jbe/readwrite
jbelkins May 6, 2024
6eef981
Merge remote-tracking branch 'origin/main' into jbe/readwrite
jbelkins May 9, 2024
05d6d33
Passes protocol tests after merge
jbelkins May 9, 2024
3bd83cc
Fix codegen tests after merge
jbelkins May 10, 2024
042b734
Regenerate WeatherSDK
jbelkins May 10, 2024
532977b
Fix Swift tests
jbelkins May 10, 2024
0a35bdf
Merge branch 'main' into jbe/readwrite
jbelkins May 10, 2024
3bd533a
Fix call to initial request message creation
jbelkins May 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ import software.amazon.smithy.swift.codegen.integration.HttpBindingDescriptor
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
import software.amazon.smithy.swift.codegen.integration.httpResponse.HTTPResponseBindingRenderable

interface HTTPResponseTraitPayloadFactory {
fun construct(
ctx: ProtocolGenerator.GenerationContext,
responseBindings: List<HttpBindingDescriptor>,
errorShape: Shape,
writer: SwiftWriter,
customizations: HTTPProtocolCustomizable,
): HTTPResponseBindingRenderable
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Delete factory since there is now only one implementation

class HTTPResponseTraitPayload(
val ctx: ProtocolGenerator.GenerationContext,
val responseBindings: List<HttpBindingDescriptor>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class HTTPResponseTraitWithHTTPPayload(
ShapeType.STRUCTURE, ShapeType.UNION -> {
if (target.hasTrait<StreamingTrait>()) {
writer.openBlock("if case .stream(let stream) = httpResponse.body {", "}") {
writer.addImport(customizations.messageDecoderSymbol.namespace)
writer.write("let messageDecoder = \$N()", customizations.messageDecoderSymbol)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The message decoder type is read from the customizations, instead of using a section writer which is super confusing and carries a lot of extra weight elsewhere in the code.

writer.write(
"let decoderStream = \$N(stream: stream, messageDecoder: messageDecoder, unmarshalClosure: \$N.unmarshal)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class HTTPResponseTraitWithoutHTTPPayload(
when (shape.type) {
ShapeType.UNION -> {
writer.openBlock("if case let .stream(stream) = httpResponse.body {", "}") {
writer.addImport(customizations.messageDecoderSymbol.namespace)
writer.write("let messageDecoder = \$N()", customizations.messageDecoderSymbol)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once again, customizations are used for message decoder type instead of a section writer.

writer.write(
"let decoderStream = \$L<\$N>(stream: stream, messageDecoder: messageDecoder, unmarshalClosure: \$N.unmarshal)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class OperationInputBodyMiddleware(

private fun addEventStreamMiddleware(writer: SwiftWriter, operationStackName: String, inputSymbol: Symbol, outputSymbol: Symbol, payloadSymbol: Symbol, keyPath: String, defaultBody: String, requestWireProtocol: WireProtocol, sendInitialRequest: Boolean) {
if (sendInitialRequest) {
writer.write("let initialRequestMessage = try input.makeInitialRequestMessage(encoder: encoder)")
writer.write("let initialRequestMessage = try input.makeInitialRequestMessage()")
}
writer.write(
"\$L.\$L.intercept(position: \$L, middleware: \$N<\$N, \$N, \$N>(keyPath: \$L, defaultBody: \$L, marshalClosure: \$N.marshal\$L))",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Types now supply their own marshal closure as a static property marshal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ class InitialRequestIntegration : SwiftIntegration {
.build()
protocolGenerationContext.delegator.useShapeWriter(inputStruct) { writer ->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code updated for new method signatures

writer.apply {
addImport(SwiftDependency.CLIENT_RUNTIME.target)
openBlock("extension ${symbol.fullName} {", "}") {
addImport(protocolGenerationContext.service.writerSymbol.namespace)
openBlock("extension \$N {", "}", symbol) {
writer.addImport(SwiftDependency.CLIENT_RUNTIME.target)
openBlock(
"func makeInitialRequestMessage(encoder: ClientRuntime.RequestEncoder) throws -> EventStream.Message {",
"func makeInitialRequestMessage() throws -> EventStream.Message {",
"}"
) {
val nodeInfoUtils = NodeInfoUtils(protocolGenerationContext, writer, protocolGenerationContext.service.requestWireProtocol)
val rootNodeInfo = nodeInfoUtils.nodeInfo(it, true)
val valueWritingClosure = WritingClosureUtils(protocolGenerationContext, writer).writingClosure(it)
writer.write("let writer = \$N(nodeInfo: \$L)", protocolGenerationContext.service.writerSymbol, rootNodeInfo)
writer.write("try writer.write(self, writingClosure: \$L)", valueWritingClosure)
writer.write("try writer.write(self, with: \$L)", valueWritingClosure)
writer.write("let initialRequestPayload = try writer.data()")
openBlock(
"let initialRequestMessage = EventStream.Message(",
Expand Down
Loading