Skip to content

Commit

Permalink
Merge branch 'main' into harryb/improve-service-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hlbarber authored Nov 25, 2022
2 parents c9d0fa4 + a1fde3b commit 6d6f949
Show file tree
Hide file tree
Showing 68 changed files with 1,113 additions and 698 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,13 @@ message = """
* The `length` trait on `string` shapes.
* The `length` trait on `map` shapes.
* The `pattern` trait on `string` shapes.
Upon receiving a request that violates the modeled constraints, the server SDK will reject it with a message indicating why.
Unsupported (constraint trait, target shape) combinations will now fail at code generation time, whereas previously they were just ignored. This is a breaking change to raise awareness in service owners of their server SDKs behaving differently than what was modeled. To continue generating a server SDK with unsupported constraint traits, set `codegenConfig.ignoreUnsupportedConstraints` to `true` in your `smithy-build.json`.
"""
references = ["smithy-rs#1199", "smithy-rs#1342", "smithy-rs#1401"]
references = ["smithy-rs#1199", "smithy-rs#1342", "smithy-rs#1401", "smithy-rs#1998"]
meta = { "breaking" = true, "tada" = true, "bug" = false, "target" = "server" }
author = "david-perez"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class AwsFluentClientDecorator : RustCodegenDecorator<ClientProtocolGenerator, C
),
retryClassifier = runtimeConfig.awsHttp().toType().member("retry::AwsResponseRetryClassifier"),
).render(rustCrate)
rustCrate.withNonRootModule(CustomizableOperationGenerator.CUSTOMIZE_MODULE) {
rustCrate.withModule(CustomizableOperationGenerator.CustomizeModule) {
renderCustomizableOperationSendMethod(runtimeConfig, generics, this)
}
rustCrate.withModule(FluentClientGenerator.clientModule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ package software.amazon.smithy.rustsdk

import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency
import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility

object InlineAwsDependency {
fun forRustFile(file: String, visibility: Visibility = Visibility.PRIVATE, vararg additionalDependency: RustDependency): InlineDependency =
InlineDependency.Companion.forRustFile(file, "aws-inlineable", visibility, *additionalDependency)
InlineDependency.Companion.forRustFile(RustModule.new(file, visibility), "/aws-inlineable/src/$file.rs", *additionalDependency)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ 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.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
Expand Down Expand Up @@ -82,19 +80,9 @@ class CodegenVisitor(

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

val clientPublicModules = setOf(
RustModule.Error,
RustModule.Model,
RustModule.Input,
RustModule.Output,
RustModule.Config,
RustModule.Types,
RustModule.operation(Visibility.PUBLIC),
).associateBy { it.name }
rustCrate = RustCrate(
context.fileManifest,
symbolProvider,
clientPublicModules,
codegenContext.settings.codegenConfig,
)
protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators

import software.amazon.smithy.model.shapes.MemberShape
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
Expand All @@ -24,7 +22,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.protocols.lensName

/** Generator for accessing nested fields through optional values **/
class NestedAccessorGenerator(private val symbolProvider: RustSymbolProvider) {
private val module = RustModule("lens", RustMetadata(visibility = Visibility.PUBLIC), "Generated accessors for nested fields")
private val module = RustModule.private("lens", "Generated accessors for nested fields")

/**
* Generate an accessor on [root] that consumes [root] and returns an `Option<T>` for the nested item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import software.amazon.smithy.model.traits.IdempotencyTokenTrait
import software.amazon.smithy.model.traits.PaginatedTrait
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerics
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.render
import software.amazon.smithy.rust.codegen.core.rustlang.rust
Expand Down Expand Up @@ -78,11 +76,7 @@ class PaginatorGenerator private constructor(
private val idx = PaginatedIndex.of(model)
private val paginationInfo =
idx.getPaginationInfo(service, operation).orNull() ?: PANIC("failed to load pagination info")
private val module = RustModule(
"paginator",
RustMetadata(visibility = Visibility.PUBLIC),
documentation = "Paginators for the service",
)
private val module = RustModule.public("paginator", "Paginators for the service")

private val inputType = symbolProvider.toSymbol(operation.inputShape(model))
private val outputShape = operation.outputShape(model)
Expand All @@ -99,7 +93,12 @@ class PaginatorGenerator private constructor(
"generics" to generics.decl,
"bounds" to generics.bounds,
"page_size_setter" to pageSizeSetter(),
"send_bounds" to generics.sendBounds(symbolProvider.toSymbol(operation), outputType, errorType, retryClassifier),
"send_bounds" to generics.sendBounds(
symbolProvider.toSymbol(operation),
outputType,
errorType,
retryClassifier,
),

// Operation Types
"operation" to symbolProvider.toSymbol(operation),
Expand Down Expand Up @@ -288,7 +287,8 @@ class PaginatorGenerator private constructor(
private fun pageSizeSetter() = writable {
paginationInfo.pageSizeMember.orNull()?.also {
val memberName = symbolProvider.toMemberName(it)
val pageSizeT = symbolProvider.toSymbol(it).rustType().stripOuter<RustType.Option>().render(true)
val pageSizeT =
symbolProvider.toSymbol(it).rustType().stripOuter<RustType.Option>().render(true)
rust(
"""
/// Set the page size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ 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.docs
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
Expand All @@ -26,20 +24,16 @@ class CustomizableOperationGenerator(
private val generics: FluentClientGenerics,
private val includeFluentClient: Boolean,
) {

companion object {
const val CUSTOMIZE_MODULE = "crate::operation::customize"
val CustomizeModule = RustModule.public("customize", "Operation customization and supporting types", parent = RustModule.operation(Visibility.PUBLIC))
}

private val smithyHttp = CargoDependency.smithyHttp(runtimeConfig).toType()
private val smithyTypes = CargoDependency.smithyTypes(runtimeConfig).toType()

fun render(crate: RustCrate) {
crate.withModule(RustModule.operation(Visibility.PUBLIC)) {
docs("Operation customization and supporting types")
rust("pub mod customize;")
}

crate.withNonRootModule(CUSTOMIZE_MODULE) {
crate.withModule(CustomizeModule) {
rustTemplate(
"""
pub use #{Operation};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
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.asArgumentType
import software.amazon.smithy.rust.codegen.core.rustlang.asOptional
import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape
Expand Down Expand Up @@ -220,7 +221,7 @@ class FluentClientGenerator(
)
}
}
writer.withModule(RustModule.public("fluent_builders")) {
writer.withInlineModule(RustModule.new("fluent_builders", visibility = Visibility.PUBLIC, inline = true)) {
docs(
"""
Utilities to ergonomically construct a request to the service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ProtocolTestGenerator(
Attribute.Custom("allow(unreachable_code, unused_variables)"),
),
)
writer.withModule(RustModule(testModuleName, moduleMeta)) {
writer.withInlineModule(RustModule.LeafModule(testModuleName, moduleMeta, inline = true)) {
renderAllTestCases(allTests)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel

class SmithyTypesPubUseGeneratorTest {
private fun emptyModel() = modelWithMember()
private fun modelWithMember(
inputMember: String = "",
outputMember: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCusto
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext
import kotlin.io.path.createDirectory
import kotlin.io.path.writeText

class CodegenVisitorTest {
@Test
Expand Down Expand Up @@ -48,8 +46,6 @@ class CodegenVisitorTest {
}
""".asSmithyModel(smithyVersion = "2.0")
val (ctx, testDir) = generatePluginContext(model)
testDir.resolve("src").createDirectory()
testDir.resolve("src/main.rs").writeText("fn main() {}")
val codegenDecorator =
CombinedCodegenDecorator.fromClasspath(
ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import software.amazon.smithy.model.traits.SparseTrait
import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
import software.amazon.smithy.rust.codegen.core.rustlang.render
import software.amazon.smithy.rust.codegen.core.smithy.Errors
import software.amazon.smithy.rust.codegen.core.smithy.Models
import software.amazon.smithy.rust.codegen.core.smithy.Operations
import software.amazon.smithy.rust.codegen.core.smithy.ErrorsModule
import software.amazon.smithy.rust.codegen.core.smithy.ModelsModule
import software.amazon.smithy.rust.codegen.core.smithy.OperationsModule
import software.amazon.smithy.rust.codegen.core.smithy.isOptional
import software.amazon.smithy.rust.codegen.core.smithy.rustType
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
Expand All @@ -57,7 +57,7 @@ class SymbolVisitorTest {
val provider: SymbolProvider = testSymbolProvider(model)
val sym = provider.toSymbol(struct)
sym.rustType().render(false) shouldBe "MyStruct"
sym.definitionFile shouldContain Models.filename
sym.definitionFile shouldContain ModelsModule.definitionFile()
sym.namespace shouldBe "crate::model"
}

Expand All @@ -77,7 +77,7 @@ class SymbolVisitorTest {
val provider: SymbolProvider = testSymbolProvider(model)
val sym = provider.toSymbol(struct)
sym.rustType().render(false) shouldBe "TerribleError"
sym.definitionFile shouldContain Errors.filename
sym.definitionFile shouldContain ErrorsModule.definitionFile()
}

@Test
Expand All @@ -101,7 +101,7 @@ class SymbolVisitorTest {
val provider: SymbolProvider = testSymbolProvider(model)
val sym = provider.toSymbol(shape)
sym.rustType().render(false) shouldBe "StandardUnit"
sym.definitionFile shouldContain Models.filename
sym.definitionFile shouldContain ModelsModule.definitionFile()
sym.namespace shouldBe "crate::model"
}

Expand Down Expand Up @@ -260,7 +260,7 @@ class SymbolVisitorTest {
}
""".asSmithyModel()
val symbol = testSymbolProvider(model).toSymbol(model.expectShape(ShapeId.from("smithy.example#PutObject")))
symbol.definitionFile shouldBe("src/${Operations.filename}")
symbol.definitionFile shouldBe(OperationsModule.definitionFile())
symbol.name shouldBe "PutObject"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import software.amazon.smithy.model.traits.EndpointTrait
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest
import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider
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.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock
import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock
Expand Down Expand Up @@ -59,7 +58,7 @@ internal class EndpointTraitBindingsTest {
operationShape.expectTrait(EndpointTrait::class.java),
)
val project = TestWorkspace.testProject()
project.withModule(RustModule.default("test", visibility = Visibility.PRIVATE)) {
project.withModule(RustModule.private("test")) {
rust(
"""
struct GetStatusInput {
Expand Down
Loading

0 comments on commit 6d6f949

Please sign in to comment.