diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt index e95c6f7183fd1edbf6ae0a3f55389ebf6879e3a6..cb18ce105f2db39397450eaaa5ee7515df205dba 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt @@ -93,6 +93,7 @@ class RustWriter private constructor(private val filename: String, val namespace rustBlock("$visibility mod $moduleName") { write(innerWriter.toString()) } + innerWriter.dependencies.forEach { addDependency(it) } } // TODO: refactor both of these methods & add a parent method to for_each across any field type diff --git a/codegen/src/test/kotlin/software/amazon/smithy/rust/lang/RustWriterTest.kt b/codegen/src/test/kotlin/software/amazon/smithy/rust/lang/RustWriterTest.kt index a9321bb9ec123738065f30b914ddadda655fb95e..27e27999114ce7a1a8a90324cb09404a15958119 100644 --- a/codegen/src/test/kotlin/software/amazon/smithy/rust/lang/RustWriterTest.kt +++ b/codegen/src/test/kotlin/software/amazon/smithy/rust/lang/RustWriterTest.kt @@ -5,14 +5,17 @@ package software.amazon.smithy.rust.lang +import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.SetShape import software.amazon.smithy.model.shapes.StringShape +import software.amazon.smithy.rust.codegen.lang.RustDependency import software.amazon.smithy.rust.codegen.lang.RustWriter import software.amazon.smithy.rust.codegen.lang.rustBlock +import software.amazon.smithy.rust.codegen.smithy.RuntimeType import software.amazon.smithy.rust.codegen.smithy.SymbolVisitor import software.amazon.smithy.rust.testutil.quickTest import software.amazon.smithy.rust.testutil.shouldCompile @@ -28,6 +31,18 @@ class RustWriterTest { sut.toString().shouldMatchResource(javaClass, "empty.rs") } + @Test + fun `inner modules correctly handle dependencies`() { + val sut = RustWriter.forModule("lib") + val requestBuilder = RuntimeType.HttpRequestBuilder + sut.withModule("inner") { + rustBlock("fn build(builer: \$T)", requestBuilder) { + } + } + val httpDep = RustDependency.Http.dependencies[0] + sut.dependencies shouldContain httpDep + } + @Test fun `manually created struct`() { val sut = RustWriter.forModule("lib")