Skip to content

Commit 61eedfa

Browse files
committed
fix: Refine rules for members of HTTP body per-protocol
1 parent a3de344 commit 61eedfa

File tree

6 files changed

+87
-0
lines changed

6 files changed

+87
-0
lines changed

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/awsjson/AWSJSON1_0ProtocolGenerator.kt

+19
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ package software.amazon.smithy.aws.swift.codegen.protocols.awsjson
88
import software.amazon.smithy.aws.swift.codegen.AWSHTTPBindingProtocolGenerator
99
import software.amazon.smithy.aws.swift.codegen.middleware.AWSXAmzTargetMiddleware
1010
import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait
11+
import software.amazon.smithy.model.shapes.MemberShape
1112
import software.amazon.smithy.model.shapes.OperationShape
13+
import software.amazon.smithy.model.shapes.Shape
1214
import software.amazon.smithy.model.shapes.ShapeId
15+
import software.amazon.smithy.model.traits.HostLabelTrait
1316
import software.amazon.smithy.swift.codegen.integration.HttpBindingResolver
1417
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
18+
import software.amazon.smithy.swift.codegen.integration.isInHttpBody
19+
import software.amazon.smithy.swift.codegen.integration.isEventStreaming
1520
import software.amazon.smithy.swift.codegen.integration.middlewares.ContentTypeMiddleware
1621
import software.amazon.smithy.swift.codegen.integration.middlewares.OperationInputBodyMiddleware
22+
import software.amazon.smithy.swift.codegen.model.hasTrait
23+
import software.amazon.smithy.swift.codegen.model.targetOrSelf
1724

1825
@Suppress("ktlint:standard:class-naming")
1926
class AWSJSON1_0ProtocolGenerator : AWSHTTPBindingProtocolGenerator(AWSJSONCustomizations()) {
@@ -52,4 +59,16 @@ class AWSJSON1_0ProtocolGenerator : AWSHTTPBindingProtocolGenerator(AWSJSONCusto
5259
ContentTypeMiddleware(ctx.model, ctx.symbolProvider, resolver.determineRequestContentType(operation), true),
5360
)
5461
}
62+
63+
override fun httpBodyMembers(ctx: ProtocolGenerator.GenerationContext, shape: Shape): List<MemberShape> {
64+
return shape
65+
.members()
66+
// The only place an input member can be bound to in AWS JSON other than the body
67+
// is the host prefix, using the host label trait.
68+
.filter { !it.hasTrait<HostLabelTrait>() }
69+
// For RPC protocols that support event streaming, we need to send initial request
70+
// with streaming member excluded during encoding the input struct.
71+
.filter { !it.targetOrSelf(ctx.model).isEventStreaming }
72+
.toList()
73+
}
5574
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/awsjson/AWSJSON1_1ProtocolGenerator.kt

+19
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ package software.amazon.smithy.aws.swift.codegen.protocols.awsjson
88
import software.amazon.smithy.aws.swift.codegen.AWSHTTPBindingProtocolGenerator
99
import software.amazon.smithy.aws.swift.codegen.middleware.AWSXAmzTargetMiddleware
1010
import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait
11+
import software.amazon.smithy.model.shapes.MemberShape
1112
import software.amazon.smithy.model.shapes.OperationShape
13+
import software.amazon.smithy.model.shapes.Shape
1214
import software.amazon.smithy.model.shapes.ShapeId
15+
import software.amazon.smithy.model.traits.HostLabelTrait
1316
import software.amazon.smithy.swift.codegen.integration.HttpBindingResolver
1417
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
18+
import software.amazon.smithy.swift.codegen.integration.isEventStreaming
19+
import software.amazon.smithy.swift.codegen.integration.isInHttpBody
1520
import software.amazon.smithy.swift.codegen.integration.middlewares.ContentTypeMiddleware
1621
import software.amazon.smithy.swift.codegen.integration.middlewares.OperationInputBodyMiddleware
22+
import software.amazon.smithy.swift.codegen.model.hasTrait
23+
import software.amazon.smithy.swift.codegen.model.targetOrSelf
1724

1825
@Suppress("ktlint:standard:class-naming")
1926
class AWSJSON1_1ProtocolGenerator : AWSHTTPBindingProtocolGenerator(AWSJSONCustomizations()) {
@@ -50,4 +57,16 @@ class AWSJSON1_1ProtocolGenerator : AWSHTTPBindingProtocolGenerator(AWSJSONCusto
5057
ContentTypeMiddleware(ctx.model, ctx.symbolProvider, resolver.determineRequestContentType(operation), true),
5158
)
5259
}
60+
61+
override fun httpBodyMembers(ctx: ProtocolGenerator.GenerationContext, shape: Shape): List<MemberShape> {
62+
return shape
63+
.members()
64+
// The only place an input member can be bound to in AWS JSON other than the body
65+
// is the host prefix, using the host label trait.
66+
.filter { !it.hasTrait<HostLabelTrait>() }
67+
// For RPC protocols that support event streaming, we need to send initial request
68+
// with streaming member excluded during encoding the input struct.
69+
.filter { !it.targetOrSelf(ctx.model).isEventStreaming }
70+
.toList()
71+
}
5372
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/awsquery/AWSQueryProtocolGenerator.kt

+14
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ package software.amazon.smithy.aws.swift.codegen.protocols.awsquery
88
import software.amazon.smithy.aws.swift.codegen.AWSHTTPBindingProtocolGenerator
99
import software.amazon.smithy.aws.swift.codegen.FormURLHttpBindingResolver
1010
import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait
11+
import software.amazon.smithy.model.shapes.MemberShape
1112
import software.amazon.smithy.model.shapes.OperationShape
13+
import software.amazon.smithy.model.shapes.Shape
1214
import software.amazon.smithy.model.shapes.ShapeId
15+
import software.amazon.smithy.model.traits.HostLabelTrait
1316
import software.amazon.smithy.swift.codegen.integration.HttpBindingResolver
1417
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
18+
import software.amazon.smithy.swift.codegen.integration.isInHttpBody
1519
import software.amazon.smithy.swift.codegen.integration.middlewares.ContentTypeMiddleware
1620
import software.amazon.smithy.swift.codegen.integration.middlewares.OperationInputBodyMiddleware
21+
import software.amazon.smithy.swift.codegen.model.hasTrait
1722

1823
open class AWSQueryProtocolGenerator : AWSHTTPBindingProtocolGenerator(AWSQueryCustomizations()) {
1924
override val defaultContentType = "application/x-www-form-urlencoded"
@@ -48,4 +53,13 @@ open class AWSQueryProtocolGenerator : AWSHTTPBindingProtocolGenerator(AWSQueryC
4853
ContentTypeMiddleware(ctx.model, ctx.symbolProvider, resolver.determineRequestContentType(operation), true),
4954
)
5055
}
56+
57+
override fun httpBodyMembers(ctx: ProtocolGenerator.GenerationContext, shape: Shape): List<MemberShape> {
58+
return shape
59+
.members()
60+
// The only place an input member can be bound to in AWSQuery other than the body
61+
// is the host prefix, using the host label trait.
62+
.filter { !it.hasTrait<HostLabelTrait>() }
63+
.toList()
64+
}
5165
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/ec2query/EC2QueryProtocolGenerator.kt

+14
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ package software.amazon.smithy.aws.swift.codegen.protocols.ec2query
88
import software.amazon.smithy.aws.swift.codegen.AWSHTTPBindingProtocolGenerator
99
import software.amazon.smithy.aws.swift.codegen.FormURLHttpBindingResolver
1010
import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait
11+
import software.amazon.smithy.model.shapes.MemberShape
1112
import software.amazon.smithy.model.shapes.OperationShape
13+
import software.amazon.smithy.model.shapes.Shape
1214
import software.amazon.smithy.model.shapes.ShapeId
15+
import software.amazon.smithy.model.traits.HostLabelTrait
1316
import software.amazon.smithy.swift.codegen.integration.HttpBindingResolver
1417
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
18+
import software.amazon.smithy.swift.codegen.integration.isInHttpBody
1519
import software.amazon.smithy.swift.codegen.integration.middlewares.ContentTypeMiddleware
1620
import software.amazon.smithy.swift.codegen.integration.middlewares.OperationInputBodyMiddleware
21+
import software.amazon.smithy.swift.codegen.model.hasTrait
1722

1823
class EC2QueryProtocolGenerator : AWSHTTPBindingProtocolGenerator(EC2QueryCustomizations()) {
1924
override val defaultContentType = "application/x-www-form-urlencoded"
@@ -48,4 +53,13 @@ class EC2QueryProtocolGenerator : AWSHTTPBindingProtocolGenerator(EC2QueryCustom
4853
ContentTypeMiddleware(ctx.model, ctx.symbolProvider, resolver.determineRequestContentType(operation), true),
4954
)
5055
}
56+
57+
override fun httpBodyMembers(ctx: ProtocolGenerator.GenerationContext, shape: Shape): List<MemberShape> {
58+
return shape
59+
.members()
60+
// The only place an input member can be bound to in EC2Query other than the body
61+
// is the host prefix, using the host label trait.
62+
.filter { !it.hasTrait<HostLabelTrait>() }
63+
.toList()
64+
}
5165
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restjson/AWSRestJson1ProtocolGenerator.kt

+11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ package software.amazon.smithy.aws.swift.codegen.protocols.restjson
66

77
import software.amazon.smithy.aws.swift.codegen.AWSHTTPBindingProtocolGenerator
88
import software.amazon.smithy.aws.traits.protocols.RestJson1Trait
9+
import software.amazon.smithy.model.shapes.MemberShape
10+
import software.amazon.smithy.model.shapes.Shape
911
import software.amazon.smithy.model.shapes.ShapeId
12+
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
13+
import software.amazon.smithy.swift.codegen.integration.isInHttpBody
1014

1115
class AWSRestJson1ProtocolGenerator : AWSHTTPBindingProtocolGenerator(RestJSONCustomizations()) {
1216
override val defaultContentType = "application/json"
@@ -18,4 +22,11 @@ class AWSRestJson1ProtocolGenerator : AWSHTTPBindingProtocolGenerator(RestJSONCu
1822
"RestJsonClientPopulatesDefaultValuesInInput", // TODO: broken in Smithy 1.53.0
1923
"RestJsonClientPopulatesDefaultsValuesWhenMissingInResponse", // TODO: broken in Smithy 1.53.0
2024
)
25+
26+
override fun httpBodyMembers(ctx: ProtocolGenerator.GenerationContext, shape: Shape): List<MemberShape> {
27+
return shape
28+
.members()
29+
.filter { it.isInHttpBody() }
30+
.toList()
31+
}
2132
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/restxml/RestXMLProtocolGenerator.kt

+10
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ package software.amazon.smithy.aws.swift.codegen.protocols.restxml
77

88
import software.amazon.smithy.aws.swift.codegen.AWSHTTPBindingProtocolGenerator
99
import software.amazon.smithy.aws.traits.protocols.RestXmlTrait
10+
import software.amazon.smithy.model.shapes.MemberShape
11+
import software.amazon.smithy.model.shapes.Shape
1012
import software.amazon.smithy.model.shapes.ShapeId
1113
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
14+
import software.amazon.smithy.swift.codegen.integration.isInHttpBody
1215

1316
class RestXMLProtocolGenerator : AWSHTTPBindingProtocolGenerator(RestXMLCustomizations()) {
1417
override val defaultContentType: String = "application/xml"
@@ -36,4 +39,11 @@ class RestXMLProtocolGenerator : AWSHTTPBindingProtocolGenerator(RestXMLCustomiz
3639
renderCodableExtension(ctx, shape)
3740
}
3841
}
42+
43+
override fun httpBodyMembers(ctx: ProtocolGenerator.GenerationContext, shape: Shape): List<MemberShape> {
44+
return shape
45+
.members()
46+
.filter { it.isInHttpBody() }
47+
.toList()
48+
}
3949
}

0 commit comments

Comments
 (0)