Unverified Commit 917d0a62 authored by Luca Palmieri's avatar Luca Palmieri Committed by GitHub
Browse files

Do not generate public empty modules (#1803)

* Mark `operation_handler` module as private in the generated server code since it does not contain any public type.
Tune the visibility of the 'operation' module based on the rendering context

* Add changelog.next entry.

* Rename `operationModule` to `operation`.

* Ensure that `operation` is added to the list of public modules for the generated client.

* Remove DefaultModules from codegen-core

* Fix Python server.

* Expose TestDefaultPublicModules.
parent 39c0096c
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -10,6 +10,16 @@
# references = ["smithy-rs#920"]
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"

[[smithy-rs]]
message = """
Mark `operation` and `operation_handler` modules as private in the generated server crate.
Both modules did not contain any public types, therefore there should be no actual breakage when updating.
"""
references = ["smithy-rs#1803"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server"}
author = "LukeMathWalker"

[[smithy-rs]]
message = "Pokémon Service example code now runs clippy during build."
references = ["smithy-rs#1727"]
+12 −2
Original line number Diff line number Diff line
@@ -23,7 +23,8 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.Cli
import software.amazon.smithy.rust.codegen.client.smithy.protocols.ClientProtocolLoader
import software.amazon.smithy.rust.codegen.client.smithy.transformers.AddErrorMessage
import software.amazon.smithy.rust.codegen.client.smithy.transformers.RemoveEventStreamOperations
import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig
@@ -81,10 +82,19 @@ class CodegenVisitor(
        symbolProvider = RustCodegenPlugin.baseSymbolProvider(model, service, symbolVisitorConfig)

        codegenContext = ClientCodegenContext(model, symbolProvider, service, protocol, settings)

        val clientPublicModules = setOf(
            RustModule.Error,
            RustModule.Model,
            RustModule.Input,
            RustModule.Output,
            RustModule.Config,
            RustModule.operation(Visibility.PUBLIC),
        ).associateBy { it.name }
        rustCrate = RustCrate(
            context.fileManifest,
            symbolProvider,
            DefaultPublicModules,
            clientPublicModules,
            codegenContext.settings.codegenConfig,
        )
        protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext)
+2 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg
import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.rustlang.asType
import software.amazon.smithy.rust.codegen.core.rustlang.docs
import software.amazon.smithy.rust.codegen.core.rustlang.rust
@@ -34,7 +35,7 @@ class CustomizableOperationGenerator(
    private val smithyTypes = CargoDependency.SmithyTypes(runtimeConfig).asType()

    fun render(crate: RustCrate) {
        crate.withModule(RustModule.Operation) { writer ->
        crate.withModule(RustModule.operation(Visibility.PUBLIC)) { writer ->
            writer.docs("Operation customization and supporting types")
            writer.rust("pub mod customize;")
        }
+11 −1
Original line number Diff line number Diff line
@@ -23,8 +23,18 @@ data class RustModule(val name: String, val rustMetadata: RustMetadata, val docu
        fun private(name: String, documentation: String? = null): RustModule =
            default(name, visibility = Visibility.PRIVATE, documentation = documentation)

        /* Common modules used across client, server and tests */
        val Config = public("config", documentation = "Configuration for the service.")
        val Error = public("error", documentation = "All error types that operations can return.")
        val Operation = public("operation", documentation = "All operations that this crate can perform.")
        val Model = public("model", documentation = "Data structures used by operation inputs/outputs.")
        val Input = public("input", documentation = "Input structures for operations.")
        val Output = public("output", documentation = "Output structures for operations.")

        /**
         * Helper method to generate the `operation` Rust module.
         * Its visibility depends on the generation context (client or server).
         */
        fun operation(visibility: Visibility): RustModule =
            default("operation", visibility = visibility, documentation = "All operations that this crate can perform.")
    }
}
+0 −12
Original line number Diff line number Diff line
@@ -170,18 +170,6 @@ open class RustCrate(
    }
}

/**
 * Allowlist of modules that will be exposed publicly in generated crates
 */
val DefaultPublicModules = setOf(
    RustModule.Error,
    RustModule.Operation,
    RustModule.public("model", documentation = "Data structures used by operation inputs/outputs."),
    RustModule.public("input", documentation = "Input structures for operations."),
    RustModule.public("output", documentation = "Output structures for operations."),
    RustModule.Config,
).associateBy { it.name }

/**
 * Finalize all the writers by:
 * - inlining inline dependencies that have been used
Loading