Skip to content

Commit 82c46e9

Browse files
committed
Fix objects and lists
1 parent 1336afb commit 82c46e9

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/smoketests/SmokeTestsRunnerGenerator.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import software.amazon.smithy.codegen.core.Symbol
44
import software.amazon.smithy.kotlin.codegen.core.*
55
import software.amazon.smithy.kotlin.codegen.integration.SectionId
66
import software.amazon.smithy.kotlin.codegen.integration.SectionKey
7+
import software.amazon.smithy.kotlin.codegen.model.expectShape
78
import software.amazon.smithy.kotlin.codegen.model.getTrait
89
import software.amazon.smithy.kotlin.codegen.model.hasTrait
910
import software.amazon.smithy.kotlin.codegen.model.isStringEnumShape
@@ -207,8 +208,9 @@ class SmokeTestsRunnerGenerator(
207208
node: Node,
208209
shapes: Map<String, Shape>,
209210
testCase: SmokeTestCase,
210-
): String {
211-
val shape = shapes[paramName] ?: throw Exception("Unable to find shape for operation parameter '$paramName' in smoke test '${testCase.functionName}'")
211+
shapeOverride: Shape? = null,
212+
) {
213+
val shape = shapeOverride ?: shapes[paramName] ?: throw Exception("Unable to find shape for operation parameter '$paramName' in smoke test '${testCase.functionName}'.")
212214
when {
213215
// String enum
214216
node is StringNode && shape.isStringEnumShape -> {
@@ -224,10 +226,30 @@ class SmokeTestsRunnerGenerator(
224226
}
225227
// Number
226228
node is NumberNode && shape is NumberShape -> writer.write("#L.#L", node.format(), stringToNumber(shape))
229+
// Object
230+
node is ObjectNode -> {
231+
val shapeSymbol = symbolProvider.toSymbol(shape)
232+
writer.withBlock("#T {", "}", shapeSymbol) {
233+
node.members.forEach { member ->
234+
val memberName = member.key.value.toCamelCase()
235+
val memberShape = shape.allMembers[member.key.value] ?: throw Exception("Unable to find shape for operation parameter '$paramName' in smoke test '${testCase.functionName}'.")
236+
writer.writeInline("#L = ", memberName)
237+
renderOperationParameter(memberName, member.value, mapOf(memberName to memberShape), testCase)
238+
}
239+
}
240+
}
241+
// List
242+
node is ArrayNode && shape is CollectionShape -> {
243+
writer.withBlock("listOf(", ")") {
244+
node.elements.forEach { element ->
245+
renderOperationParameter(paramName, element, mapOf(), testCase, model.expectShape(shape.member.target))
246+
writer.write(",")
247+
}
248+
}
249+
}
227250
// Everything else
228251
else -> writer.write("#L", node.format())
229252
}
230-
return writer.rawString()
231253
}
232254

233255
/**

0 commit comments

Comments
 (0)