Unverified Commit 6eccf701 authored by david-perez's avatar david-perez Committed by GitHub
Browse files

Remove `RemoveEventStreamOperations` model transformer from `ServerCodegenVisitor` (#1764)

This is a holdover from when the server subproject was started. We've
never utilized this model transformer, nor will we have any use for it
now, since event stream operations are supported in the server since #1479.

See https://github.com/awslabs/smithy-rs/pull/1762#discussion_r978151466.
parent e5c8cf30
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ package software.amazon.smithy.rust.codegen.client.smithy
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.node.ObjectNode
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.rust.codegen.core.util.orNull
import java.util.Optional

/**
@@ -76,24 +77,28 @@ data class ClientRustSettings(
data class ClientCodegenConfig(
    override val formatTimeoutSeconds: Int = defaultFormatTimeoutSeconds,
    override val debugMode: Boolean = defaultDebugMode,
    override val eventStreamAllowList: Set<String> = defaultEventStreamAllowList,
    val renameExceptions: Boolean = defaultRenameExceptions,
    val includeFluentClient: Boolean = defaultIncludeFluentClient,
    val addMessageToErrors: Boolean = defaultAddMessageToErrors,
    // TODO(EventStream): [CLEANUP] Remove this property when turning on Event Stream for all services
    val eventStreamAllowList: Set<String> = defaultEventStreamAllowList,
) : CoreCodegenConfig(
    formatTimeoutSeconds, debugMode, eventStreamAllowList,
    formatTimeoutSeconds, debugMode,
) {
    companion object {
        private const val defaultRenameExceptions = true
        private const val defaultIncludeFluentClient = true
        private const val defaultAddMessageToErrors = true
        private val defaultEventStreamAllowList: Set<String> = emptySet()

        fun fromCodegenConfigAndNode(coreCodegenConfig: CoreCodegenConfig, node: Optional<ObjectNode>) =
            if (node.isPresent) {
                ClientCodegenConfig(
                    formatTimeoutSeconds = coreCodegenConfig.formatTimeoutSeconds,
                    debugMode = coreCodegenConfig.debugMode,
                    eventStreamAllowList = coreCodegenConfig.eventStreamAllowList,
                    eventStreamAllowList = node.get().getArrayMember("eventStreamAllowList")
                        .map { array -> array.toList().mapNotNull { node -> node.asStringNode().orNull()?.value } }
                        .orNull()?.toSet() ?: defaultEventStreamAllowList,
                    renameExceptions = node.get().getBooleanMemberOrDefault("renameErrors", defaultRenameExceptions),
                    includeFluentClient = node.get().getBooleanMemberOrDefault("includeFluentClient", defaultIncludeFluentClient),
                    addMessageToErrors = node.get().getBooleanMemberOrDefault("addMessageToErrors", defaultAddMessageToErrors),
@@ -102,7 +107,7 @@ data class ClientCodegenConfig(
                ClientCodegenConfig(
                    formatTimeoutSeconds = coreCodegenConfig.formatTimeoutSeconds,
                    debugMode = coreCodegenConfig.debugMode,
                    eventStreamAllowList = coreCodegenConfig.eventStreamAllowList,
                    eventStreamAllowList = defaultEventStreamAllowList,
                )
            }
    }
+0 −7
Original line number Diff line number Diff line
@@ -41,28 +41,21 @@ const val CODEGEN_SETTINGS = "codegen"
open class CoreCodegenConfig(
    open val formatTimeoutSeconds: Int = defaultFormatTimeoutSeconds,
    open val debugMode: Boolean = defaultDebugMode,
    // TODO(EventStream): [CLEANUP] Remove this property when turning on Event Stream for all services
    open val eventStreamAllowList: Set<String> = defaultEventStreamAllowList,
) {
    companion object {
        const val defaultFormatTimeoutSeconds = 20
        const val defaultDebugMode = false
        val defaultEventStreamAllowList: Set<String> = emptySet()

        fun fromNode(node: Optional<ObjectNode>): CoreCodegenConfig =
            if (node.isPresent) {
                CoreCodegenConfig(
                    node.get().getNumberMemberOrDefault("formatTimeoutSeconds", defaultFormatTimeoutSeconds).toInt(),
                    node.get().getBooleanMemberOrDefault("debugMode", defaultDebugMode),
                    node.get().getArrayMember("eventStreamAllowList")
                        .map { array -> array.toList().mapNotNull { node -> node.asStringNode().orNull()?.value } }
                        .orNull()?.toSet() ?: defaultEventStreamAllowList,
                )
            } else {
                CoreCodegenConfig(
                    formatTimeoutSeconds = defaultFormatTimeoutSeconds,
                    debugMode = defaultDebugMode,
                    eventStreamAllowList = defaultEventStreamAllowList,
                )
            }
    }
+1 −3
Original line number Diff line number Diff line
@@ -73,9 +73,8 @@ data class ServerRustSettings(
data class ServerCodegenConfig(
    override val formatTimeoutSeconds: Int = defaultFormatTimeoutSeconds,
    override val debugMode: Boolean = defaultDebugMode,
    override val eventStreamAllowList: Set<String> = defaultEventStreamAllowList,
) : CoreCodegenConfig(
    formatTimeoutSeconds, debugMode, eventStreamAllowList,
    formatTimeoutSeconds, debugMode,
) {
    companion object {
        // Note `node` is unused, because at the moment `ServerCodegenConfig` has the same properties as
@@ -85,7 +84,6 @@ data class ServerCodegenConfig(
            ServerCodegenConfig(
                formatTimeoutSeconds = coreCodegenConfig.formatTimeoutSeconds,
                debugMode = coreCodegenConfig.debugMode,
                eventStreamAllowList = coreCodegenConfig.eventStreamAllowList,
            )
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.transform.ModelTransformer
import software.amazon.smithy.rust.codegen.client.smithy.CoreRustSettings
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustSettings
import software.amazon.smithy.rust.codegen.core.util.findStreamingMember
import software.amazon.smithy.rust.codegen.core.util.orNull
import java.util.logging.Logger
@@ -19,7 +19,7 @@ import java.util.logging.Logger
object RemoveEventStreamOperations {
    private val logger = Logger.getLogger(javaClass.name)

    fun transform(model: Model, settings: CoreRustSettings): Model {
    fun transform(model: Model, settings: ClientRustSettings): Model {
        // If Event Stream is allowed in build config, then don't remove the operations
        val allowList = settings.codegenConfig.eventStreamAllowList
        if (allowList.isEmpty() || allowList.contains(settings.moduleName)) {
+29 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.client.testutil

import software.amazon.smithy.model.Model
import software.amazon.smithy.model.knowledge.NullableIndex
import software.amazon.smithy.model.node.ObjectNode
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.shapes.StructureShape
@@ -16,6 +17,8 @@ import software.amazon.smithy.rust.codegen.client.rustlang.CratesIo
import software.amazon.smithy.rust.codegen.client.rustlang.DependencyScope
import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.client.rustlang.asType
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenConfig
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustSettings
import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenConfig
import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.CoreRustSettings
@@ -41,6 +44,32 @@ val TestSymbolVisitorConfig = SymbolVisitorConfig(
    nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1,
)

fun clientTestRustSettings(
    service: ShapeId = ShapeId.from("notrelevant#notrelevant"),
    moduleName: String = "test-module",
    moduleVersion: String = "0.0.1",
    moduleAuthors: List<String> = listOf("notrelevant"),
    moduleDescription: String = "not relevant",
    moduleRepository: String? = null,
    runtimeConfig: RuntimeConfig = TestRuntimeConfig,
    codegenConfig: ClientCodegenConfig = ClientCodegenConfig(),
    license: String? = null,
    examplesUri: String? = null,
    customizationConfig: ObjectNode? = null,
) = ClientRustSettings(
    service,
    moduleName,
    moduleVersion,
    moduleAuthors,
    moduleDescription,
    moduleRepository,
    runtimeConfig,
    codegenConfig,
    license,
    examplesUri,
    customizationConfig,
)

fun testRustSettings(
    service: ShapeId = ShapeId.from("notrelevant#notrelevant"),
    moduleName: String = "test-module",
Loading