Skip to content

Commit

Permalink
Remove RemoveEventStreamOperations model transformer from `ServerCo…
Browse files Browse the repository at this point in the history
…degenVisitor` (#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 #1762 (comment).
  • Loading branch information
david-perez authored Sep 23, 2022
1 parent e5c8cf3 commit 6eccf70
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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),
Expand All @@ -102,7 +107,7 @@ data class ClientCodegenConfig(
ClientCodegenConfig(
formatTimeoutSeconds = coreCodegenConfig.formatTimeoutSeconds,
debugMode = coreCodegenConfig.debugMode,
eventStreamAllowList = coreCodegenConfig.eventStreamAllowList,
eventStreamAllowList = defaultEventStreamAllowList,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -85,7 +84,6 @@ data class ServerCodegenConfig(
ServerCodegenConfig(
formatTimeoutSeconds = coreCodegenConfig.formatTimeoutSeconds,
debugMode = coreCodegenConfig.debugMode,
eventStreamAllowList = coreCodegenConfig.eventStreamAllowList,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import software.amazon.smithy.model.shapes.Shape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenConfig
import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel
import software.amazon.smithy.rust.codegen.client.testutil.testRustSettings
import software.amazon.smithy.rust.codegen.client.testutil.clientTestRustSettings
import java.util.Optional

internal class RemoveEventStreamOperationsTest {
Expand Down Expand Up @@ -49,7 +49,7 @@ internal class RemoveEventStreamOperationsTest {
fun `remove event stream ops from services that are not in the allow list`() {
val transformed = RemoveEventStreamOperations.transform(
model,
testRustSettings(
clientTestRustSettings(
codegenConfig = ClientCodegenConfig(eventStreamAllowList = setOf("not-test-module")),
),
)
Expand All @@ -61,7 +61,7 @@ internal class RemoveEventStreamOperationsTest {
fun `keep event stream ops from services that are in the allow list`() {
val transformed = RemoveEventStreamOperations.transform(
model,
testRustSettings(
clientTestRustSettings(
codegenConfig = ClientCodegenConfig(eventStreamAllowList = setOf("test-module")),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolGener
import software.amazon.smithy.rust.codegen.client.smithy.transformers.EventStreamNormalizer
import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer
import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer
import software.amazon.smithy.rust.codegen.client.smithy.transformers.RemoveEventStreamOperations
import software.amazon.smithy.rust.codegen.core.util.CommandFailed
import software.amazon.smithy.rust.codegen.core.util.getTrait
import software.amazon.smithy.rust.codegen.core.util.runCommand
Expand Down Expand Up @@ -113,8 +112,6 @@ open class ServerCodegenVisitor(
.let(RecursiveShapeBoxer::transform)
// Normalize operations by adding synthetic input and output shapes to every operation
.let(OperationNormalizer::transform)
// Drop unsupported event stream operations from the model
.let { RemoveEventStreamOperations.transform(it, settings) }
// Normalize event stream operations
.let(EventStreamNormalizer::transform)

Expand Down

0 comments on commit 6eccf70

Please sign in to comment.