in smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/model/AddOperationShapes.kt [34:74]
fun execute(model: Model, serviceShape: ServiceShape, moduleName: String): Model {
val topDownIndex: TopDownIndex = TopDownIndex.of(model)
val operations = topDownIndex.getContainedOperations(serviceShape)
val modelBuilder: Model.Builder = model.toBuilder()
for (operation in operations) {
val operationId = operation.id
LOGGER.info("building unique input/output shapes for $operationId")
// TODO: MUST FIX BEFORE SHIPPING. check to see if new synthetic input or output shapes conflict with any other shapes
// in the model by walking the model and fail code generation
val inputShape = operation.input
.map { shapeId ->
cloneOperationShape(
operationId, (model.expectShape(shapeId) as StructureShape),
"Input"
)
}
.orElseGet { emptyOperationStructure(operationId, "Input", moduleName) }
val outputShape = operation.output
.map { shapeId ->
cloneOperationShape(
operationId, (model.expectShape(shapeId) as StructureShape),
"OutputResponse"
)
}
.orElseGet { emptyOperationStructure(operationId, "OutputResponse", moduleName) }
// Add new input/output to model
modelBuilder.addShape(inputShape)
modelBuilder.addShape(outputShape)
// Update operation model with the input/output shape ids
modelBuilder.addShape(
operation.toBuilder()
.input(inputShape.toShapeId())
.output(outputShape.toShapeId())
.build()
)
}
return modelBuilder.build()
}