Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt +3 −16 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import software.amazon.smithy.model.traits.HttpLabelTrait import software.amazon.smithy.rust.codegen.lang.RustType import software.amazon.smithy.rust.codegen.smithy.generators.toSnakeCase import software.amazon.smithy.rust.codegen.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.smithy.traits.SyntheticOutputTrait import software.amazon.smithy.utils.StringUtils // TODO: currently, respecting integer types. Loading @@ -55,20 +56,6 @@ val SimpleShapes = mapOf( StringShape::class to RustType.String ) // TODO: // Unions // Recursive shapes // Synthetics (blobs, timestamps) // Operation // Resources (do we do anything for resources?) // Services // Higher-level: Set, List, Map fun Symbol.referenceClosure(): List<Symbol> { val referencedSymbols = this.references.map { it.symbol } return listOf(this) + referencedSymbols.flatMap { it.referenceClosure() } } data class SymbolVisitorConfig( val runtimeConfig: RuntimeConfig, val handleOptionality: Boolean = true, Loading Loading @@ -222,7 +209,7 @@ class SymbolVisitor( override fun structureShape(shape: StructureShape): Symbol { val isError = shape.hasTrait(ErrorTrait::class.java) val isInput = shape.hasTrait(SyntheticInputTrait::class.java) val isIoShape = shape.hasTrait(SyntheticInputTrait::class.java) || shape.hasTrait(SyntheticOutputTrait::class.java) val name = StringUtils.capitalize(shape.id.name).letIf(isError) { // TODO: this is should probably be a configurable mixin it.replace("Exception", "Error") Loading @@ -231,7 +218,7 @@ class SymbolVisitor( return when { isError -> builder.locatedIn(Errors) // Input shapes live with their Operations isInput -> builder.locatedIn(Operations) isIoShape -> builder.locatedIn(Operations) else -> builder.locatedIn(Shapes) }.build() } Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/StructureGenerator.kt +2 −3 Original line number Diff line number Diff line Loading @@ -98,7 +98,6 @@ class StructureGenerator( write("$memberName: \$T,", symbolProvider.toSymbol(member)) } } if (renderBuilder) { writer.rustBlock("impl ${symbol.name}") { docs("Creates a new builder-style object to manufacture \$D", symbol) Loading Loading @@ -140,8 +139,8 @@ class StructureGenerator( val outerType = memberSymbol.rustType() val coreType = outerType.stripOuter<RustType.Option>() val signature = when (coreType) { is RustType.String -> "<Str: Into<String>>(mut self, inp: Str) -> Self" is RustType.Box -> "<T>(mut self, inp: T) -> Self where T: Into<${coreType.render()}>" is RustType.String -> "(mut self, inp: impl Into<String>) -> Self" is RustType.Box -> "(mut self, inp: impl Into<${coreType.render()}>) -> Self" else -> "(mut self, inp: ${coreType.render()}) -> Self" } writer.documentShape(member, model) Loading codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/SymbolBuilderTest.kt +6 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.CsvSource import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.loader.ModelAssembler Loading @@ -31,12 +32,16 @@ import software.amazon.smithy.rust.codegen.smithy.Errors import software.amazon.smithy.rust.codegen.smithy.Operations import software.amazon.smithy.rust.codegen.smithy.Shapes import software.amazon.smithy.rust.codegen.smithy.isOptional import software.amazon.smithy.rust.codegen.smithy.referenceClosure import software.amazon.smithy.rust.codegen.smithy.rustType import software.amazon.smithy.rust.testutil.asSmithyModel import software.amazon.smithy.rust.testutil.testSymbolProvider class SymbolBuilderTest { private fun Symbol.referenceClosure(): List<Symbol> { val referencedSymbols = this.references.map { it.symbol } return listOf(this) + referencedSymbols.flatMap { it.referenceClosure() } } @Test fun `creates structures`() { val memberBuilder = MemberShape.builder().id("foo.bar#MyStruct\$someField").target("smithy.api#String") Loading Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt +3 −16 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import software.amazon.smithy.model.traits.HttpLabelTrait import software.amazon.smithy.rust.codegen.lang.RustType import software.amazon.smithy.rust.codegen.smithy.generators.toSnakeCase import software.amazon.smithy.rust.codegen.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.smithy.traits.SyntheticOutputTrait import software.amazon.smithy.utils.StringUtils // TODO: currently, respecting integer types. Loading @@ -55,20 +56,6 @@ val SimpleShapes = mapOf( StringShape::class to RustType.String ) // TODO: // Unions // Recursive shapes // Synthetics (blobs, timestamps) // Operation // Resources (do we do anything for resources?) // Services // Higher-level: Set, List, Map fun Symbol.referenceClosure(): List<Symbol> { val referencedSymbols = this.references.map { it.symbol } return listOf(this) + referencedSymbols.flatMap { it.referenceClosure() } } data class SymbolVisitorConfig( val runtimeConfig: RuntimeConfig, val handleOptionality: Boolean = true, Loading Loading @@ -222,7 +209,7 @@ class SymbolVisitor( override fun structureShape(shape: StructureShape): Symbol { val isError = shape.hasTrait(ErrorTrait::class.java) val isInput = shape.hasTrait(SyntheticInputTrait::class.java) val isIoShape = shape.hasTrait(SyntheticInputTrait::class.java) || shape.hasTrait(SyntheticOutputTrait::class.java) val name = StringUtils.capitalize(shape.id.name).letIf(isError) { // TODO: this is should probably be a configurable mixin it.replace("Exception", "Error") Loading @@ -231,7 +218,7 @@ class SymbolVisitor( return when { isError -> builder.locatedIn(Errors) // Input shapes live with their Operations isInput -> builder.locatedIn(Operations) isIoShape -> builder.locatedIn(Operations) else -> builder.locatedIn(Shapes) }.build() } Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/StructureGenerator.kt +2 −3 Original line number Diff line number Diff line Loading @@ -98,7 +98,6 @@ class StructureGenerator( write("$memberName: \$T,", symbolProvider.toSymbol(member)) } } if (renderBuilder) { writer.rustBlock("impl ${symbol.name}") { docs("Creates a new builder-style object to manufacture \$D", symbol) Loading Loading @@ -140,8 +139,8 @@ class StructureGenerator( val outerType = memberSymbol.rustType() val coreType = outerType.stripOuter<RustType.Option>() val signature = when (coreType) { is RustType.String -> "<Str: Into<String>>(mut self, inp: Str) -> Self" is RustType.Box -> "<T>(mut self, inp: T) -> Self where T: Into<${coreType.render()}>" is RustType.String -> "(mut self, inp: impl Into<String>) -> Self" is RustType.Box -> "(mut self, inp: impl Into<${coreType.render()}>) -> Self" else -> "(mut self, inp: ${coreType.render()}) -> Self" } writer.documentShape(member, model) Loading
codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/SymbolBuilderTest.kt +6 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.CsvSource import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.loader.ModelAssembler Loading @@ -31,12 +32,16 @@ import software.amazon.smithy.rust.codegen.smithy.Errors import software.amazon.smithy.rust.codegen.smithy.Operations import software.amazon.smithy.rust.codegen.smithy.Shapes import software.amazon.smithy.rust.codegen.smithy.isOptional import software.amazon.smithy.rust.codegen.smithy.referenceClosure import software.amazon.smithy.rust.codegen.smithy.rustType import software.amazon.smithy.rust.testutil.asSmithyModel import software.amazon.smithy.rust.testutil.testSymbolProvider class SymbolBuilderTest { private fun Symbol.referenceClosure(): List<Symbol> { val referencedSymbols = this.references.map { it.symbol } return listOf(this) + referencedSymbols.flatMap { it.referenceClosure() } } @Test fun `creates structures`() { val memberBuilder = MemberShape.builder().id("foo.bar#MyStruct\$someField").target("smithy.api#String") Loading