Skip to content

Commit 2965547

Browse files
committed
fix: pr feedback
1 parent 5cef3b6 commit 2965547

File tree

12 files changed

+155
-202
lines changed

12 files changed

+155
-202
lines changed

codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/Ec2Query.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ private class Ec2QuerySerializerGenerator(
8080
shape: Shape,
8181
members: List<MemberShape>,
8282
writer: KotlinWriter,
83-
idempotencyTokenEligible: Boolean,
8483
) {
8584
// render the serde descriptors
8685
descriptorGenerator(ctx, shape, members, writer).render()

codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/QueryHttpBindingProtocolGenerator.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ abstract class AbstractQueryFormUrlSerializerGenerator(
132132
) {
133133
val shape = ctx.model.expectShape(op.input.get())
134134
writer.write("val serializer = #T()", RuntimeTypes.Serde.SerdeFormUrl.FormUrlSerializer)
135-
renderSerializerBody(ctx, shape, documentMembers, writer, true)
135+
renderSerializerBody(ctx, shape, documentMembers, writer)
136136
writer.write("return serializer.toByteArray()")
137137
}
138138

@@ -156,13 +156,12 @@ abstract class AbstractQueryFormUrlSerializerGenerator(
156156
shape: Shape,
157157
members: List<MemberShape>,
158158
writer: KotlinWriter,
159-
idempotencyTokenEligible: Boolean = false,
160159
) {
161160
// render the serde descriptors
162161
descriptorGenerator(ctx, shape, members, writer).render()
163162
when (shape) {
164163
is UnionShape -> SerializeUnionGenerator(ctx, shape, members, writer, defaultTimestampFormat).render()
165-
else -> SerializeStructGenerator(ctx, members, writer, defaultTimestampFormat, idempotencyTokenEligible).render()
164+
else -> SerializeStructGenerator(ctx, members, writer, defaultTimestampFormat).render()
166165
}
167166
}
168167

codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/AwsQueryTest.kt

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,43 +63,43 @@ class AwsQueryTest {
6363
}
6464

6565
private val model = """
66-
${"$"}version: "2"
67-
68-
namespace com.test
69-
70-
use aws.protocols#awsQuery
71-
use aws.api#service
72-
73-
@awsQuery
74-
@service(sdkId: "Example")
75-
@xmlNamespace(uri: "http://foo.com")
76-
service Example {
77-
version: "1.0.0",
78-
operations: [GetBarUnNested, GetBarNested]
79-
}
80-
81-
@http(method: "POST", uri: "/get-bar-un-nested")
82-
operation GetBarUnNested {
83-
input: BarUnNested
84-
}
66+
${"$"}version: "2"
8567
86-
structure BarUnNested {
87-
@idempotencyToken
88-
bar: String
89-
}
68+
namespace com.test
69+
70+
use aws.protocols#awsQuery
71+
use aws.api#service
9072
91-
@http(method: "POST", uri: "/get-bar-nested")
92-
operation GetBarNested {
93-
input: BarNested
94-
}
73+
@awsQuery
74+
@service(sdkId: "Example")
75+
@xmlNamespace(uri: "http://foo.com")
76+
service Example {
77+
version: "1.0.0",
78+
operations: [GetBarUnNested, GetBarNested]
79+
}
9580
96-
structure BarNested {
97-
bar: Nest
98-
}
99-
100-
structure Nest {
101-
@idempotencyToken
102-
baz: String
103-
}
81+
@http(method: "POST", uri: "/get-bar-un-nested")
82+
operation GetBarUnNested {
83+
input: BarUnNested
84+
}
85+
86+
structure BarUnNested {
87+
@idempotencyToken
88+
bar: String
89+
}
90+
91+
@http(method: "POST", uri: "/get-bar-nested")
92+
operation GetBarNested {
93+
input: BarNested
94+
}
95+
96+
structure BarNested {
97+
bar: Nest
98+
}
99+
100+
structure Nest {
101+
@idempotencyToken
102+
baz: String
103+
}
104104
""".toSmithyModel()
105105
}

codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/RestJson1Test.kt

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -63,42 +63,42 @@ class RestJson1Test {
6363
}
6464

6565
private val model = """
66-
${"$"}version: "2"
67-
68-
namespace com.test
69-
70-
use aws.protocols#restJson1
71-
use aws.api#service
72-
73-
@restJson1
74-
@service(sdkId: "Example")
75-
service Example {
76-
version: "1.0.0",
77-
operations: [GetBarUnNested, GetBarNested]
78-
}
79-
80-
@http(method: "POST", uri: "/get-bar-un-nested")
81-
operation GetBarUnNested {
82-
input: BarUnNested
83-
}
66+
${"$"}version: "2"
8467
85-
structure BarUnNested {
86-
@idempotencyToken
87-
bar: String
88-
}
68+
namespace com.test
69+
70+
use aws.protocols#restJson1
71+
use aws.api#service
8972
90-
@http(method: "POST", uri: "/get-bar-nested")
91-
operation GetBarNested {
92-
input: BarNested
93-
}
73+
@restJson1
74+
@service(sdkId: "Example")
75+
service Example {
76+
version: "1.0.0",
77+
operations: [GetBarUnNested, GetBarNested]
78+
}
9479
95-
structure BarNested {
96-
bar: Nest
97-
}
98-
99-
structure Nest {
100-
@idempotencyToken
101-
baz: String
102-
}
80+
@http(method: "POST", uri: "/get-bar-un-nested")
81+
operation GetBarUnNested {
82+
input: BarUnNested
83+
}
84+
85+
structure BarUnNested {
86+
@idempotencyToken
87+
bar: String
88+
}
89+
90+
@http(method: "POST", uri: "/get-bar-nested")
91+
operation GetBarNested {
92+
input: BarNested
93+
}
94+
95+
structure BarNested {
96+
bar: Nest
97+
}
98+
99+
structure Nest {
100+
@idempotencyToken
101+
baz: String
102+
}
103103
""".toSmithyModel()
104104
}

codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/RestXmlTest.kt

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -63,42 +63,42 @@ class RestXmlTest {
6363
}
6464

6565
private val model = """
66-
${"$"}version: "2"
67-
68-
namespace com.test
69-
70-
use aws.protocols#restXml
71-
use aws.api#service
72-
73-
@restXml
74-
@service(sdkId: "Example")
75-
service Example {
76-
version: "1.0.0",
77-
operations: [GetBarUnNested, GetBarNested]
78-
}
79-
80-
@http(method: "POST", uri: "/get-bar-un-nested")
81-
operation GetBarUnNested {
82-
input: BarUnNested
83-
}
66+
${"$"}version: "2"
8467
85-
structure BarUnNested {
86-
@idempotencyToken
87-
bar: String
88-
}
68+
namespace com.test
69+
70+
use aws.protocols#restXml
71+
use aws.api#service
8972
90-
@http(method: "POST", uri: "/get-bar-nested")
91-
operation GetBarNested {
92-
input: BarNested
93-
}
73+
@restXml
74+
@service(sdkId: "Example")
75+
service Example {
76+
version: "1.0.0",
77+
operations: [GetBarUnNested, GetBarNested]
78+
}
9479
95-
structure BarNested {
96-
bar: Nest
97-
}
98-
99-
structure Nest {
100-
@idempotencyToken
101-
baz: String
102-
}
80+
@http(method: "POST", uri: "/get-bar-un-nested")
81+
operation GetBarUnNested {
82+
input: BarUnNested
83+
}
84+
85+
structure BarUnNested {
86+
@idempotencyToken
87+
bar: String
88+
}
89+
90+
@http(method: "POST", uri: "/get-bar-nested")
91+
operation GetBarNested {
92+
input: BarNested
93+
}
94+
95+
structure BarNested {
96+
bar: Nest
97+
}
98+
99+
structure Nest {
100+
@idempotencyToken
101+
baz: String
102+
}
103103
""".toSmithyModel()
104104
}

codegen/smithy-kotlin-codegen-testutils/src/main/kotlin/software/amazon/smithy/kotlin/codegen/test/CodegenTestUtils.kt

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,17 @@ fun codegenSerializerForShape(
5959
shapeId: String,
6060
location: HttpBinding.Location = HttpBinding.Location.DOCUMENT,
6161
settings: KotlinSettings? = null,
62-
idempotencyTokenEligible: Boolean = false,
6362
): String {
6463
val resolvedSettings = settings ?: model.defaultSettings(TestModelDefault.SERVICE_NAME, TestModelDefault.NAMESPACE)
6564
val ctx = model.newTestContext(settings = resolvedSettings)
6665

67-
val shape = ctx.generationCtx.model.expectShape(ShapeId.from(shapeId))
68-
return testRender(ctx.shapeMembers(shape, location)) { members, writer ->
66+
val op = ctx.generationCtx.model.expectShape(ShapeId.from(shapeId))
67+
return testRender(ctx.requestMembers(op, location)) { members, writer ->
6968
SerializeStructGenerator(
7069
ctx.generationCtx,
7170
members,
7271
writer,
7372
TimestampFormatTrait.Format.EPOCH_SECONDS,
74-
idempotencyTokenEligible,
7573
).render()
7674
}
7775
}
@@ -123,25 +121,16 @@ fun TestContext.responseMembers(shape: Shape, location: HttpBinding.Location = H
123121
.map { it.member }
124122
}
125123

126-
/**
127-
* If the shape represents an operation, it attempts to retrieve the request document members for protocols enabled with HttpTrait.
128-
* Otherwise, it retrieves the shape's members.
129-
* */
130-
fun TestContext.shapeMembers(shape: Shape, location: HttpBinding.Location = HttpBinding.Location.DOCUMENT): List<MemberShape> =
131-
when (shape) {
132-
is OperationShape -> {
133-
val bindingIndex = HttpBindingIndex.of(this.generationCtx.model)
134-
val responseBindings = bindingIndex.getRequestBindings(shape)
135-
136-
responseBindings.values
137-
.filter { it.location == location }
138-
.sortedBy { it.memberName }
139-
.map { it.member }
140-
}
141-
else -> {
142-
shape.members().toList()
143-
}
144-
}
124+
/** Retrieves Request Document members for HttpTrait-enabled protocols */
125+
fun TestContext.requestMembers(shape: Shape, location: HttpBinding.Location = HttpBinding.Location.DOCUMENT): List<MemberShape> {
126+
val bindingIndex = HttpBindingIndex.of(this.generationCtx.model)
127+
val responseBindings = bindingIndex.getRequestBindings(shape)
128+
129+
return responseBindings.values
130+
.filter { it.location == location }
131+
.sortedBy { it.memberName }
132+
.map { it.member }
133+
}
145134

146135
fun TestContext.toGenerationContext(): GenerationContext =
147136
GenerationContext(generationCtx.model, generationCtx.symbolProvider, generationCtx.settings, generator)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.kotlin.codegen.model.knowledge
7+
8+
import software.amazon.smithy.kotlin.codegen.utils.getOrNull
9+
import software.amazon.smithy.model.Model
10+
import software.amazon.smithy.model.knowledge.TopDownIndex
11+
import software.amazon.smithy.model.shapes.MemberShape
12+
import software.amazon.smithy.model.shapes.ServiceShape
13+
14+
class TopLevelIndex(model: Model, service: ServiceShape) {
15+
private val operations = TopDownIndex(model).getContainedOperations(service)
16+
private val inputStructs = operations.mapNotNull { it.input.getOrNull() }.map { model.expectShape(it) }
17+
private val inputMembers = inputStructs.flatMap { it.members() }.toSet()
18+
19+
fun isTopLevelInputMember(member: MemberShape): Boolean = member in inputMembers
20+
}

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/serde/CborSerializerGenerator.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CborSerializerGenerator(
4141
) {
4242
val shape = ctx.model.expectShape(op.input.get())
4343
writer.write("val serializer = #T()", RuntimeTypes.Serde.SerdeCbor.CborSerializer)
44-
renderSerializerBody(ctx, shape, documentMembers, writer, idempotencyTokenEligible = true)
44+
renderSerializerBody(ctx, shape, documentMembers, writer)
4545
writer.write("return serializer.toHttpBody()")
4646
}
4747

@@ -50,13 +50,12 @@ class CborSerializerGenerator(
5050
shape: Shape,
5151
members: List<MemberShape>,
5252
writer: KotlinWriter,
53-
idempotencyTokenEligible: Boolean = false,
5453
) {
5554
descriptorGenerator(ctx, shape, members, writer).render()
5655
when (shape) {
5756
is DocumentShape -> writer.write("serializer.serializeDocument(input)")
5857
is UnionShape -> SerializeUnionGenerator(ctx, shape, members, writer, TimestampFormatTrait.Format.EPOCH_SECONDS).render()
59-
else -> SerializeStructGenerator(ctx, members, writer, TimestampFormatTrait.Format.EPOCH_SECONDS, idempotencyTokenEligible).render()
58+
else -> SerializeStructGenerator(ctx, members, writer, TimestampFormatTrait.Format.EPOCH_SECONDS).render()
6059
}
6160
}
6261

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/serde/JsonSerializerGenerator.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ open class JsonSerializerGenerator(
6363
) {
6464
val shape = ctx.model.expectShape(op.input.get())
6565
writer.write("val serializer = #T()", RuntimeTypes.Serde.SerdeJson.JsonSerializer)
66-
renderSerializerBody(ctx, shape, documentMembers, writer, idempotencyTokenEligible = true)
66+
renderSerializerBody(ctx, shape, documentMembers, writer)
6767
writer.write("return serializer.toByteArray()")
6868
}
6969

@@ -88,14 +88,13 @@ open class JsonSerializerGenerator(
8888
shape: Shape,
8989
members: List<MemberShape>,
9090
writer: KotlinWriter,
91-
idempotencyTokenEligible: Boolean = false,
9291
) {
9392
// render the serde descriptors
9493
JsonSerdeDescriptorGenerator(ctx.toRenderingContext(protocolGenerator, shape, writer), members, supportsJsonNameTrait).render()
9594
when (shape) {
9695
is DocumentShape -> writer.write("serializer.serializeDocument(input)")
9796
is UnionShape -> SerializeUnionGenerator(ctx, shape, members, writer, defaultTimestampFormat).render()
98-
else -> SerializeStructGenerator(ctx, members, writer, defaultTimestampFormat, idempotencyTokenEligible).render()
97+
else -> SerializeStructGenerator(ctx, members, writer, defaultTimestampFormat).render()
9998
}
10099
}
101100

0 commit comments

Comments
 (0)