fun render()

in smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/httpResponse/HttpResponseBindingErrorNarrowGenerator.kt [28:67]


    fun render() {
        val errorShapes = op.errors.map { ctx.model.expectShape(it) as StructureShape }.toSet().sorted()
        val operationErrorName = MiddlewareShapeUtils.outputErrorSymbolName(op)
        val rootNamespace = ctx.settings.moduleName
        val httpBindingSymbol = Symbol.builder()
            .definitionFile("./$rootNamespace/models/$operationErrorName+HttpResponseBinding.swift")
            .name(operationErrorName)
            .build()

        ctx.delegator.useShapeWriter(httpBindingSymbol) { writer ->
            writer.addImport(SwiftDependency.CLIENT_RUNTIME.target)
            writer.addImport(unknownServiceErrorSymbol)
            val unknownServiceErrorType = unknownServiceErrorSymbol.name

            val context = mapOf(
                "ctx" to ctx,
                "unknownServiceErrorType" to unknownServiceErrorType,
                "operationErrorName" to operationErrorName,
                "errorShapes" to errorShapes
            )
            writer.declareSection(HttpResponseBindingErrorNarrowGeneratorSectionId, context) {
                writer.openBlock("extension \$L {", "}", operationErrorName) {
                    writer.openBlock(
                        "public init(errorType: \$T, httpResponse: \$N, decoder: \$D, message: \$D, requestID: \$D) throws {", "}",
                        SwiftTypes.String, ClientRuntimeTypes.Http.HttpResponse, ClientRuntimeTypes.Serde.ResponseDecoder, SwiftTypes.String, SwiftTypes.String
                    ) {
                        writer.write("switch errorType {")
                        for (errorShape in errorShapes) {
                            var errorShapeName = resolveErrorShapeName(errorShape)
                            var errorShapeType = ctx.symbolProvider.toSymbol(errorShape).name
                            var errorShapeEnumCase = errorShapeType.decapitalize()
                            writer.write("case \$S : self = .\$L(try \$L(httpResponse: httpResponse, decoder: decoder, message: message, requestID: requestID))", errorShapeName, errorShapeEnumCase, errorShapeType)
                        }
                        writer.write("default : self = .unknown($unknownServiceErrorType(httpResponse: httpResponse, message: message, requestID: requestID))")
                        writer.write("}")
                    }
                }
            }
        }
    }