From 65e6ed90553f9d2f61c3b41865cbd7e3a9008869 Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Tue, 1 Nov 2022 15:59:50 -0500 Subject: [PATCH 01/19] move: all AWS decorators into a new decorators folder add: AwsCustomization NamedSectionGenerator add: AwsSection for `From for service::config::Builder` codegen rename: AwsCodegenDecorator to AwsCombinedCodegenDecorator add: new interface AwsCodegenDecorator that respects AwsCustomizations --- .../smithy/rustsdk/AwsCodegenDecorator.kt | 55 --------- .../amazon/smithy/rustsdk/AwsCustomization.kt | 22 ++++ .../decorators/AwsCombinedCodegenDecorator.kt | 104 ++++++++++++++++++ .../{ => decorators}/AwsEndpointDecorator.kt | 76 ++++++++----- .../AwsFluentClientDecorator.kt | 75 ++++++------- .../AwsPresigningDecorator.kt | 32 +++--- .../{ => decorators}/AwsReadmeDecorator.kt | 7 +- .../{ => decorators}/CrateLicenseDecorator.kt | 8 +- .../CredentialsProviderDecorator.kt} | 64 +++++++---- .../HttpRequestChecksumDecorator.kt | 18 +-- .../HttpResponseChecksumDecorator.kt | 2 +- .../IntegrationTestDecorator.kt} | 15 +-- .../{ => decorators}/RegionDecorator.kt | 42 ++++--- .../ResiliencyDecorator.kt} | 45 ++++++-- .../{ => decorators}/SdkConfigDecorator.kt | 31 +----- .../ServiceConfigDecorator.kt | 4 +- .../{ => decorators}/SigV4SigningDecorator.kt | 42 +++---- .../rustsdk/decorators/SleepImplDecorator.kt | 32 ++++++ .../{ => decorators}/UserAgentDecorator.kt | 47 +++++--- .../s3/S3Decorator.kt | 18 ++- ...ient.smithy.customize.RustCodegenDecorator | 2 +- 21 files changed, 450 insertions(+), 291 deletions(-) delete mode 100644 aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt create mode 100644 aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCustomization.kt create mode 100644 aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/AwsEndpointDecorator.kt (89%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/AwsFluentClientDecorator.kt (83%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/AwsPresigningDecorator.kt (93%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/AwsReadmeDecorator.kt (98%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/CrateLicenseDecorator.kt (85%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{CredentialProviders.kt => decorators/CredentialsProviderDecorator.kt} (69%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/HttpRequestChecksumDecorator.kt (93%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/HttpResponseChecksumDecorator.kt (99%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{IntegrationTestDependencies.kt => decorators/IntegrationTestDecorator.kt} (90%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/RegionDecorator.kt (83%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{RetryClassifierDecorator.kt => decorators/ResiliencyDecorator.kt} (56%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/SdkConfigDecorator.kt (66%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/ServiceConfigDecorator.kt (96%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/SigV4SigningDecorator.kt (87%) create mode 100644 aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{ => decorators}/UserAgentDecorator.kt (82%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/s3/S3Decorator.kt (92%) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt deleted file mode 100644 index aec623d221..0000000000 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.rustsdk - -import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customizations.DocsRsMetadataDecorator -import software.amazon.smithy.rust.codegen.client.smithy.customizations.DocsRsMetadataSettings -import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator -import software.amazon.smithy.rustsdk.customize.apigateway.ApiGatewayDecorator -import software.amazon.smithy.rustsdk.customize.auth.DisabledAuthDecorator -import software.amazon.smithy.rustsdk.customize.ec2.Ec2Decorator -import software.amazon.smithy.rustsdk.customize.glacier.GlacierDecorator -import software.amazon.smithy.rustsdk.customize.route53.Route53Decorator -import software.amazon.smithy.rustsdk.customize.s3.S3Decorator -import software.amazon.smithy.rustsdk.customize.sts.STSDecorator - -val DECORATORS = listOf( - // General AWS Decorators - CredentialsProviderDecorator(), - RegionDecorator(), - AwsEndpointDecorator(), - UserAgentDecorator(), - SigV4SigningDecorator(), - HttpRequestChecksumDecorator(), - HttpResponseChecksumDecorator(), - RetryClassifierDecorator(), - IntegrationTestDecorator(), - AwsFluentClientDecorator(), - CrateLicenseDecorator(), - SdkConfigDecorator(), - ServiceConfigDecorator(), - AwsPresigningDecorator(), - AwsReadmeDecorator(), - - // Service specific decorators - ApiGatewayDecorator(), - DisabledAuthDecorator(), - Ec2Decorator(), - GlacierDecorator(), - Route53Decorator(), - S3Decorator(), - STSDecorator(), - - // Only build docs-rs for linux to reduce load on docs.rs - DocsRsMetadataDecorator(DocsRsMetadataSettings(targets = listOf("x86_64-unknown-linux-gnu"), allFeatures = true)), -) - -class AwsCodegenDecorator : CombinedCodegenDecorator(DECORATORS) { - override val name: String = "AwsSdkCodegenDecorator" - override val order: Byte = -1 -} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCustomization.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCustomization.kt new file mode 100644 index 0000000000..5c23d23b2c --- /dev/null +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCustomization.kt @@ -0,0 +1,22 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rustsdk + +import software.amazon.smithy.rust.codegen.core.smithy.customize.NamedSectionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.customize.Section + +sealed class AwsSection(name: String) : Section(name) { + abstract val customizations: List + + /** + * Write custom code into the `impl From<&aws_types::sdk_config::SdkConfig> for Builder`. + * This `From` impl takes a reference; Don't forget to clone non-`Copy` types. + */ + data class FromSdkConfigForBuilder(override val customizations: List) : + AwsSection("FromSdkConfig") +} + +abstract class AwsCustomization : NamedSectionGenerator() diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt new file mode 100644 index 0000000000..41f5d429d5 --- /dev/null +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt @@ -0,0 +1,104 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rustsdk.decorators + +import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +import software.amazon.smithy.rust.codegen.client.smithy.customizations.DocsRsMetadataDecorator +import software.amazon.smithy.rust.codegen.client.smithy.customizations.DocsRsMetadataSettings +import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations +import software.amazon.smithy.rustsdk.AwsCustomization +import software.amazon.smithy.rustsdk.AwsSection +import software.amazon.smithy.rustsdk.awsTypes +import software.amazon.smithy.rustsdk.servicecustomizations.apigateway.ApiGatewayDecorator +import software.amazon.smithy.rustsdk.servicecustomizations.auth.DisabledAuthDecorator +import software.amazon.smithy.rustsdk.servicecustomizations.ec2.Ec2Decorator +import software.amazon.smithy.rustsdk.servicecustomizations.glacier.GlacierDecorator +import software.amazon.smithy.rustsdk.servicecustomizations.route53.Route53Decorator +import software.amazon.smithy.rustsdk.servicecustomizations.s3.S3Decorator +import software.amazon.smithy.rustsdk.servicecustomizations.sts.STSDecorator + +val DECORATORS = listOf( + // General AWS Decorators + AwsEndpointDecorator(), + AwsFluentClientDecorator(), + AwsPresigningDecorator(), + AwsReadmeDecorator(), + CrateLicenseDecorator(), + CredentialsProviderDecorator(), + HttpRequestChecksumDecorator(), + HttpResponseChecksumDecorator(), + IntegrationTestDecorator(), + RegionDecorator(), + ResiliencyDecorator(), + SdkConfigDecorator(), + ServiceConfigDecorator(), + SigV4SigningDecorator(), + SleepImplDecorator(), + UserAgentDecorator(), + + // Service specific decorators + ApiGatewayDecorator(), + DisabledAuthDecorator(), + Ec2Decorator(), + GlacierDecorator(), + Route53Decorator(), + S3Decorator(), + STSDecorator(), + + // Only build docs-rs for linux to reduce load on docs.rs + DocsRsMetadataDecorator(DocsRsMetadataSettings(targets = listOf("x86_64-unknown-linux-gnu"), allFeatures = true)), +) + +interface AwsCodegenDecorator : RustCodegenDecorator { + fun awsCustomizations( + codegenContext: ClientCodegenContext, + baseCustomizations: List, + ): List { + return baseCustomizations + } +} + +class AwsCombinedCodegenDecorator : + CombinedCodegenDecorator(DECORATORS) { + override val name: String = "AwsCombinedCodegen" + override val order: Byte = -1 + + override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { + super.extras(codegenContext, rustCrate) + + val awsCustomizations = orderedDecorators.filterIsInstance() + .foldRight(listOf()) { decorator, customizations -> + decorator.awsCustomizations(codegenContext, customizations) + } + generateImplFromRefSdkConfigForConfigBuilder(codegenContext.runtimeConfig, rustCrate, awsCustomizations) + } +} + +fun generateImplFromRefSdkConfigForConfigBuilder( + runtimeConfig: RuntimeConfig, + rustCrate: RustCrate, + customizations: List, +) { + val codegenContext = arrayOf("SdkConfig" to runtimeConfig.awsTypes().member("sdk_config::SdkConfig")) + + rustCrate.withModule(RustModule.Config) { + rustBlockTemplate("impl From<&#{SdkConfig}> for Builder", *codegenContext) { + rustBlockTemplate("fn from(input: &#{SdkConfig}) -> Self", *codegenContext) { + rust("let mut builder = Builder::default();") + writeCustomizations(customizations, AwsSection.FromSdkConfigForBuilder(customizations)) + rust("builder") + } + } + } +} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt similarity index 89% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt index 822dca09a1..87e2874706 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.aws.traits.ServiceTrait import software.amazon.smithy.codegen.core.CodegenException @@ -12,18 +12,15 @@ import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.node.StringNode import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable @@ -38,9 +35,14 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuild import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.orNull +import software.amazon.smithy.rustsdk.AwsCustomization +import software.amazon.smithy.rustsdk.AwsSection +import software.amazon.smithy.rustsdk.SdkSettings +import software.amazon.smithy.rustsdk.awsEndpoint +import software.amazon.smithy.rustsdk.awsTypes import kotlin.io.path.readText -class AwsEndpointDecorator : RustCodegenDecorator { +class AwsEndpointDecorator : AwsCodegenDecorator { override val name: String = "AwsEndpoint" override val order: Byte = 0 @@ -53,6 +55,7 @@ class AwsEndpointDecorator : RustCodegenDecorator path.readText() } endpointsCache = Node.parse(endpointsJson).expectObjectNode() @@ -75,7 +78,7 @@ class AwsEndpointDecorator : RustCodegenDecorator, ): List { - return baseCustomizations + EndpointResolverFeature(codegenContext.runtimeConfig, operation) + return baseCustomizations + EndpointResolverFeature(codegenContext.runtimeConfig) } override fun libRsCustomizations( @@ -85,6 +88,13 @@ class AwsEndpointDecorator : RustCodegenDecorator, + ): List { + return baseCustomizations + EndpointFromSdkConfig() + } + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } @@ -95,18 +105,13 @@ class EndpointConfigCustomization( ) : ConfigCustomization() { private val runtimeConfig = codegenContext.runtimeConfig - private val resolveAwsEndpoint = runtimeConfig.awsEndpoint().asType().copy(name = "ResolveAwsEndpoint") - private val smithyEndpointResolver = - CargoDependency.SmithyHttp(runtimeConfig).asType().member("endpoint::ResolveEndpoint") - private val placeholderEndpointParams = runtimeConfig.awsEndpoint().asType().member("Params") - private val endpointShim = runtimeConfig.awsEndpoint().asType().member("EndpointShim") private val moduleUseName = codegenContext.moduleUseName() private val codegenScope = arrayOf( - "SmithyResolver" to smithyEndpointResolver, - "PlaceholderParams" to placeholderEndpointParams, - "ResolveAwsEndpoint" to resolveAwsEndpoint, - "EndpointShim" to endpointShim, - "aws_types" to awsTypes(runtimeConfig).asType(), + "SmithyResolver" to runtimeConfig.smithyHttp().member("endpoint::ResolveEndpoint"), + "PlaceholderParams" to runtimeConfig.awsEndpoint().member("Params"), + "ResolveAwsEndpoint" to runtimeConfig.awsEndpoint().member("ResolveAwsEndpoint"), + "EndpointShim" to runtimeConfig.awsEndpoint().member("EndpointShim"), + "Region" to runtimeConfig.awsTypes().member("region::Region"), ) override fun section(section: ServiceConfig): Writable = writable { @@ -115,6 +120,7 @@ class EndpointConfigCustomization( "pub (crate) endpoint_resolver: std::sync::Arc>,", *codegenScope, ) + is ServiceConfig.ConfigImpl -> emptySection // TODO(https://github.com/awslabs/smithy-rs/issues/1780): Uncomment once endpoints 2.0 project is completed // rustTemplate( @@ -127,7 +133,11 @@ class EndpointConfigCustomization( // *codegenScope, // ) is ServiceConfig.BuilderStruct -> - rustTemplate("endpoint_resolver: Option>>,", *codegenScope) + rustTemplate( + "endpoint_resolver: Option>>,", + *codegenScope, + ) + ServiceConfig.BuilderImpl -> rustTemplate( """ @@ -138,7 +148,7 @@ class EndpointConfigCustomization( /// /// ## Examples /// ```no_run - /// use #{aws_types}::region::Region; + /// use #{Region}; /// use $moduleUseName::config::{Builder, Config}; /// use $moduleUseName::Endpoint; /// @@ -180,13 +190,13 @@ class EndpointConfigCustomization( // This is an experiment in a slightly different way to create runtime types. All code MAY be refactored to use this pattern -class EndpointResolverFeature(private val runtimeConfig: RuntimeConfig, private val operationShape: OperationShape) : - OperationCustomization() { - private val placeholderEndpointParams = runtimeConfig.awsEndpoint().asType().member("Params") +class EndpointResolverFeature(runtimeConfig: RuntimeConfig) : OperationCustomization() { private val codegenScope = arrayOf( - "PlaceholderParams" to placeholderEndpointParams, + "PlaceholderParams" to runtimeConfig.awsEndpoint().member("Params"), + "EndpointResult" to runtimeConfig.smithyHttp().member("endpoint::Result"), "BuildError" to runtimeConfig.operationBuildError(), ) + override fun section(section: OperationSection): Writable { return when (section) { is OperationSection.MutateRequest -> writable { @@ -195,13 +205,14 @@ class EndpointResolverFeature(private val runtimeConfig: RuntimeConfig, private """ let endpoint_params = #{PlaceholderParams}::new(${section.config}.region.clone()); ${section.request}.properties_mut() - .insert::(${section.config} + .insert::<#{EndpointResult}>(${section.config} .endpoint_resolver .resolve_endpoint(&endpoint_params)); """, *codegenScope, ) } + else -> emptySection } } @@ -212,10 +223,11 @@ class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat return when (section) { is LibRsSection.Body -> writable { rust( - "pub use #T::endpoint::Endpoint;", - CargoDependency.SmithyHttp(runtimeConfig).asType(), + "pub use #T;", + runtimeConfig.smithyHttp().member("endpoint::Endpoint"), ) } + else -> emptySection } } @@ -224,8 +236,8 @@ class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat class EndpointResolverGenerator(codegenContext: CodegenContext, private val endpointData: ObjectNode) { private val runtimeConfig = codegenContext.runtimeConfig private val endpointPrefix = codegenContext.serviceShape.expectTrait().endpointPrefix - private val awsEndpoint = runtimeConfig.awsEndpoint().asType() - private val awsTypes = runtimeConfig.awsTypes().asType() + private val awsEndpoint = runtimeConfig.awsEndpoint() + private val awsTypes = runtimeConfig.awsTypes() private val codegenScope = arrayOf( "Partition" to awsEndpoint.member("Partition"), @@ -436,3 +448,11 @@ class EndpointResolverGenerator(codegenContext: CodegenContext, private val endp } } } + +class EndpointFromSdkConfig : AwsCustomization() { + override fun section(section: AwsSection): Writable = writable { + when (section) { + is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_endpoint_resolver(input.endpoint_resolver().clone());") + } + } +} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt similarity index 83% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt index bbdb9d80a5..4d8af2f257 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.shapes.ShapeId @@ -17,17 +17,17 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.client.Fluen import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientSection import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope import software.amazon.smithy.rust.codegen.core.rustlang.Feature 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.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyClient +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig @@ -37,25 +37,23 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomiza import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware +import software.amazon.smithy.rustsdk.SdkSettings +import software.amazon.smithy.rustsdk.awsConfig +import software.amazon.smithy.rustsdk.awsHttp +import software.amazon.smithy.rustsdk.awsTypes private class Types(runtimeConfig: RuntimeConfig) { - private val smithyTypesDep = CargoDependency.SmithyTypes(runtimeConfig) - private val smithyClientDep = CargoDependency.SmithyClient(runtimeConfig) - private val smithyHttpDep = CargoDependency.SmithyHttp(runtimeConfig) - - val awsTypes = awsTypes(runtimeConfig).asType() - val smithyClientRetry = RuntimeType("retry", smithyClientDep, "aws_smithy_client") - val awsSmithyClient = smithyClientDep.asType() - - val connectorSettings = RuntimeType("ConnectorSettings", smithyClientDep, "aws_smithy_client::http_connector") + val clientBuilder = runtimeConfig.smithyClient().member("Builder") + val connectorError = runtimeConfig.smithyHttp().member("result::ConnectorError") + val connectorSettings = runtimeConfig.smithyClient().member("http_connector::ConnectorSettings") val defaultMiddleware = runtimeConfig.defaultMiddleware() - val dynConnector = RuntimeType("DynConnector", smithyClientDep, "aws_smithy_client::erase") - val dynMiddleware = RuntimeType("DynMiddleware", smithyClientDep, "aws_smithy_client::erase") - val retryConfig = RuntimeType("RetryConfig", smithyTypesDep, "aws_smithy_types::retry") - val smithyConnector = RuntimeType("SmithyConnector", smithyClientDep, "aws_smithy_client::bounds") - val timeoutConfig = RuntimeType("TimeoutConfig", smithyTypesDep, "aws_smithy_types::timeout") - - val connectorError = RuntimeType("ConnectorError", smithyHttpDep, "aws_smithy_http::result") + val dynConnector = runtimeConfig.smithyClient().member("erase::DynConnector") + val dynMiddleware = runtimeConfig.smithyClient().member("erase::DynMiddleware") + val retryConfig = runtimeConfig.smithyTypes().member("retry::RetryConfig") + val sdkConfig = runtimeConfig.awsTypes().member("SdkConfig") + val smithyClientRetry = runtimeConfig.smithyClient().member("retry") + val smithyConnector = runtimeConfig.smithyClient().member("bounds::SmithyConnector") + val timeoutConfig = runtimeConfig.smithyTypes().member("timeout::TimeoutConfig") } private class AwsClientGenerics(private val types: Types) : FluentClientGenerics { @@ -83,14 +81,13 @@ private class AwsClientGenerics(private val types: Types) : FluentClientGenerics operationOutput: Symbol, operationError: RuntimeType, retryClassifier: RuntimeType, - ): Writable = - writable { } + ): Writable = writable { } override fun toRustGenerics() = RustGenerics() } class AwsFluentClientDecorator : RustCodegenDecorator { - override val name: String = "FluentClient" + override val name: String = "AwsFluentClient" // Must run after the AwsPresigningDecorator so that the presignable trait is correctly added to operations override val order: Byte = (AwsPresigningDecorator.ORDER + 1).toByte() @@ -106,7 +103,7 @@ class AwsFluentClientDecorator : RustCodegenDecorator Self { + pub fn new(sdk_config: &#{SdkConfig}) -> Self { Self::from_conf(sdk_config.into()) } @@ -192,7 +188,7 @@ private class AwsFluentClientExtensions(types: Types) { panic!("An async sleep implementation is required for retries or timeouts to work. \ Set the `sleep_impl` on the Config passed into this function to fix this panic."); } - let mut builder = #{aws_smithy_client}::Builder::new() + let mut builder = #{ClientBuilder}::new() .dyn_https_connector(#{ConnectorSettings}::from_timeout_config(&timeout_config)) .middleware(#{DynMiddleware}::new(#{Middleware}::new())) .retry_config(retry_config.into()) @@ -210,11 +206,10 @@ private class AwsFluentClientExtensions(types: Types) { } private class AwsFluentClientDocs(private val codegenContext: CodegenContext) : FluentClientCustomization() { - private val serviceName = codegenContext.serviceShape.expectTrait().value private val serviceShape = codegenContext.serviceShape + private val serviceName = serviceShape.expectTrait().value private val crateName = codegenContext.moduleUseName() - private val codegenScope = - arrayOf("aws_config" to codegenContext.runtimeConfig.awsConfig().copy(scope = DependencyScope.Dev).asType()) + private val runtimeConfig = codegenContext.runtimeConfig // If no `aws-config` version is provided, assume that docs referencing `aws-config` cannot be given. // Also, STS and SSO must NOT reference `aws-config` since that would create a circular dependency. @@ -264,7 +259,7 @@ private class AwsFluentClientDocs(private val codegenContext: CodegenContext) : /// let client = $crateName::Client::from_conf(config); /// ## } """, - *codegenScope, + "aws_config" to runtimeConfig.awsConfig(), ) } } @@ -279,8 +274,6 @@ private fun renderCustomizableOperationSendMethod( generics: FluentClientGenerics, writer: RustWriter, ) { - val smithyHttp = CargoDependency.SmithyHttp(runtimeConfig).asType() - val operationGenerics = RustGenerics(GenericTypeArg("O"), GenericTypeArg("Retry")) val handleGenerics = generics.toRustGenerics() val combinedGenerics = operationGenerics + handleGenerics @@ -288,9 +281,9 @@ private fun renderCustomizableOperationSendMethod( val codegenScope = arrayOf( "combined_generics_decl" to combinedGenerics.declaration(), "handle_generics_bounds" to handleGenerics.bounds(), - "SdkSuccess" to smithyHttp.member("result::SdkSuccess"), - "ClassifyRetry" to smithyHttp.member("retry::ClassifyRetry"), - "ParseHttpResponse" to smithyHttp.member("response::ParseHttpResponse"), + "SdkSuccess" to runtimeConfig.smithyHttp().member("result::SdkSuccess"), + "ClassifyRetry" to runtimeConfig.smithyHttp().member("retry::ClassifyRetry"), + "ParseHttpResponse" to runtimeConfig.smithyHttp().member("response::ParseHttpResponse"), ) writer.rustTemplate( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsPresigningDecorator.kt similarity index 93% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsPresigningDecorator.kt index a65cb4fcae..cb7e8ce9d3 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsPresigningDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.model.Model import software.amazon.smithy.model.knowledge.HttpBinding @@ -30,6 +30,7 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -42,7 +43,10 @@ import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBoundProtoc import software.amazon.smithy.rust.codegen.core.util.cloneOperation import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait +import software.amazon.smithy.rustsdk.AwsRuntimeType import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware +import software.amazon.smithy.rustsdk.awsSigAuth +import software.amazon.smithy.rustsdk.awsSigv4 import software.amazon.smithy.rustsdk.traits.PresignableTrait import kotlin.streams.toList @@ -109,7 +113,7 @@ class AwsPresigningDecorator internal constructor( val intermediate = ModelTransformer.create().mapShapes(modelWithSynthetics) { shape -> if (shape is OperationShape && presignableOperations.containsKey(shape.id)) { presignableTransforms.addAll(presignableOperations.getValue(shape.id).modelTransforms) - shape.toBuilder().addTrait(PresignableTrait(syntheticShapeId(shape))).build() + shape.toBuilder().addTrait(PresignableTrait()).build() } else { shape } @@ -145,9 +149,9 @@ class AwsInputPresignedMethod( "PresignedRequest" to AwsRuntimeType.Presigning.member("request::PresignedRequest"), "PresignedRequestService" to AwsRuntimeType.Presigning.member("service::PresignedRequestService"), "PresigningConfig" to AwsRuntimeType.Presigning.member("config::PresigningConfig"), - "SdkError" to CargoDependency.SmithyHttp(runtimeConfig).asType().member("result::SdkError"), - "aws_sigv4" to runtimeConfig.awsRuntimeDependency("aws-sigv4").asType(), - "sig_auth" to runtimeConfig.sigAuth().asType(), + "SdkError" to runtimeConfig.smithyHttp().member("result::SdkError"), + "aws_sigv4" to runtimeConfig.awsSigv4(), + "sig_auth" to runtimeConfig.awsSigAuth(), "tower" to CargoDependency.Tower.asType(), "Middleware" to runtimeConfig.defaultMiddleware(), ) @@ -253,7 +257,7 @@ class AwsPresignedFluentBuilderMethod( "Error" to AwsRuntimeType.Presigning.member("config::Error"), "PresignedRequest" to AwsRuntimeType.Presigning.member("request::PresignedRequest"), "PresigningConfig" to AwsRuntimeType.Presigning.member("config::PresigningConfig"), - "SdkError" to CargoDependency.SmithyHttp(runtimeConfig).asType().member("result::SdkError"), + "SdkError" to runtimeConfig.smithyHttp().member("result::SdkError"), ) override fun section(section: FluentClientSection): Writable = @@ -262,19 +266,19 @@ class AwsPresignedFluentBuilderMethod( documentPresignedMethod(hasConfigArg = false) rustBlockTemplate( """ - pub async fn presigned( - self, - presigning_config: #{PresigningConfig}, - ) -> Result<#{PresignedRequest}, #{SdkError}<#{OpError}>> - """, + pub async fn presigned( + self, + presigning_config: #{PresigningConfig}, + ) -> Result<#{PresignedRequest}, #{SdkError}<#{OpError}>> + """, *codegenScope, "OpError" to section.operationErrorType, ) { rustTemplate( """ - let input = self.inner.build().map_err(|err| #{SdkError}::ConstructionFailure(err.into()))?; - input.presigned(&self.handle.conf, presigning_config).await - """, + let input = self.inner.build().map_err(|err| #{SdkError}::ConstructionFailure(err.into()))?; + input.presigned(&self.handle.conf, presigning_config).await + """, *codegenScope, ) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsReadmeDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsReadmeDecorator.kt similarity index 98% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsReadmeDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsReadmeDecorator.kt index 666fc342e1..b28017843c 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsReadmeDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsReadmeDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import org.jsoup.Jsoup import org.jsoup.nodes.Element @@ -17,6 +17,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.generators.ManifestCustomizations import software.amazon.smithy.rust.codegen.core.util.getTrait +import software.amazon.smithy.rustsdk.SdkSettings import java.util.logging.Logger // Use a sigil that should always be unique in the text to fix line breaks and spaces @@ -28,7 +29,7 @@ private const val SPACE_SIGIL = "[[smithy-rs-nbsp]]" * Generates a README.md for each service crate for display on crates.io. */ class AwsReadmeDecorator : RustCodegenDecorator { - override val name: String = "AwsReadmeDecorator" + override val name: String = "AwsReadme" override val order: Byte = 0 override fun supportsCodegenContext(clazz: Class): Boolean = @@ -218,7 +219,7 @@ internal class AwsSdkReadmeGenerator { private fun Element.normalizeLists() { (getElementsByTag("ul") + getElementsByTag("ol")) // Only operate on lists that are top-level (are not nested within other lists) - .filter { list -> list.parents().none() { it.isList() } } + .filter { list -> list.parents().none { it.isList() } } .forEach { list -> list.normalizeList() } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CrateLicenseDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CrateLicenseDecorator.kt similarity index 85% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CrateLicenseDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CrateLicenseDecorator.kt index b1847809ed..360de696a1 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CrateLicenseDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CrateLicenseDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator @@ -14,13 +14,13 @@ import software.amazon.smithy.rust.codegen.core.smithy.RustCrate class CrateLicenseDecorator : RustCodegenDecorator { override val name: String = "CrateLicense" - override val order: Byte = 0 override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { rustCrate.withFile("LICENSE") { - val license = this::class.java.getResource("/LICENSE").readText() - raw(license) + this::class.java.getResource("/LICENSE")?.readText()?.let { license -> + raw(license) + } } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CredentialsProviderDecorator.kt similarity index 69% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CredentialsProviderDecorator.kt index 304195588c..3755eb80fe 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CredentialsProviderDecorator.kt @@ -3,16 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType 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.rustlang.writable @@ -23,8 +20,13 @@ import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustom import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection +import software.amazon.smithy.rustsdk.AwsCustomization +import software.amazon.smithy.rustsdk.AwsSection +import software.amazon.smithy.rustsdk.InlineAwsDependency +import software.amazon.smithy.rustsdk.awsHttp +import software.amazon.smithy.rustsdk.awsTypes -class CredentialsProviderDecorator : RustCodegenDecorator { +class CredentialsProviderDecorator : AwsCodegenDecorator { override val name: String = "CredentialsProvider" override val order: Byte = 0 @@ -50,6 +52,13 @@ class CredentialsProviderDecorator : RustCodegenDecorator, + ): List { + return baseCustomizations + CredentialsFromSdkConfig() + } + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } @@ -58,40 +67,45 @@ class CredentialsProviderDecorator : RustCodegenDecorator rustTemplate( - """pub(crate) credentials_provider: #{credentials}::SharedCredentialsProvider,""", + """pub(crate) credentials_provider: #{SharedCredentialsProvider},""", *codegenScope, ) + is ServiceConfig.ConfigImpl -> rustTemplate( """ /// Returns the credentials provider. - pub fn credentials_provider(&self) -> #{credentials}::SharedCredentialsProvider { + pub fn credentials_provider(&self) -> #{SharedCredentialsProvider} { self.credentials_provider.clone() } """, *codegenScope, ) + is ServiceConfig.BuilderStruct -> - rustTemplate("credentials_provider: Option<#{credentials}::SharedCredentialsProvider>,", *codegenScope) + rustTemplate("credentials_provider: Option<#{SharedCredentialsProvider}>,", *codegenScope) + ServiceConfig.BuilderImpl -> { rustTemplate( """ /// Sets the credentials provider for this service - pub fn credentials_provider(mut self, credentials_provider: impl #{credentials}::ProvideCredentials + 'static) -> Self { - self.credentials_provider = Some(#{credentials}::SharedCredentialsProvider::new(credentials_provider)); + pub fn credentials_provider(mut self, credentials_provider: impl #{ProvideCredentials} + 'static) -> Self { + self.credentials_provider = Some(#{SharedCredentialsProvider}::new(credentials_provider)); self } /// Sets the credentials provider for this service - pub fn set_credentials_provider(&mut self, credentials_provider: Option<#{credentials}::SharedCredentialsProvider>) -> &mut Self { + pub fn set_credentials_provider(&mut self, credentials_provider: Option<#{SharedCredentialsProvider}>) -> &mut Self { self.credentials_provider = credentials_provider; self } @@ -101,9 +115,11 @@ class CredentialProviderConfig(runtimeConfig: RuntimeConfig) : ConfigCustomizati } ServiceConfig.BuilderBuild -> rustTemplate( - "credentials_provider: self.credentials_provider.unwrap_or_else(|| #{credentials}::SharedCredentialsProvider::new(#{DefaultProvider})),", + "credentials_provider: self.credentials_provider.unwrap_or_else(|| #{SharedCredentialsProvider}::new(#{DefaultProvider})),", *codegenScope, ) + + else -> emptySection } } } @@ -116,7 +132,7 @@ class CredentialsProviderFeature(private val runtimeConfig: RuntimeConfig) : Ope """ #T(&mut ${section.request}.properties_mut(), ${section.config}.credentials_provider.clone()); """, - setProvider(runtimeConfig), + runtimeConfig.awsHttp().member("auth::set_provider"), ) } @@ -130,8 +146,8 @@ class PubUseCredentials(private val runtimeConfig: RuntimeConfig) : LibRsCustomi return when (section) { is LibRsSection.Body -> writable { rust( - "pub use #T::Credentials;", - awsTypes(runtimeConfig).asType(), + "pub use #T;", + runtimeConfig.awsTypes().member("Credentials"), ) } @@ -140,10 +156,10 @@ class PubUseCredentials(private val runtimeConfig: RuntimeConfig) : LibRsCustomi } } -fun awsHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeDependency("aws-http") - -fun defaultProvider() = - RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("no_credentials")).member("NoCredentials") - -fun setProvider(runtimeConfig: RuntimeConfig) = - RuntimeType("set_provider", awsHttp(runtimeConfig), "aws_http::auth") +class CredentialsFromSdkConfig : AwsCustomization() { + override fun section(section: AwsSection): Writable = writable { + when (section) { + is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_credentials_provider(input.credentials_provider().cloned());") + } + } +} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt similarity index 93% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt index a14c9843cb..49d351c863 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.aws.traits.HttpChecksumTrait import software.amazon.smithy.model.shapes.OperationShape @@ -13,9 +13,9 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.Cli import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.asType 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.rustlang.smithyChecksums import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType @@ -26,19 +26,21 @@ import software.amazon.smithy.rust.codegen.core.util.expectMember import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.orNull +import software.amazon.smithy.rustsdk.InlineAwsDependency +import software.amazon.smithy.rustsdk.awsRuntimeCrate fun RuntimeConfig.awsInlineableBodyWithChecksum() = RuntimeType.forInlineDependency( InlineAwsDependency.forRustFile( "http_body_checksum", visibility = Visibility.PUBLIC, CargoDependency.Http, CargoDependency.HttpBody, - CargoDependency.SmithyHttp(this), - CargoDependency.SmithyChecksums(this), - CargoDependency.SmithyTypes(this), + CargoDependency.smithyHttp(this), + CargoDependency.smithyChecksums(this), + CargoDependency.smithyTypes(this), CargoDependency.Bytes, CargoDependency.Tracing, - this.sigAuth(), - this.awsHttp(), + this.awsRuntimeCrate("aws-sig-auth"), + this.smithyRuntimeCrate("smithy-http"), ), ) @@ -105,7 +107,7 @@ private fun HttpChecksumTrait.checksumAlgorithmToStr( }; """, "BuildError" to runtimeConfig.operationBuildError(), - "ChecksumAlgorithm" to CargoDependency.SmithyChecksums(runtimeConfig).asType().member("ChecksumAlgorithm"), + "ChecksumAlgorithm" to runtimeConfig.smithyChecksums().member("ChecksumAlgorithm"), ) // If a request checksum is not required and there's no way to set one, do nothing diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpResponseChecksumDecorator.kt similarity index 99% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpResponseChecksumDecorator.kt index c695c5c407..8beafbcad9 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpResponseChecksumDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.aws.traits.HttpChecksumTrait import software.amazon.smithy.model.shapes.MemberShape diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt similarity index 90% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt index 76d42c8255..13fa1f0355 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator @@ -19,6 +19,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection +import software.amazon.smithy.rustsdk.SdkSettings import java.nio.file.Files import java.nio.file.Paths @@ -65,10 +66,10 @@ class IntegrationTestDependencies( override fun section(section: LibRsSection) = when (section) { is LibRsSection.Body -> writable { if (hasTests) { - val smithyClient = CargoDependency.SmithyClient(runtimeConfig) + val smithyClient = CargoDependency.smithyClient(runtimeConfig) .copy(features = setOf("test-util"), scope = DependencyScope.Dev) addDependency(smithyClient) - addDependency(CargoDependency.SmithyProtocolTestHelpers(runtimeConfig)) + addDependency(CargoDependency.smithyProtocolTestHelpers(runtimeConfig)) addDependency(SerdeJson) addDependency(Tokio) addDependency(FuturesUtil) @@ -110,10 +111,10 @@ class S3TestDependencies( addDependency(BytesUtils) addDependency(Smol) addDependency(TempFile) - runtimeConfig.runtimeCrate("async", scope = DependencyScope.Dev) - runtimeConfig.runtimeCrate("client", scope = DependencyScope.Dev) - runtimeConfig.runtimeCrate("http", scope = DependencyScope.Dev) - runtimeConfig.runtimeCrate("types", scope = DependencyScope.Dev) + runtimeConfig.smithyRuntimeCrate("smithy-async", scope = DependencyScope.Dev) + runtimeConfig.smithyRuntimeCrate("smithy-client", scope = DependencyScope.Dev) + runtimeConfig.smithyRuntimeCrate("smithy-http", scope = DependencyScope.Dev) + runtimeConfig.smithyRuntimeCrate("smithy-types", scope = DependencyScope.Dev) } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt similarity index 83% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt index d57d379f2c..4ec3e3d5c3 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt @@ -3,25 +3,25 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator 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 import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection +import software.amazon.smithy.rustsdk.AwsCustomization +import software.amazon.smithy.rustsdk.AwsSection +import software.amazon.smithy.rustsdk.awsTypes /* Example Generated Code */ /* @@ -71,7 +71,7 @@ fn test_1() { } */ -class RegionDecorator : RustCodegenDecorator { +class RegionDecorator : AwsCodegenDecorator { override val name: String = "Region" override val order: Byte = 0 @@ -97,14 +97,21 @@ class RegionDecorator : RustCodegenDecorator, + ): List { + return baseCustomizations + RegionFromSdkConfig() + } + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } class RegionProviderConfig(codegenContext: CodegenContext) : ConfigCustomization() { - private val region = region(codegenContext.runtimeConfig) + private val runtimeConfig = codegenContext.runtimeConfig private val moduleUseName = codegenContext.moduleUseName() - private val codegenScope = arrayOf("Region" to region.member("Region")) + private val codegenScope = arrayOf("Region" to runtimeConfig.awsTypes().member("region::Region")) override fun section(section: ServiceConfig) = writable { when (section) { is ServiceConfig.ConfigStruct -> rustTemplate("pub(crate) region: Option<#{Region}>,", *codegenScope) @@ -119,7 +126,7 @@ class RegionProviderConfig(codegenContext: CodegenContext) : ConfigCustomization ) is ServiceConfig.BuilderStruct -> rustTemplate("region: Option<#{Region}>,", *codegenScope) - ServiceConfig.BuilderImpl -> + is ServiceConfig.BuilderImpl -> rustTemplate( """ /// Sets the AWS region to use when making requests. @@ -140,11 +147,11 @@ class RegionProviderConfig(codegenContext: CodegenContext) : ConfigCustomization """, *codegenScope, ) - - ServiceConfig.BuilderBuild -> rustTemplate( + is ServiceConfig.BuilderBuild -> rustTemplate( """region: self.region,""", *codegenScope, ) + else -> emptySection } } } @@ -172,8 +179,8 @@ class PubUseRegion(private val runtimeConfig: RuntimeConfig) : LibRsCustomizatio return when (section) { is LibRsSection.Body -> writable { rust( - "pub use #T::Region;", - region(runtimeConfig), + "pub use #T;", + runtimeConfig.awsTypes().member("region::Region"), ) } else -> emptySection @@ -181,7 +188,10 @@ class PubUseRegion(private val runtimeConfig: RuntimeConfig) : LibRsCustomizatio } } -fun region(runtimeConfig: RuntimeConfig) = - RuntimeType("region", awsTypes(runtimeConfig), "aws_types") - -fun awsTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeDependency("aws-types") +class RegionFromSdkConfig : AwsCustomization() { + override fun section(section: AwsSection): Writable = writable { + when (section) { + is AwsSection.FromSdkConfigForBuilder -> rust("builder = builder.region(input.region().cloned());") + } + } +} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RetryClassifierDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt similarity index 56% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RetryClassifierDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt index 4d1aa4973d..c72d5002f2 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RetryClassifierDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt @@ -1,15 +1,8 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator -import software.amazon.smithy.rust.codegen.core.rustlang.asType +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.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -17,9 +10,12 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rustsdk.AwsCustomization +import software.amazon.smithy.rustsdk.AwsSection +import software.amazon.smithy.rustsdk.awsHttp -class RetryClassifierDecorator : RustCodegenDecorator { - override val name: String = "RetryPolicy" +class ResiliencyDecorator : AwsCodegenDecorator { + override val name: String = "Resiliency" override val order: Byte = 0 override fun operationCustomizations( @@ -30,12 +26,21 @@ class RetryClassifierDecorator : RustCodegenDecorator, + ): List { + return baseCustomizations + + RetryConfigFromSdkConfig() + + TimeoutConfigFromSdkConfig() + } + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } class RetryClassifierFeature(private val runtimeConfig: RuntimeConfig) : OperationCustomization() { - override fun retryType(): RuntimeType = runtimeConfig.awsHttp().asType().member("retry::AwsResponseRetryClassifier") + override fun retryType(): RuntimeType = runtimeConfig.awsHttp().member("retry::AwsResponseRetryClassifier") override fun section(section: OperationSection) = when (section) { is OperationSection.FinalizeOperation -> writable { rust( @@ -46,3 +51,19 @@ class RetryClassifierFeature(private val runtimeConfig: RuntimeConfig) : Operati else -> emptySection } } + +class RetryConfigFromSdkConfig : AwsCustomization() { + override fun section(section: AwsSection): Writable = writable { + when (section) { + is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_retry_config(input.retry_config().cloned());") + } + } +} + +class TimeoutConfigFromSdkConfig : AwsCustomization() { + override fun section(section: AwsSection): Writable = writable { + when (section) { + is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_timeout_config(input.timeout_config().cloned());") + } + } +} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkConfigDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt similarity index 66% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkConfigDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt index 5a4135429c..0bf7adc046 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkConfigDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator @@ -12,12 +12,12 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.config.Servi import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rustsdk.awsTypes /** * Adds functionality for constructing `::Config` objects from `aws_types::SdkConfig`s @@ -37,34 +37,16 @@ class SdkConfigDecorator : RustCodegenDecorator for Builder { - fn from(input: &#{SdkConfig}) -> Self { - let mut builder = Builder::default(); - builder = builder.region(input.region().cloned()); - builder.set_endpoint_resolver(input.endpoint_resolver().clone()); - builder.set_retry_config(input.retry_config().cloned()); - builder.set_timeout_config(input.timeout_config().cloned()); - builder.set_sleep_impl(input.sleep_impl()); - builder.set_credentials_provider(input.credentials_provider().cloned()); - builder.set_app_name(input.app_name().cloned()); - builder - } - } - impl From<&#{SdkConfig}> for Config { fn from(sdk_config: &#{SdkConfig}) -> Self { Builder::from(sdk_config).build() } } """, - *codegenScope, + "SdkConfig" to codegenContext.runtimeConfig.awsTypes().member("sdk_config::SdkConfig"), ) } } @@ -73,10 +55,7 @@ class SdkConfigDecorator : RustCodegenDecorator writable { @@ -87,7 +66,7 @@ class NewFromShared(runtimeConfig: RuntimeConfig) : ConfigCustomization() { Builder::from(config).build() } """, - *codegenScope, + "SdkConfig" to runtimeConfig.awsTypes().member("sdk_config::SdkConfig"), ) } else -> emptySection diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/ServiceConfigDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ServiceConfigDecorator.kt similarity index 96% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/ServiceConfigDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ServiceConfigDecorator.kt index e8729060e8..2f10cf14cd 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/ServiceConfigDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ServiceConfigDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator @@ -16,7 +16,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext class ServiceConfigDecorator : RustCodegenDecorator { - override val name: String = "ServiceConfigGenerator" + override val name: String = "ServiceConfig" override val order: Byte = 0 override fun configCustomizations( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4SigningDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt similarity index 87% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4SigningDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt index 97b8813bfb..9c5a5018df 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4SigningDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.aws.traits.auth.SigV4Trait import software.amazon.smithy.aws.traits.auth.UnsignedPayloadTrait @@ -19,13 +19,11 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.config.Confi import software.amazon.smithy.rust.codegen.client.smithy.generators.config.EventStreamSigningConfig import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType 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.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.dq @@ -34,6 +32,9 @@ import software.amazon.smithy.rust.codegen.core.util.hasEventStreamOperations import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.isInputEventStream import software.amazon.smithy.rust.codegen.core.util.letIf +import software.amazon.smithy.rustsdk.awsSigAuth +import software.amazon.smithy.rustsdk.awsSigAuthEventStream +import software.amazon.smithy.rustsdk.awsTypes /** * The SigV4SigningDecorator: @@ -87,11 +88,7 @@ class SigV4SigningConfig( private val sigV4Trait: SigV4Trait, ) : EventStreamSigningConfig(runtimeConfig) { private val codegenScope = arrayOf( - "SigV4Signer" to RuntimeType( - "SigV4Signer", - runtimeConfig.awsRuntimeDependency("aws-sig-auth", setOf("sign-eventstream")), - "aws_sig_auth::event_stream", - ), + "SigV4Signer" to runtimeConfig.awsSigAuthEventStream().member("event_stream::SigV4Signer"), ) override fun configImplSection(): Writable { @@ -144,10 +141,14 @@ class SigV4SigningFeature( private val operation: OperationShape, runtimeConfig: RuntimeConfig, private val service: ServiceShape, -) : - OperationCustomization() { - private val codegenScope = - arrayOf("sig_auth" to runtimeConfig.sigAuth().asType(), "aws_types" to awsTypes(runtimeConfig).asType()) +) : OperationCustomization() { + private val codegenScope = arrayOf( + "OperationSigningConfig" to runtimeConfig.awsSigAuth().member("signer::OperationSigningConfig"), + "SignableBody" to runtimeConfig.awsSigAuth().member("signer::SignableBody"), + "SigningRegion" to runtimeConfig.awsTypes().member("region::SigningRegion"), + "SigningRequirements" to runtimeConfig.awsSigAuth().member("signer::SigningRequirements"), + "SigningService" to runtimeConfig.awsTypes().member("SigningService"), + ) private val serviceIndex = ServiceIndex.of(model) @@ -155,7 +156,7 @@ class SigV4SigningFeature( return when (section) { is OperationSection.MutateRequest -> writable { rustTemplate( - "let mut signing_config = #{sig_auth}::signer::OperationSigningConfig::default_config();", + "let mut signing_config = #{OperationSigningConfig}::default_config();", *codegenScope, ) if (needsAmzSha256(service)) { @@ -167,13 +168,13 @@ class SigV4SigningFeature( if (operation.hasTrait()) { rust("signing_config.signing_options.content_sha256_header = true;") rustTemplate( - "${section.request}.properties_mut().insert(#{sig_auth}::signer::SignableBody::UnsignedPayload);", + "${section.request}.properties_mut().insert(#{SignableBody}::UnsignedPayload);", *codegenScope, ) } else if (operation.isInputEventStream(model)) { // TODO(EventStream): Is this actually correct for all Event Stream operations? rustTemplate( - "${section.request}.properties_mut().insert(#{sig_auth}::signer::SignableBody::Bytes(&[]));", + "${section.request}.properties_mut().insert(#{SignableBody}::Bytes(&[]));", *codegenScope, ) } @@ -181,13 +182,13 @@ class SigV4SigningFeature( val authSchemes = serviceIndex.getEffectiveAuthSchemes(service, operation) if (!authSchemes.containsKey(SigV4Trait.ID)) { rustTemplate( - "signing_config.signing_requirements = #{sig_auth}::signer::SigningRequirements::Disabled;", + "signing_config.signing_requirements = #{SigningRequirements}::Disabled;", *codegenScope, ) } else { if (operation.hasTrait()) { rustTemplate( - "signing_config.signing_requirements = #{sig_auth}::signer::SigningRequirements::Optional;", + "signing_config.signing_requirements = #{SigningRequirements}::Optional;", *codegenScope, ) } @@ -195,17 +196,16 @@ class SigV4SigningFeature( rustTemplate( """ ${section.request}.properties_mut().insert(signing_config); - ${section.request}.properties_mut().insert(#{aws_types}::SigningService::from_static(${section.config}.signing_service())); + ${section.request}.properties_mut().insert(#{SigningService}::from_static(${section.config}.signing_service())); if let Some(region) = &${section.config}.region { - ${section.request}.properties_mut().insert(#{aws_types}::region::SigningRegion::from(region.clone())); + ${section.request}.properties_mut().insert(#{SigningRegion}::from(region.clone())); } """, *codegenScope, ) } + else -> emptySection } } } - -fun RuntimeConfig.sigAuth() = awsRuntimeDependency("aws-sig-auth") diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt new file mode 100644 index 0000000000..283c25d39e --- /dev/null +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt @@ -0,0 +1,32 @@ +package software.amazon.smithy.rustsdk.decorators + +import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +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.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rustsdk.AwsCustomization +import software.amazon.smithy.rustsdk.AwsSection + +class SleepImplDecorator : AwsCodegenDecorator { + override val name: String = "SleepImpl" + override val order: Byte = 0 + + override fun awsCustomizations( + codegenContext: ClientCodegenContext, + baseCustomizations: List, + ): List { + return baseCustomizations + SleepImplFromSdkConfig() + } + + override fun supportsCodegenContext(clazz: Class): Boolean = + clazz.isAssignableFrom(ClientCodegenContext::class.java) +} + +class SleepImplFromSdkConfig : AwsCustomization() { + override fun section(section: AwsSection): Writable = writable { + when (section) { + is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_sleep_impl(input.sleep_impl());") + } + } +} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt similarity index 82% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt index f18c9cd06b..c5a9a2ca76 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt @@ -3,34 +3,34 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk +package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.aws.traits.ServiceTrait import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType 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.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectTrait +import software.amazon.smithy.rustsdk.AwsCustomization +import software.amazon.smithy.rustsdk.AwsSection +import software.amazon.smithy.rustsdk.awsHttp +import software.amazon.smithy.rustsdk.awsTypes /** * Inserts a UserAgent configuration into the operation */ -class UserAgentDecorator : RustCodegenDecorator { +class UserAgentDecorator : AwsCodegenDecorator { override val name: String = "UserAgent" override val order: Byte = 10 @@ -50,6 +50,13 @@ class UserAgentDecorator : RustCodegenDecorator, + ): List { + return baseCustomizations + AppNameFromSdkConfig() + } + override fun operationCustomizations( codegenContext: ClientCodegenContext, operation: OperationShape, @@ -71,28 +78,24 @@ private class ApiVersionAndPubUse(private val runtimeConfig: RuntimeConfig, serv override fun section(section: LibRsSection): Writable = when (section) { is LibRsSection.Body -> writable { // PKG_VERSION comes from CrateVersionGenerator - rust( - "static API_METADATA: #1T::ApiMetadata = #1T::ApiMetadata::new(${serviceId.dq()}, PKG_VERSION);", - runtimeConfig.userAgentModule(), + rustTemplate( + "static API_METADATA: #{ApiMetadata} = #{ApiMetadata}::new(${serviceId.dq()}, PKG_VERSION);", + "ApiMetadata" to runtimeConfig.awsHttp().member("user_agent::ApiMetadata"), ) // Re-export the app name so that it can be specified in config programmatically without an explicit dependency - rustTemplate("pub use #{AppName};", "AppName" to runtimeConfig.appName()) + rust("pub use #T;", runtimeConfig.awsTypes().member("app_name::AppName")) } else -> emptySection } } -private fun RuntimeConfig.userAgentModule() = awsHttp().asType().member("user_agent") -private fun RuntimeConfig.env(): RuntimeType = RuntimeType("Env", awsTypes(), "aws_types::os_shim_internal") -private fun RuntimeConfig.appName(): RuntimeType = RuntimeType("AppName", awsTypes(this), "aws_types::app_name") - private class UserAgentFeature(private val runtimeConfig: RuntimeConfig) : OperationCustomization() { override fun section(section: OperationSection): Writable = when (section) { is OperationSection.MutateRequest -> writable { rustTemplate( """ - let mut user_agent = #{ua_module}::AwsUserAgent::new_from_environment( + let mut user_agent = #{AwsUserAgent}::new_from_environment( #{Env}::real(), crate::API_METADATA.clone(), ); @@ -101,8 +104,8 @@ private class UserAgentFeature(private val runtimeConfig: RuntimeConfig) : Opera } ${section.request}.properties_mut().insert(user_agent); """, - "ua_module" to runtimeConfig.userAgentModule(), - "Env" to runtimeConfig.env(), + "AwsUserAgent" to runtimeConfig.awsHttp().member("user_agent::AwsUserAgent"), + "Env" to runtimeConfig.awsTypes().member("os_shim_internal::Env"), ) } else -> emptySection @@ -110,7 +113,7 @@ private class UserAgentFeature(private val runtimeConfig: RuntimeConfig) : Opera } private class AppNameCustomization(runtimeConfig: RuntimeConfig) : ConfigCustomization() { - private val codegenScope = arrayOf("AppName" to runtimeConfig.appName()) + private val codegenScope = arrayOf("AppName" to runtimeConfig.awsTypes().member("app_name::AppName")) override fun section(section: ServiceConfig): Writable = when (section) { @@ -164,3 +167,11 @@ private class AppNameCustomization(runtimeConfig: RuntimeConfig) : ConfigCustomi else -> emptySection } } + +class AppNameFromSdkConfig : AwsCustomization() { + override fun section(section: AwsSection): Writable = writable { + when (section) { + is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_app_name(input.app_name().cloned());") + } + } +} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/s3/S3Decorator.kt similarity index 92% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/s3/S3Decorator.kt index 230cf8491a..fd11d1ae2b 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/s3/S3Decorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.s3 +package software.amazon.smithy.rustsdk.servicecustomizations.s3 import software.amazon.smithy.aws.traits.protocols.RestXmlTrait import software.amazon.smithy.model.Model @@ -17,13 +17,12 @@ import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.client.smithy.protocols.ClientRestXmlFactory -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType @@ -36,9 +35,8 @@ import software.amazon.smithy.rust.codegen.core.util.letIf import software.amazon.smithy.rustsdk.AwsRuntimeType import java.util.logging.Logger -/** - * Top level decorator for S3 - */ +val S3: ShapeId = ShapeId.from("com.amazonaws.s3#AmazonS3") + class S3Decorator : RustCodegenDecorator { override val name: String = "S3" override val order: Byte = 0 @@ -49,7 +47,7 @@ class S3Decorator : RustCodegenDecorator - S3(protocolConfig) + S3RestXml(protocolConfig) }, ) } @@ -89,14 +87,14 @@ class S3Decorator : RustCodegenDecorator Date: Tue, 1 Nov 2022 16:02:27 -0500 Subject: [PATCH 02/19] move: all AWS-service-specific customizations into a new servicecustomizations folder --- .../apigateway/ApiGatewayDecorator.kt | 4 +--- .../auth/DisabledAuthDecorator.kt | 4 ++-- .../ec2/BoxPrimitiveShapes.kt | 2 +- .../ec2/Ec2Decorator.kt | 10 +++++----- .../ec2/Ec2MakePrimitivesOptional.kt} | 4 ++-- .../glacier/AccountIdAutofill.kt | 2 +- .../glacier/ApiVersionHeader.kt | 4 +--- .../glacier/GlacierDecorator.kt | 10 ++++++---- .../glacier/TreeHashHeader.kt | 7 ++++--- .../route53/Route53Decorator.kt | 2 +- .../route53/TrimResourceId.kt | 2 +- .../sts/STSDecorator.kt | 6 ++++-- 12 files changed, 29 insertions(+), 28 deletions(-) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/apigateway/ApiGatewayDecorator.kt (92%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/auth/DisabledAuthDecorator.kt (94%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/ec2/BoxPrimitiveShapes.kt (97%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/ec2/Ec2Decorator.kt (83%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize/ec2/EC2MakePrimitivesOptional.kt => servicecustomizations/ec2/Ec2MakePrimitivesOptional.kt} (87%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/glacier/AccountIdAutofill.kt (95%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/glacier/ApiVersionHeader.kt (87%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/glacier/GlacierDecorator.kt (81%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/glacier/TreeHashHeader.kt (89%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/route53/Route53Decorator.kt (98%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/route53/TrimResourceId.kt (88%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{customize => servicecustomizations}/sts/STSDecorator.kt (93%) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/apigateway/ApiGatewayDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/apigateway/ApiGatewayDecorator.kt similarity index 92% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/apigateway/ApiGatewayDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/apigateway/ApiGatewayDecorator.kt index 23d489a5ce..836ea31a60 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/apigateway/ApiGatewayDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/apigateway/ApiGatewayDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.apigateway +package software.amazon.smithy.rustsdk.servicecustomizations.apigateway import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId @@ -42,8 +42,6 @@ class ApiGatewayDecorator : RustCodegenDecorator emptySection - is OperationSection.OperationImplBlock -> emptySection is OperationSection.MutateRequest -> writable { rust( """${section.request} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/auth/DisabledAuthDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/auth/DisabledAuthDecorator.kt similarity index 94% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/auth/DisabledAuthDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/auth/DisabledAuthDecorator.kt index 57acccd6a5..c4ffe34372 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/auth/DisabledAuthDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/auth/DisabledAuthDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.auth +package software.amazon.smithy.rustsdk.servicecustomizations.auth import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape @@ -20,7 +20,7 @@ private fun String.shapeId() = ShapeId.from(this) // / STS (and possibly other services) need to have auth manually set to [] class DisabledAuthDecorator : RustCodegenDecorator { - override val name: String = "OptionalAuth" + override val name: String = "DisabledAuth" override val order: Byte = 0 private val optionalAuth = diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/BoxPrimitiveShapes.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/BoxPrimitiveShapes.kt similarity index 97% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/BoxPrimitiveShapes.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/BoxPrimitiveShapes.kt index 77805ee91f..01a094842c 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/BoxPrimitiveShapes.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/BoxPrimitiveShapes.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.ec2 +package software.amazon.smithy.rustsdk.servicecustomizations.ec2 import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.AbstractShapeBuilder diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/Ec2Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2Decorator.kt similarity index 83% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/Ec2Decorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2Decorator.kt index 630ac0af02..5a41b8512a 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/Ec2Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2Decorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.ec2 +package software.amazon.smithy.rustsdk.servicecustomizations.ec2 import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -14,20 +14,20 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.Cli import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.util.letIf +private val Ec2 = ShapeId.from("com.amazonaws.ec2#AmazonEC2") + class Ec2Decorator : RustCodegenDecorator { override val name: String = "Ec2" override val order: Byte = 0 - private val ec2 = ShapeId.from("com.amazonaws.ec2#AmazonEC2") - private fun applies(serviceShape: ServiceShape) = - serviceShape.id == ec2 + private fun applies(serviceShape: ServiceShape) = serviceShape.id == Ec2 override fun transformModel(service: ServiceShape, model: Model): Model { // EC2 incorrectly models primitive shapes as unboxed when they actually // need to be boxed for the API to work properly return model.letIf( applies(service), - EC2MakePrimitivesOptional::processModel, + Ec2MakePrimitivesOptional::processModel, ) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptional.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptional.kt similarity index 87% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptional.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptional.kt index 0554f860f4..918b90ab59 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptional.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptional.kt @@ -3,14 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.ec2 +package software.amazon.smithy.rustsdk.servicecustomizations.ec2 import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.traits.ClientOptionalTrait import software.amazon.smithy.model.transform.ModelTransformer -object EC2MakePrimitivesOptional { +object Ec2MakePrimitivesOptional { fun processModel(model: Model): Model { val updates = arrayListOf() for (struct in model.structureShapes) { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/AccountIdAutofill.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/AccountIdAutofill.kt similarity index 95% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/AccountIdAutofill.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/AccountIdAutofill.kt index a101742512..a4cf622b77 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/AccountIdAutofill.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/AccountIdAutofill.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.glacier +package software.amazon.smithy.rustsdk.servicecustomizations.glacier import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/ApiVersionHeader.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/ApiVersionHeader.kt similarity index 87% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/ApiVersionHeader.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/ApiVersionHeader.kt index 8bc2d3b061..b0f14f34df 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/ApiVersionHeader.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/ApiVersionHeader.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.glacier +package software.amazon.smithy.rustsdk.servicecustomizations.glacier import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -21,8 +21,6 @@ class ApiVersionHeader( private val apiVersion: String, ) : OperationCustomization() { override fun section(section: OperationSection): Writable = when (section) { - is OperationSection.FinalizeOperation -> emptySection - is OperationSection.OperationImplBlock -> emptySection is OperationSection.MutateRequest -> writable { rust( """${section.request} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/GlacierDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/GlacierDecorator.kt similarity index 81% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/GlacierDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/GlacierDecorator.kt index 166ca7e3b1..c0f76fed76 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/GlacierDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/GlacierDecorator.kt @@ -3,9 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.glacier +package software.amazon.smithy.rustsdk.servicecustomizations.glacier import software.amazon.smithy.model.shapes.OperationShape +import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator @@ -19,15 +20,16 @@ class GlacierDecorator : RustCodegenDecorator, ): List { - val extras = if (applies(codegenContext)) { - val apiVersion = codegenContext.serviceShape.version + val serviceShape = codegenContext.serviceShape + val extras = if (applies(serviceShape)) { + val apiVersion = serviceShape.version listOfNotNull( ApiVersionHeader(apiVersion), TreeHashHeader.forOperation(operation, codegenContext.runtimeConfig), diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/TreeHashHeader.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/TreeHashHeader.kt similarity index 89% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/TreeHashHeader.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/TreeHashHeader.kt index 05f6e7471c..6d936a0f08 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/TreeHashHeader.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/TreeHashHeader.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.glacier +package software.amazon.smithy.rustsdk.servicecustomizations.glacier import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId @@ -34,7 +34,6 @@ private val UploadMultipartPart: ShapeId = ShapeId.from("com.amazonaws.glacier#U private val Applies = setOf(UploadArchive, UploadMultipartPart) class TreeHashHeader(private val runtimeConfig: RuntimeConfig) : OperationCustomization() { - private val glacierChecksums = RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("glacier_checksums")) override fun section(section: OperationSection): Writable { return when (section) { is OperationSection.MutateRequest -> writable { @@ -47,9 +46,11 @@ class TreeHashHeader(private val runtimeConfig: RuntimeConfig) : OperationCustom &mut ${section.request} ).await.map_err(|e|#{BuildError}::Other(e.into()))?; """, - "glacier_checksums" to glacierChecksums, "BuildError" to runtimeConfig.operationBuildError(), + "glacier_checksums" to RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("glacier_checksums")), + "BuildError" to runtimeConfig.operationBuildError(), ) } + else -> emptySection } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/route53/Route53Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/Route53Decorator.kt similarity index 98% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/route53/Route53Decorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/Route53Decorator.kt index adff13cf80..988df955f5 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/route53/Route53Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/Route53Decorator.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.route53 +package software.amazon.smithy.rustsdk.servicecustomizations.route53 import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.MemberShape diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/route53/TrimResourceId.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/TrimResourceId.kt similarity index 88% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/route53/TrimResourceId.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/TrimResourceId.kt index 5a56367f8b..8a398f1668 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/route53/TrimResourceId.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/TrimResourceId.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.route53 +package software.amazon.smithy.rustsdk.servicecustomizations.route53 import software.amazon.smithy.model.node.Node import software.amazon.smithy.model.shapes.ShapeId diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/sts/STSDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/sts/STSDecorator.kt similarity index 93% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/sts/STSDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/sts/STSDecorator.kt index 874fd3979e..01f2332abd 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/sts/STSDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/sts/STSDecorator.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.sts +package software.amazon.smithy.rustsdk.servicecustomizations.sts import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -20,13 +20,15 @@ import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.letIf import java.util.logging.Logger +val Sts = ShapeId.from("com.amazonaws.sts#AWSSecurityTokenServiceV20110615") + class STSDecorator : RustCodegenDecorator { override val name: String = "STS" override val order: Byte = 0 private val logger: Logger = Logger.getLogger(javaClass.name) private fun applies(serviceId: ShapeId) = - serviceId == ShapeId.from("com.amazonaws.sts#AWSSecurityTokenServiceV20110615") + serviceId == Sts private fun isIdpCommunicationError(shape: Shape): Boolean = shape is StructureShape && shape.hasTrait() && From 813e388cb6bc2c46567656767cc44fbbbab4a75f Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Tue, 1 Nov 2022 16:04:10 -0500 Subject: [PATCH 03/19] fix: various small lints and compile warnings fix: tests broken by moves --- .../amazon/smithy/rustsdk/SdkSettings.kt | 2 +- .../smithy/rustsdk/traits/PresignableTrait.kt | 4 +-- .../src/test/kotlin/AwsReadmeDecoratorTest.kt | 2 +- .../rustsdk/CredentialProviderConfigTest.kt | 1 + .../EndpointConfigCustomizationTest.kt | 29 ++++++++++++------- .../rustsdk/RegionProviderConfigTest.kt | 1 + .../rustsdk/SigV4SigningCustomizationTest.kt | 1 + .../ec2/Ec2MakePrimitivesOptionalTest.kt} | 6 ++-- tools/crate-hasher/src/file_list.rs | 2 +- 9 files changed, 29 insertions(+), 19 deletions(-) rename aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/{customize/ec2/EC2MakePrimitivesOptionalTest.kt => servicecustomizations/ec2/Ec2MakePrimitivesOptionalTest.kt} (87%) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt index bdae9bf35e..4b8187b99a 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt @@ -21,7 +21,7 @@ class SdkSettings private constructor(private val awsSdk: ObjectNode?) { /** Path to the `sdk-default-configuration.json` config file */ val defaultsConfigPath: Path? get() = - awsSdk?.getStringMember("defaultConfigPath")?.orNull()?.value.let { Paths.get(it) } + awsSdk?.getStringMember("defaultConfigPath")?.orNull()?.value?.let { Paths.get(it) } /** Path to the `sdk-endpoints.json` configuration */ val endpointsConfigPath: Path? get() = diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/traits/PresignableTrait.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/traits/PresignableTrait.kt index ea3c2db066..b8dbeb163e 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/traits/PresignableTrait.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/traits/PresignableTrait.kt @@ -11,8 +11,8 @@ import software.amazon.smithy.model.traits.AnnotationTrait /** Synthetic trait that indicates an operation is presignable. */ // TODO(https://github.com/awslabs/smithy/pull/897) this can be replaced when the trait is added to Smithy. -class PresignableTrait(val syntheticOperationId: ShapeId) : AnnotationTrait(ID, Node.objectNode()) { +class PresignableTrait : AnnotationTrait(ID, Node.objectNode()) { companion object { - val ID = ShapeId.from("smithy.api.aws.internal#presignable") + val ID: ShapeId = ShapeId.from("smithy.api.aws.internal#presignable") } } diff --git a/aws/sdk-codegen/src/test/kotlin/AwsReadmeDecoratorTest.kt b/aws/sdk-codegen/src/test/kotlin/AwsReadmeDecoratorTest.kt index 5717fcc2fe..cfb4a30466 100644 --- a/aws/sdk-codegen/src/test/kotlin/AwsReadmeDecoratorTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/AwsReadmeDecoratorTest.kt @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test -import software.amazon.smithy.rustsdk.AwsSdkReadmeGenerator +import software.amazon.smithy.rustsdk.decorators.AwsSdkReadmeGenerator class AwsReadmeDecoratorTest { @Test diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/CredentialProviderConfigTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/CredentialProviderConfigTest.kt index df26efdfec..ac364b1339 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/CredentialProviderConfigTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/CredentialProviderConfigTest.kt @@ -7,6 +7,7 @@ package software.amazon.smithy.rustsdk import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.testutil.validateConfigCustomizations +import software.amazon.smithy.rustsdk.decorators.CredentialProviderConfig internal class CredentialProviderConfigTest { @Test diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt index 99185116f3..07935b2116 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt @@ -26,13 +26,15 @@ import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.runCommand +import software.amazon.smithy.rustsdk.decorators.EndpointConfigCustomization +import software.amazon.smithy.rustsdk.decorators.PubUseEndpoint internal class EndpointConfigCustomizationTest { - private val placeholderEndpointParams = AwsTestRuntimeConfig.awsEndpoint().asType().member("Params") + private val runtimeConfig = AwsTestRuntimeConfig private val codegenScope = arrayOf( "http" to CargoDependency.Http.asType(), - "PlaceholderParams" to placeholderEndpointParams, - "aws_types" to awsTypes(AwsTestRuntimeConfig).asType(), + "PlaceholderParams" to runtimeConfig.awsEndpoint().member("Params"), + "Region" to runtimeConfig.awsTypes().member("region::Region"), ) private val model = """ @@ -135,16 +137,18 @@ internal class EndpointConfigCustomizationTest { codegenContext: ClientCodegenContext, baseCustomizations: List, ): List = - baseCustomizations + stubConfigCustomization("a") + EndpointConfigCustomization( - codegenContext, - endpointConfig, - ) + stubConfigCustomization("b") + baseCustomizations + + stubConfigCustomization("a") + + EndpointConfigCustomization(codegenContext, endpointConfig) + + stubConfigCustomization("b") override fun libRsCustomizations( codegenContext: ClientCodegenContext, baseCustomizations: List, ): List = - baseCustomizations + PubUseEndpoint(AwsTestRuntimeConfig) + AllowLintsGenerator(listOf("dead_code"), listOf(), listOf()) + baseCustomizations + + PubUseEndpoint(AwsTestRuntimeConfig) + + AllowLintsGenerator(listOf("dead_code"), listOf(), listOf()) override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { if (test != null) { @@ -180,7 +184,8 @@ internal class EndpointConfigCustomizationTest { """ let conf = crate::config::Config::builder().build(); let endpoint = conf.endpoint_resolver - .resolve_endpoint(&::#{PlaceholderParams}::new(Some(#{aws_types}::region::Region::new("fips-ca-central-1")))).expect("default resolver produces a valid endpoint"); + .resolve_endpoint(&#{PlaceholderParams}::new(Some(#{Region}::new("fips-ca-central-1")))) + .expect("default resolver produces a valid endpoint"); assert_eq!(endpoint.url(), "https://access-analyzer-fips.ca-central-1.amazonaws.com/"); """, *codegenScope, @@ -199,11 +204,13 @@ internal class EndpointConfigCustomizationTest { """ let conf = crate::config::Config::builder().build(); let endpoint = conf.endpoint_resolver - .resolve_endpoint(&::#{PlaceholderParams}::new(Some(#{aws_types}::region::Region::new("us-east-1")))).expect("default resolver produces a valid endpoint"); + .resolve_endpoint(&#{PlaceholderParams}::new(Some(#{Region}::new("us-east-1")))) + .expect("default resolver produces a valid endpoint"); assert_eq!(endpoint.url(), "https://iam.amazonaws.com/"); let endpoint = conf.endpoint_resolver - .resolve_endpoint(&::#{PlaceholderParams}::new(Some(#{aws_types}::region::Region::new("iam-fips")))).expect("default resolver produces a valid endpoint"); + .resolve_endpoint(&#{PlaceholderParams}::new(Some(#{Region}::new("iam-fips")))) + .expect("default resolver produces a valid endpoint"); assert_eq!(endpoint.url(), "https://iam-fips.amazonaws.com/"); """, *codegenScope, diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt index 8d69fb2c86..efb77706dc 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt @@ -10,6 +10,7 @@ import software.amazon.smithy.rust.codegen.client.testutil.validateConfigCustomi import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.core.testutil.rustSettings +import software.amazon.smithy.rustsdk.decorators.RegionProviderConfig internal class RegionProviderConfigTest { @Test diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt index 9de7c91f65..8b5174754a 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt @@ -11,6 +11,7 @@ import software.amazon.smithy.rust.codegen.client.testutil.stubConfigProject import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest import software.amazon.smithy.rust.codegen.core.testutil.unitTest +import software.amazon.smithy.rustsdk.decorators.SigV4SigningConfig internal class SigV4SigningCustomizationTest { @Test diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptionalTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptionalTest.kt similarity index 87% rename from aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptionalTest.kt rename to aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptionalTest.kt index 51eba7fa86..f7f50cd91d 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptionalTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptionalTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.customize.ec2 +package software.amazon.smithy.rustsdk.servicecustomizations.ec2 import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test @@ -12,7 +12,7 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.util.lookup -internal class EC2MakePrimitivesOptionalTest { +internal class Ec2MakePrimitivesOptionalTest { @Test fun `primitive shapes are boxed`() { val baseModel = """ @@ -32,7 +32,7 @@ internal class EC2MakePrimitivesOptionalTest { structure Other {} """.asSmithyModel() - val model = EC2MakePrimitivesOptional.processModel(baseModel) + val model = Ec2MakePrimitivesOptional.processModel(baseModel) val nullableIndex = NullableIndex(model) val struct = model.lookup("test#Primitives") struct.members().forEach { diff --git a/tools/crate-hasher/src/file_list.rs b/tools/crate-hasher/src/file_list.rs index 03f6090cb6..1a129a28f2 100644 --- a/tools/crate-hasher/src/file_list.rs +++ b/tools/crate-hasher/src/file_list.rs @@ -64,7 +64,7 @@ impl FileList { .to_str() .expect("not using unusual file names in crate source") .into(), - sha256: sha256::digest_file(&path).context("hash file")?, + sha256: sha256::try_digest(path).context("hash file")?, }); } } From f1e9e1f0f285f3d757869c80e96de9e547a947e1 Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Tue, 1 Nov 2022 16:12:57 -0500 Subject: [PATCH 04/19] refactor: unify how runtime types are instantiated format: unify casing of runtime type function names format: unify casing of CargoDependency function names rename: args of FluentClientGenerics.sendBounds method to be more explicit update: make orderedDecorators field of CombinedCodegenDecorator accessible to inheritors fix: spelling issues highlighted by IntelliJ update: make protected fields private where possible --- .../smithy/rustsdk/AwsRuntimeDependency.kt | 24 +- .../smithy/EventStreamSymbolProvider.kt | 7 +- .../HttpVersionListCustomization.kt | 10 +- .../ResiliencyConfigCustomization.kt | 357 +++++++++--------- .../SmithyTypesPubUseGenerator.kt | 5 +- .../NoOpEventStreamSigningDecorator.kt | 2 +- .../smithy/customize/RustCodegenDecorator.kt | 2 +- .../EndpointTraitBindingGenerator.kt | 7 +- .../smithy/generators/PaginatorGenerator.kt | 10 +- .../client/CustomizableOperationGenerator.kt | 25 +- .../client/FluentClientDecorator.kt | 2 +- .../client/FluentClientGenerator.kt | 13 +- .../generators/client/FluentClientGenerics.kt | 2 +- .../config/EventStreamSigningConfig.kt | 4 +- .../protocol/ProtocolTestGenerator.kt | 11 +- .../HttpVersionListGeneratorTest.kt | 8 +- .../codegen/core/rustlang/CargoDependency.kt | 42 ++- .../rust/codegen/core/rustlang/RustType.kt | 4 +- .../rust/codegen/core/rustlang/RustWriter.kt | 20 +- .../codegen/core/smithy/CoreRustSettings.kt | 8 +- .../rust/codegen/core/smithy/RuntimeType.kt | 52 +-- .../core/smithy/generators/Instantiator.kt | 19 +- .../smithy/generators/StructureGenerator.kt | 4 +- .../error/CombinedErrorGenerator.kt | 3 +- .../smithy/generators/error/ErrorGenerator.kt | 2 +- .../error/TopLevelErrorGenerator.kt | 2 +- .../generators/http/HttpBindingGenerator.kt | 23 +- .../http/RequestBindingGenerator.kt | 5 +- .../http/RestRequestSpecGenerator.kt | 29 +- .../protocol/MakeOperationGenerator.kt | 14 +- .../codegen/core/smithy/protocols/AwsJson.kt | 8 +- .../codegen/core/smithy/protocols/AwsQuery.kt | 5 +- .../codegen/core/smithy/protocols/Ec2Query.kt | 5 +- .../HttpBoundProtocolPayloadGenerator.kt | 17 +- .../codegen/core/smithy/protocols/Protocol.kt | 2 +- .../codegen/core/smithy/protocols/RestJson.kt | 5 +- .../codegen/core/smithy/protocols/RestXml.kt | 5 +- .../parse/EventStreamUnmarshallerGenerator.kt | 25 +- .../protocols/parse/JsonParserGenerator.kt | 33 +- .../parse/XmlBindingTraitParserGenerator.kt | 23 +- .../EventStreamErrorMarshallerGenerator.kt | 13 +- .../EventStreamMarshallerGenerator.kt | 13 +- .../serialize/JsonSerializerGenerator.kt | 24 +- .../serialize/QuerySerializerGenerator.kt | 15 +- .../XmlBindingTraitSerializerGenerator.kt | 14 +- .../core/smithy/traits/RustBoxTrait.kt | 2 +- .../traits/SyntheticEventStreamUnionTrait.kt | 2 +- .../smithy/PythonServerCargoDependency.kt | 4 +- .../python/smithy/PythonServerRuntimeType.kt | 10 +- .../generators/PythonApplicationGenerator.kt | 2 +- .../PythonServerOperationHandlerGenerator.kt | 2 +- .../server/smithy/ServerCargoDependency.kt | 4 +- .../server/smithy/ServerRuntimeType.kt | 12 +- .../ServerHttpSensitivityGenerator.kt | 10 +- .../generators/ServerOperationGenerator.kt | 2 +- .../ServerOperationHandlerGenerator.kt | 5 +- .../ServerOperationRegistryGenerator.kt | 4 +- .../generators/ServerServiceGeneratorV2.kt | 2 +- .../generators/protocol/ServerProtocol.kt | 10 +- .../protocol/ServerProtocolTestGenerator.kt | 4 +- .../ServerHttpBoundProtocolGenerator.kt | 18 +- .../ServerHttpSensitivityGeneratorTest.kt | 2 +- .../EventStreamMarshallerGeneratorTest.kt | 2 +- 63 files changed, 495 insertions(+), 525 deletions(-) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt index eb87bf56dd..dc1bfc8869 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt @@ -8,6 +8,7 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType @@ -50,20 +51,23 @@ object AwsRuntimeType { fun RuntimeConfig.defaultMiddleware() = RuntimeType.forInlineDependency( InlineAwsDependency.forRustFile( "middleware", visibility = Visibility.PUBLIC, - CargoDependency.SmithyHttp(this), - CargoDependency.SmithyHttpTower(this), - CargoDependency.SmithyClient(this), + CargoDependency.smithyHttp(this), + CargoDependency.smithyHttpTower(this), + CargoDependency.smithyClient(this), CargoDependency.Tower, - awsHttp(), - awsEndpoint(), + awsRuntimeCrate("aws-http"), + awsRuntimeCrate("aws-endpoint"), ), ).member("DefaultMiddleware") } -fun RuntimeConfig.awsRuntimeDependency(name: String, features: Set = setOf()): CargoDependency = +fun RuntimeConfig.awsRuntimeCrate(name: String, features: Set = setOf()): CargoDependency = CargoDependency(name, awsRoot().crateLocation(null), features = features) -fun RuntimeConfig.awsHttp(): CargoDependency = awsRuntimeDependency("aws-http") -fun RuntimeConfig.awsTypes(): CargoDependency = awsRuntimeDependency("aws-types") -fun RuntimeConfig.awsConfig(): CargoDependency = awsRuntimeDependency("aws-config") -fun RuntimeConfig.awsEndpoint() = awsRuntimeDependency("aws-endpoint") +fun RuntimeConfig.awsConfig() = awsRuntimeCrate("aws-config").asType() +fun RuntimeConfig.awsEndpoint() = awsRuntimeCrate("aws-endpoint").asType() +fun RuntimeConfig.awsHttp() = awsRuntimeCrate("aws-http").asType() +fun RuntimeConfig.awsSigAuth() = awsRuntimeCrate("aws-sig-auth").asType() +fun RuntimeConfig.awsSigAuthEventStream() = awsRuntimeCrate("aws-sig-auth", setOf("sign-eventstream")).asType() +fun RuntimeConfig.awsSigv4() = awsRuntimeCrate("aws-sigv4").asType() +fun RuntimeConfig.awsTypes() = awsRuntimeCrate("aws-types").asType() diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProvider.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProvider.kt index 6802d444c4..5a098aac40 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProvider.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProvider.kt @@ -13,10 +13,10 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.rustlang.smithyEventStream import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.WrappingSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.generators.error.eventStreamErrorSymbol @@ -38,7 +38,6 @@ class EventStreamSymbolProvider( private val model: Model, private val target: CodegenTarget, ) : WrappingSymbolProvider(base) { - private val smithyEventStream = CargoDependency.SmithyEventStream(runtimeConfig) override fun toSymbol(shape: Shape): Symbol { val initial = super.toSymbol(shape) @@ -54,7 +53,7 @@ class EventStreamSymbolProvider( if (operationShape != null) { val unionShape = model.expectShape(shape.target).asUnionShape().get() val error = if (target == CodegenTarget.SERVER && unionShape.eventStreamErrors().isEmpty()) { - RuntimeType("MessageStreamError", smithyEventStream, "aws_smithy_http::event_stream").toSymbol() + runtimeConfig.smithyEventStream().member("event_stream::MessageStreamError").toSymbol() } else { unionShape.eventStreamErrorSymbol(model, this, target).toSymbol() } @@ -71,7 +70,7 @@ class EventStreamSymbolProvider( .name(rustType.name) .rustType(rustType) .addReference(initial) - .addDependency(CargoDependency.SmithyHttp(runtimeConfig).withFeature("event-stream")) + .addDependency(CargoDependency.smithyHttp(runtimeConfig).withFeature("event-stream")) .addReference(error) .build() } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt index 8550adcefa..6de29c2817 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt @@ -9,25 +9,19 @@ import software.amazon.smithy.aws.traits.protocols.AwsProtocolTrait import software.amazon.smithy.model.shapes.OperationShape 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.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.isEventStream -private fun RuntimeConfig.httpVersionModule(): RuntimeType = - RuntimeType("http_versions", this.runtimeCrate("http"), "aws_smithy_http") -private fun RuntimeConfig.defaultHttpVersionList(): RuntimeType = - this.httpVersionModule().member("DEFAULT_HTTP_VERSION_LIST") - class HttpVersionListCustomization( private val codegenContext: CodegenContext, private val operationShape: OperationShape, ) : OperationCustomization() { - private val defaultHttpVersions = codegenContext.runtimeConfig.defaultHttpVersionList().fullyQualifiedName() + private val defaultHttpVersions = codegenContext.runtimeConfig.smithyHttp().member("http_versions::DEFAULT_HTTP_VERSION_LIST").fullyQualifiedName() override fun section(section: OperationSection): Writable { val awsProtocolTrait = codegenContext.serviceShape.getTrait() diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt index 40131d517a..28be65b1f2 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt @@ -9,22 +9,21 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.config.Confi import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyAsync +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.RustCrate class ResiliencyConfigCustomization(codegenContext: CodegenContext) : ConfigCustomization() { - private val retryConfig = smithyTypesRetry(codegenContext.runtimeConfig) - private val sleepModule = smithyAsyncRtSleep(codegenContext.runtimeConfig) - private val timeoutModule = smithyTypesTimeout(codegenContext.runtimeConfig) + private val runtimeConfig = codegenContext.runtimeConfig private val moduleUseName = codegenContext.moduleUseName() private val codegenScope = arrayOf( - "AsyncSleep" to sleepModule.member("AsyncSleep"), - "RetryConfig" to retryConfig.member("RetryConfig"), - "Sleep" to sleepModule.member("Sleep"), - "TimeoutConfig" to timeoutModule.member("TimeoutConfig"), + "AsyncSleep" to runtimeConfig.smithyAsync().member("rt::sleep::AsyncSleep"), + "RetryConfig" to runtimeConfig.smithyTypes().member("retry::RetryConfig"), + "Sleep" to runtimeConfig.smithyAsync().member("rt::sleep::Sleep"), + "TimeoutConfig" to runtimeConfig.smithyTypes().member("timeout::TimeoutConfig"), ) override fun section(section: ServiceConfig) = @@ -32,31 +31,31 @@ class ResiliencyConfigCustomization(codegenContext: CodegenContext) : ConfigCust when (section) { is ServiceConfig.ConfigStruct -> rustTemplate( """ - retry_config: Option<#{RetryConfig}>, - sleep_impl: Option>, - timeout_config: Option<#{TimeoutConfig}>, - """, + retry_config: Option<#{RetryConfig}>, + sleep_impl: Option>, + timeout_config: Option<#{TimeoutConfig}>, + """, *codegenScope, ) is ServiceConfig.ConfigImpl -> { rustTemplate( """ - /// Return a reference to the retry configuration contained in this config, if any. - pub fn retry_config(&self) -> Option<&#{RetryConfig}> { - self.retry_config.as_ref() - } - - /// Return a cloned Arc containing the async sleep implementation from this config, if any. - pub fn sleep_impl(&self) -> Option> { - self.sleep_impl.clone() - } - - /// Return a reference to the timeout configuration contained in this config, if any. - pub fn timeout_config(&self) -> Option<&#{TimeoutConfig}> { - self.timeout_config.as_ref() - } - """, + /// Return a reference to the retry configuration contained in this config, if any. + pub fn retry_config(&self) -> Option<&#{RetryConfig}> { + self.retry_config.as_ref() + } + + /// Return a cloned Arc containing the async sleep implementation from this config, if any. + pub fn sleep_impl(&self) -> Option> { + self.sleep_impl.clone() + } + + /// Return a reference to the timeout configuration contained in this config, if any. + pub fn timeout_config(&self) -> Option<&#{TimeoutConfig}> { + self.timeout_config.as_ref() + } + """, *codegenScope, ) } @@ -64,159 +63,159 @@ class ResiliencyConfigCustomization(codegenContext: CodegenContext) : ConfigCust is ServiceConfig.BuilderStruct -> rustTemplate( """ - retry_config: Option<#{RetryConfig}>, - sleep_impl: Option>, - timeout_config: Option<#{TimeoutConfig}>, - """, + retry_config: Option<#{RetryConfig}>, + sleep_impl: Option>, + timeout_config: Option<#{TimeoutConfig}>, + """, *codegenScope, ) ServiceConfig.BuilderImpl -> rustTemplate( """ - /// Set the retry_config for the builder - /// - /// ## Examples - /// ```no_run - /// use $moduleUseName::config::Config; - /// use $moduleUseName::config::retry::RetryConfig; - /// - /// let retry_config = RetryConfig::standard().with_max_attempts(5); - /// let config = Config::builder().retry_config(retry_config).build(); - /// ``` - pub fn retry_config(mut self, retry_config: #{RetryConfig}) -> Self { - self.set_retry_config(Some(retry_config)); - self - } - - /// Set the retry_config for the builder - /// - /// ## Examples - /// ```no_run - /// use $moduleUseName::config::{Builder, Config}; - /// use $moduleUseName::config::retry::RetryConfig; - /// - /// fn disable_retries(builder: &mut Builder) { - /// let retry_config = RetryConfig::standard().with_max_attempts(1); - /// builder.set_retry_config(Some(retry_config)); - /// } - /// - /// let mut builder = Config::builder(); - /// disable_retries(&mut builder); - /// let config = builder.build(); - /// ``` - pub fn set_retry_config(&mut self, retry_config: Option<#{RetryConfig}>) -> &mut Self { - self.retry_config = retry_config; - self - } - - /// Set the sleep_impl for the builder - /// - /// ## Examples - /// - /// ```no_run - /// use $moduleUseName::config::{AsyncSleep, Sleep, Config}; - /// - /// ##[derive(Debug)] - /// pub struct ForeverSleep; - /// - /// impl AsyncSleep for ForeverSleep { - /// fn sleep(&self, duration: std::time::Duration) -> Sleep { - /// Sleep::new(std::future::pending()) - /// } - /// } - /// - /// let sleep_impl = std::sync::Arc::new(ForeverSleep); - /// let config = Config::builder().sleep_impl(sleep_impl).build(); - /// ``` - pub fn sleep_impl(mut self, sleep_impl: std::sync::Arc) -> Self { - self.set_sleep_impl(Some(sleep_impl)); - self - } - - /// Set the sleep_impl for the builder - /// - /// ## Examples - /// - /// ```no_run - /// use $moduleUseName::config::{AsyncSleep, Sleep, Builder, Config}; - /// - /// ##[derive(Debug)] - /// pub struct ForeverSleep; - /// - /// impl AsyncSleep for ForeverSleep { - /// fn sleep(&self, duration: std::time::Duration) -> Sleep { - /// Sleep::new(std::future::pending()) - /// } - /// } - /// - /// fn set_never_ending_sleep_impl(builder: &mut Builder) { - /// let sleep_impl = std::sync::Arc::new(ForeverSleep); - /// builder.set_sleep_impl(Some(sleep_impl)); - /// } - /// - /// let mut builder = Config::builder(); - /// set_never_ending_sleep_impl(&mut builder); - /// let config = builder.build(); - /// ``` - pub fn set_sleep_impl(&mut self, sleep_impl: Option>) -> &mut Self { - self.sleep_impl = sleep_impl; - self - } - - /// Set the timeout_config for the builder - /// - /// ## Examples - /// - /// ```no_run - /// ## use std::time::Duration; - /// use $moduleUseName::config::Config; - /// use $moduleUseName::config::timeout::TimeoutConfig; - /// - /// let timeout_config = TimeoutConfig::builder() - /// .operation_attempt_timeout(Duration::from_secs(1)) - /// .build(); - /// let config = Config::builder().timeout_config(timeout_config).build(); - /// ``` - pub fn timeout_config(mut self, timeout_config: #{TimeoutConfig}) -> Self { - self.set_timeout_config(Some(timeout_config)); - self - } - - /// Set the timeout_config for the builder - /// - /// ## Examples - /// - /// ```no_run - /// ## use std::time::Duration; - /// use $moduleUseName::config::{Builder, Config}; - /// use $moduleUseName::config::timeout::TimeoutConfig; - /// - /// fn set_request_timeout(builder: &mut Builder) { - /// let timeout_config = TimeoutConfig::builder() - /// .operation_attempt_timeout(Duration::from_secs(1)) - /// .build(); - /// builder.set_timeout_config(Some(timeout_config)); - /// } - /// - /// let mut builder = Config::builder(); - /// set_request_timeout(&mut builder); - /// let config = builder.build(); - /// ``` - pub fn set_timeout_config(&mut self, timeout_config: Option<#{TimeoutConfig}>) -> &mut Self { - self.timeout_config = timeout_config; - self - } - """, + /// Set the retry_config for the builder + /// + /// ## Examples + /// ```no_run + /// use $moduleUseName::config::Config; + /// use $moduleUseName::config::retry::RetryConfig; + /// + /// let retry_config = RetryConfig::standard().with_max_attempts(5); + /// let config = Config::builder().retry_config(retry_config).build(); + /// ``` + pub fn retry_config(mut self, retry_config: #{RetryConfig}) -> Self { + self.set_retry_config(Some(retry_config)); + self + } + + /// Set the retry_config for the builder + /// + /// ## Examples + /// ```no_run + /// use $moduleUseName::config::{Builder, Config}; + /// use $moduleUseName::config::retry::RetryConfig; + /// + /// fn disable_retries(builder: &mut Builder) { + /// let retry_config = RetryConfig::standard().with_max_attempts(1); + /// builder.set_retry_config(Some(retry_config)); + /// } + /// + /// let mut builder = Config::builder(); + /// disable_retries(&mut builder); + /// let config = builder.build(); + /// ``` + pub fn set_retry_config(&mut self, retry_config: Option<#{RetryConfig}>) -> &mut Self { + self.retry_config = retry_config; + self + } + + /// Set the sleep_impl for the builder + /// + /// ## Examples + /// + /// ```no_run + /// use $moduleUseName::config::{AsyncSleep, Sleep, Config}; + /// + /// ##[derive(Debug)] + /// pub struct ForeverSleep; + /// + /// impl AsyncSleep for ForeverSleep { + /// fn sleep(&self, duration: std::time::Duration) -> Sleep { + /// Sleep::new(std::future::pending()) + /// } + /// } + /// + /// let sleep_impl = std::sync::Arc::new(ForeverSleep); + /// let config = Config::builder().sleep_impl(sleep_impl).build(); + /// ``` + pub fn sleep_impl(mut self, sleep_impl: std::sync::Arc) -> Self { + self.set_sleep_impl(Some(sleep_impl)); + self + } + + /// Set the sleep_impl for the builder + /// + /// ## Examples + /// + /// ```no_run + /// use $moduleUseName::config::{AsyncSleep, Sleep, Builder, Config}; + /// + /// ##[derive(Debug)] + /// pub struct ForeverSleep; + /// + /// impl AsyncSleep for ForeverSleep { + /// fn sleep(&self, duration: std::time::Duration) -> Sleep { + /// Sleep::new(std::future::pending()) + /// } + /// } + /// + /// fn set_never_ending_sleep_impl(builder: &mut Builder) { + /// let sleep_impl = std::sync::Arc::new(ForeverSleep); + /// builder.set_sleep_impl(Some(sleep_impl)); + /// } + /// + /// let mut builder = Config::builder(); + /// set_never_ending_sleep_impl(&mut builder); + /// let config = builder.build(); + /// ``` + pub fn set_sleep_impl(&mut self, sleep_impl: Option>) -> &mut Self { + self.sleep_impl = sleep_impl; + self + } + + /// Set the timeout_config for the builder + /// + /// ## Examples + /// + /// ```no_run + /// ## use std::time::Duration; + /// use $moduleUseName::config::Config; + /// use $moduleUseName::config::timeout::TimeoutConfig; + /// + /// let timeout_config = TimeoutConfig::builder() + /// .operation_attempt_timeout(Duration::from_secs(1)) + /// .build(); + /// let config = Config::builder().timeout_config(timeout_config).build(); + /// ``` + pub fn timeout_config(mut self, timeout_config: #{TimeoutConfig}) -> Self { + self.set_timeout_config(Some(timeout_config)); + self + } + + /// Set the timeout_config for the builder + /// + /// ## Examples + /// + /// ```no_run + /// ## use std::time::Duration; + /// use $moduleUseName::config::{Builder, Config}; + /// use $moduleUseName::config::timeout::TimeoutConfig; + /// + /// fn set_request_timeout(builder: &mut Builder) { + /// let timeout_config = TimeoutConfig::builder() + /// .operation_attempt_timeout(Duration::from_secs(1)) + /// .build(); + /// builder.set_timeout_config(Some(timeout_config)); + /// } + /// + /// let mut builder = Config::builder(); + /// set_request_timeout(&mut builder); + /// let config = builder.build(); + /// ``` + pub fn set_timeout_config(&mut self, timeout_config: Option<#{TimeoutConfig}>) -> &mut Self { + self.timeout_config = timeout_config; + self + } + """, *codegenScope, ) ServiceConfig.BuilderBuild -> rustTemplate( """ - retry_config: self.retry_config, - sleep_impl: self.sleep_impl, - timeout_config: self.timeout_config, - """, + retry_config: self.retry_config, + sleep_impl: self.sleep_impl, + timeout_config: self.timeout_config, + """, *codegenScope, ) @@ -236,7 +235,7 @@ class ResiliencyReExportCustomization(private val runtimeConfig: RuntimeConfig) /// /// These are re-exported from `aws-smithy-types` for convenience. pub mod retry { - pub use #{types_retry}::{RetryConfig, RetryConfigBuilder, RetryMode}; + pub use #{retry}::{RetryConfig, RetryConfigBuilder, RetryMode}; } /// Timeout configuration /// @@ -245,22 +244,10 @@ class ResiliencyReExportCustomization(private val runtimeConfig: RuntimeConfig) pub use #{timeout}::{TimeoutConfig, TimeoutConfigBuilder}; } """, - "types_retry" to smithyTypesRetry(runtimeConfig), - "sleep" to smithyAsyncRtSleep(runtimeConfig), - "timeout" to smithyTypesTimeout(runtimeConfig), + "retry" to runtimeConfig.smithyTypes().member("retry"), + "sleep" to runtimeConfig.smithyAsync().member("rt::sleep"), + "timeout" to runtimeConfig.smithyTypes().member("timeout"), ) } } } - -// Generate path to the retry module in aws_smithy_types -private fun smithyTypesRetry(runtimeConfig: RuntimeConfig) = - RuntimeType("retry", runtimeConfig.runtimeCrate("types"), "aws_smithy_types") - -// Generate path to the root module in aws_smithy_async -private fun smithyAsyncRtSleep(runtimeConfig: RuntimeConfig) = - RuntimeType("sleep", runtimeConfig.runtimeCrate("async"), "aws_smithy_async::rt") - -// Generate path to the timeout module in aws_smithy_types -private fun smithyTypesTimeout(runtimeConfig: RuntimeConfig) = - RuntimeType("timeout", runtimeConfig.runtimeCrate("types"), "aws_smithy_types") diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt index f605e3a712..722d35bb69 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt @@ -7,11 +7,10 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency -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 import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType @@ -59,7 +58,7 @@ internal fun pubUseTypes(runtimeConfig: RuntimeConfig, model: Model): List + ) + runtimeConfig.smithyHttp().let { http -> listOf( PubUseType(http.member("result::SdkError")) { true }, PubUseType(http.member("byte_stream::ByteStream"), ::hasStreamingOperations), diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt index f4cfce3898..8c63b06d72 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt @@ -48,7 +48,7 @@ class NoOpEventStreamSigningConfig( private val serviceHasEventStream: Boolean, runtimeConfig: RuntimeConfig, ) : EventStreamSigningConfig(runtimeConfig) { - private val smithyEventStream = CargoDependency.SmithyEventStream(runtimeConfig) + private val smithyEventStream = CargoDependency.smithyEventStream(runtimeConfig) private val codegenScope = arrayOf( "NoOpSigner" to RuntimeType("NoOpSigner", smithyEventStream, "aws_smithy_eventstream::frame"), ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt index bfaae9c871..38afef53ad 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt @@ -79,7 +79,7 @@ interface RustCodegenDecorator { */ open class CombinedCodegenDecorator(decorators: List>) : RustCodegenDecorator { - private val orderedDecorators = decorators.sortedBy { it.order } + protected val orderedDecorators = decorators.sortedBy { it.order } override val name: String get() = "MetaDecorator" override val order: Byte diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt index ad01544e30..fa8fa0e2bd 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt @@ -8,12 +8,11 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.EndpointTrait -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.asType 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.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.generators.OperationBuildError @@ -25,8 +24,6 @@ fun EndpointTrait.prefixFormatString(): String { return this.hostPrefix.rustFormatString("", "") } -fun RuntimeConfig.smithyHttp() = CargoDependency.SmithyHttp(this).asType() - class EndpointTraitBindings( model: Model, private val symbolProvider: RustSymbolProvider, @@ -60,7 +57,7 @@ class EndpointTraitBindings( } else { val operationBuildError = OperationBuildError(runtimeConfig) writer.rustBlock("") { - // build a list of args: `labelname = "field"` + // build a list of args: `field_name = "field"` // these eventually end up in the format! macro invocation: // ```format!("some.{endpoint}", endpoint = endpoint);``` val args = endpointTrait.hostPrefix.labels.map { label -> diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt index 2f3f994b95..2b149d68d3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt @@ -22,6 +22,9 @@ import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.render 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.rustlang.smithyAsync +import software.amazon.smithy.rust.codegen.core.rustlang.smithyClient +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -110,10 +113,9 @@ class PaginatorGenerator private constructor( "Builder" to operation.inputShape(model).builderSymbol(symbolProvider), // SDK Types - "SdkError" to CargoDependency.SmithyHttp(runtimeConfig).asType() - .copy(name = "result::SdkError"), - "client" to CargoDependency.SmithyClient(runtimeConfig).asType(), - "fn_stream" to CargoDependency.SmithyAsync(runtimeConfig).asType().member("future::fn_stream"), + "SdkError" to runtimeConfig.smithyHttp().member("result::SdkError"), + "client" to runtimeConfig.smithyClient(), + "fn_stream" to runtimeConfig.smithyAsync().member("future::fn_stream"), // External Types "Stream" to CargoDependency.TokioStream.asType().member("Stream"), diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt index 1c8ba17ca6..d36e4f1f09 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt @@ -15,6 +15,9 @@ 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 import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyClient +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RustCrate @@ -31,9 +34,6 @@ class CustomizableOperationGenerator( const val CUSTOMIZE_MODULE = "crate::operation::customize" } - private val smithyHttp = CargoDependency.SmithyHttp(runtimeConfig).asType() - private val smithyTypes = CargoDependency.SmithyTypes(runtimeConfig).asType() - fun render(crate: RustCrate) { crate.withModule(RustModule.operation(Visibility.PUBLIC)) { docs("Operation customization and supporting types") @@ -47,9 +47,9 @@ class CustomizableOperationGenerator( pub use #{ClassifyRetry}; pub use #{RetryKind}; """, - "Operation" to smithyHttp.member("operation::Operation"), - "ClassifyRetry" to smithyHttp.member("retry::ClassifyRetry"), - "RetryKind" to smithyTypes.member("retry::RetryKind"), + "Operation" to runtimeConfig.smithyHttp().member("operation::Operation"), + "ClassifyRetry" to runtimeConfig.smithyHttp().member("retry::ClassifyRetry"), + "RetryKind" to runtimeConfig.smithyTypes().member("retry::RetryKind"), ) renderCustomizableOperationModule(this) @@ -66,8 +66,8 @@ class CustomizableOperationGenerator( val codegenScope = arrayOf( // SDK Types - "http_result" to smithyHttp.member("result"), - "http_body" to smithyHttp.member("body"), + "http_result" to runtimeConfig.smithyHttp().member("result"), + "http_body" to runtimeConfig.smithyHttp().member("body"), "HttpRequest" to CargoDependency.Http.asType().member("Request"), "handle_generics_decl" to handleGenerics.declaration(), "handle_generics_bounds" to handleGenerics.bounds(), @@ -143,9 +143,6 @@ class CustomizableOperationGenerator( } private fun renderCustomizableOperationSend(writer: RustWriter) { - val smithyHttp = CargoDependency.SmithyHttp(runtimeConfig).asType() - val smithyClient = CargoDependency.SmithyClient(runtimeConfig).asType() - val operationGenerics = RustGenerics(GenericTypeArg("O"), GenericTypeArg("Retry")) val handleGenerics = generics.toRustGenerics() val combinedGenerics = operationGenerics + handleGenerics @@ -153,9 +150,9 @@ class CustomizableOperationGenerator( val codegenScope = arrayOf( "combined_generics_decl" to combinedGenerics.declaration(), "handle_generics_bounds" to handleGenerics.bounds(), - "ParseHttpResponse" to smithyHttp.member("response::ParseHttpResponse"), - "NewRequestPolicy" to smithyClient.member("retry::NewRequestPolicy"), - "SmithyRetryPolicy" to smithyClient.member("bounds::SmithyRetryPolicy"), + "ParseHttpResponse" to runtimeConfig.smithyHttp().member("response::ParseHttpResponse"), + "NewRequestPolicy" to runtimeConfig.smithyClient().member("retry::NewRequestPolicy"), + "SmithyRetryPolicy" to runtimeConfig.smithyClient().member("bounds::SmithyRetryPolicy"), ) writer.rustTemplate( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt index 8e8cf8f8b2..db56f6f0f5 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt @@ -82,7 +82,7 @@ abstract class FluentClientCustomization : NamedSectionGenerator = emptyList(), - private val retryClassifier: RuntimeType = CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType() - .member("retry::DefaultResponseRetryClassifier"), + private val retryClassifier: RuntimeType = codegenContext.runtimeConfig.smithyHttp().member("retry::DefaultResponseRetryClassifier"), ) { companion object { fun clientOperationFnName(operationShape: OperationShape, symbolProvider: RustSymbolProvider): String = @@ -81,7 +80,7 @@ class FluentClientGenerator( TopDownIndex.of(codegenContext.model).getContainedOperations(serviceShape).sortedBy { it.id } private val symbolProvider = codegenContext.symbolProvider private val model = codegenContext.model - private val clientDep = CargoDependency.SmithyClient(codegenContext.runtimeConfig) + private val clientDep = CargoDependency.smithyClient(codegenContext.runtimeConfig) private val runtimeConfig = codegenContext.runtimeConfig private val core = FluentClientCore(model) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt index f855156820..b0e4beecfb 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt @@ -28,7 +28,7 @@ interface FluentClientGenerics { val bounds: Writable /** Bounds for generated `send()` functions */ - fun sendBounds(operation: Symbol, output: Symbol, error: RuntimeType, retryClassifier: RuntimeType): Writable + fun sendBounds(operation: Symbol, operationOutput: Symbol, operationError: RuntimeType, retryClassifier: RuntimeType): Writable /** Convert this `FluentClientGenerics` into the more general `RustGenerics` */ fun toRustGenerics(): RustGenerics diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt index 6651503429..6e6e167a5a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt @@ -18,12 +18,12 @@ open class EventStreamSigningConfig( private val codegenScope = arrayOf( "SharedPropertyBag" to RuntimeType( "SharedPropertyBag", - CargoDependency.SmithyHttp(runtimeConfig), + CargoDependency.smithyHttp(runtimeConfig), "aws_smithy_http::property_bag", ), "SignMessage" to RuntimeType( "SignMessage", - CargoDependency.SmithyEventStream(runtimeConfig), + CargoDependency.smithyEventStream(runtimeConfig), "aws_smithy_eventstream::frame", ), ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt index 6f670b641f..a80c9db0b5 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt @@ -32,6 +32,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.escape 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.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType @@ -59,7 +60,7 @@ class ProtocolTestGenerator( private val writer: RustWriter, ) { private val logger = Logger.getLogger(javaClass.name) - + private val runtimeConfig = codegenContext.runtimeConfig private val inputShape = operationShape.inputShape(codegenContext.model) private val outputShape = operationShape.outputShape(codegenContext.model) private val operationSymbol = codegenContext.symbolProvider.toSymbol(operationShape) @@ -68,7 +69,7 @@ class ProtocolTestGenerator( private val instantiator = clientInstantiator(codegenContext) private val codegenScope = arrayOf( - "SmithyHttp" to CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType(), + "SmithyHttp" to runtimeConfig.smithyHttp(), "Http" to CargoDependency.Http.asType(), "AssertEq" to CargoDependency.PrettyAssertions.asType().member("assert_eq!"), ) @@ -138,12 +139,12 @@ class ProtocolTestGenerator( testModuleWriter: RustWriter, block: Writable, ) { - testModuleWriter.setNewlinePrefix("/// ") + testModuleWriter.newlinePrefix = "/// " testCase.documentation.map { testModuleWriter.writeWithNoFormatting(it) } testModuleWriter.write("Test ID: ${testCase.id}") - testModuleWriter.setNewlinePrefix("") + testModuleWriter.newlinePrefix = "" TokioTest.render(testModuleWriter) val action = when (testCase) { is HttpResponseTestCase -> Action.Response @@ -283,7 +284,7 @@ class ProtocolTestGenerator( """, "op" to operationSymbol, "bytes" to RuntimeType.Bytes, - "parse_http_response" to CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType() + "parse_http_response" to CargoDependency.smithyHttp(codegenContext.runtimeConfig).asType() .member("response::ParseHttpResponse"), ) if (expectedShape.hasTrait()) { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt index 6b07db5cc4..cdb30ad046 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt @@ -224,22 +224,22 @@ class FakeSigningConfig( private val codegenScope = arrayOf( "SharedPropertyBag" to RuntimeType( "SharedPropertyBag", - CargoDependency.SmithyHttp(runtimeConfig), + CargoDependency.smithyHttp(runtimeConfig), "aws_smithy_http::property_bag", ), "SignMessageError" to RuntimeType( "SignMessageError", - CargoDependency.SmithyEventStream(runtimeConfig), + CargoDependency.smithyEventStream(runtimeConfig), "aws_smithy_eventstream::frame", ), "SignMessage" to RuntimeType( "SignMessage", - CargoDependency.SmithyEventStream(runtimeConfig), + CargoDependency.smithyEventStream(runtimeConfig), "aws_smithy_eventstream::frame", ), "Message" to RuntimeType( "Message", - CargoDependency.SmithyEventStream(runtimeConfig), + CargoDependency.smithyEventStream(runtimeConfig), "aws_smithy_eventstream::frame", ), ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt index bd231f8094..e89d3e41ea 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt @@ -45,12 +45,12 @@ sealed class RustDependency(open val name: String) : SymbolDependencyContainer { * A dependency on a snippet of code * * InlineDependency should not be instantiated directly, rather, it should be constructed with - * [software.amazon.smithy.rust.codegen.smithy.RuntimeType.forInlineFun] + * [software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.forInlineFun] * * InlineDependencies are created as private modules within the main crate. This is useful for any code that * doesn't need to exist in a shared crate, but must still be generated exactly once during codegen. * - * CodegenVisitor deduplicates inline dependencies by (module, name) during code generation. + * CodegenVisitor de-duplicates inline dependencies by (module, name) during code generation. */ class InlineDependency( name: String, @@ -95,11 +95,8 @@ class InlineDependency( fun forRustFile(name: String, vararg additionalDependencies: RustDependency) = forRustFile(name, "inlineable", *additionalDependencies) - fun eventStream(runtimeConfig: RuntimeConfig) = - forRustFile("event_stream", CargoDependency.SmithyEventStream(runtimeConfig)) - fun jsonErrors(runtimeConfig: RuntimeConfig) = - forRustFile("json_errors", CargoDependency.Http, CargoDependency.SmithyTypes(runtimeConfig)) + forRustFile("json_errors", CargoDependency.Http, CargoDependency.smithyTypes(runtimeConfig)) fun idempotencyToken() = forRustFile("idempotency_token", CargoDependency.FastRand) @@ -132,8 +129,6 @@ data class CargoDependency( ) : RustDependency(name) { val key: Triple get() = Triple(name, location, scope) - fun canMergeWith(other: CargoDependency): Boolean = key == other.key - fun withFeature(feature: String): CargoDependency { return copy(features = features.toMutableSet().apply { add(feature) }) } @@ -209,17 +204,24 @@ data class CargoDependency( val Tower: CargoDependency = CargoDependency("tower", CratesIo("0.4")) val Tracing: CargoDependency = CargoDependency("tracing", CratesIo("0.1")) - fun SmithyTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("types") - fun SmithyClient(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("client") - fun SmithyChecksums(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("checksums") - fun SmithyAsync(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("async") - fun SmithyEventStream(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("eventstream") - fun SmithyHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("http") - fun SmithyHttpTower(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("http-tower") - fun SmithyProtocolTestHelpers(runtimeConfig: RuntimeConfig) = - runtimeConfig.runtimeCrate("protocol-test", scope = DependencyScope.Dev) - fun smithyJson(runtimeConfig: RuntimeConfig): CargoDependency = runtimeConfig.runtimeCrate("json") - fun smithyQuery(runtimeConfig: RuntimeConfig): CargoDependency = runtimeConfig.runtimeCrate("query") - fun smithyXml(runtimeConfig: RuntimeConfig): CargoDependency = runtimeConfig.runtimeCrate("xml") + fun smithyChecksums(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-checksums") + fun smithyClient(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-client") + fun smithyEventStream(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-eventstream") + fun smithyHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http") + fun smithyHttpTower(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http-tower") + fun smithyProtocolTestHelpers(runtimeConfig: RuntimeConfig) = + runtimeConfig.smithyRuntimeCrate("smithy-protocol-test", scope = DependencyScope.Dev) + fun smithyTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-types") + fun smithyXml(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-xml") } } + +fun RuntimeConfig.smithyAsync() = smithyRuntimeCrate("smithy-async").asType() +fun RuntimeConfig.smithyChecksums() = smithyRuntimeCrate("smithy-checksums").asType() +fun RuntimeConfig.smithyClient() = smithyRuntimeCrate("smithy-client").asType() +fun RuntimeConfig.smithyEventStream() = smithyRuntimeCrate("smithy-eventstream").asType() +fun RuntimeConfig.smithyHttp() = smithyRuntimeCrate("smithy-http").asType() +fun RuntimeConfig.smithyJson() = smithyRuntimeCrate("smithy-json").asType() +fun RuntimeConfig.smithyQuery() = smithyRuntimeCrate("smithy-query").asType() +fun RuntimeConfig.smithyTypes() = smithyRuntimeCrate("smithy-types").asType() +fun RuntimeConfig.smithyXml() = smithyRuntimeCrate("smithy-xml").asType() diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt index 6ff484bbaa..6a7d36e2e8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt @@ -23,13 +23,11 @@ fun autoDeref(input: String) = if (input.startsWith("&")) { * A hierarchy of types handled by Smithy codegen */ sealed class RustType { - - // TODO(kotlin): when Kotlin supports, sealed interfaces, seal Container /** * A Rust type that contains [member], another RustType. Used to generically operate over * shapes that contain other shapes, e.g. [stripOuter] and [contains]. */ - interface Container { + sealed interface Container { val member: RustType val namespace: kotlin.String? val name: kotlin.String diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt index 8ef035f042..30665f6777 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt @@ -33,7 +33,7 @@ import java.util.function.BiFunction /** * # RustWriter (and Friends) * - * RustWriter contains a set of features to make generating Rust code much more ergonomic ontop of the Smithy CodeWriter + * RustWriter contains a set of features to make generating Rust code much more ergonomic on top of the Smithy CodeWriter * interface. * * ## Recommended Patterns @@ -47,7 +47,7 @@ import java.util.function.BiFunction * writer.rustTemplate(""" * // regular types can be rendered directly * let request = #{http}::Request::builder().uri("http://example.com"); - * // writeables can be rendered with `:W` + * // writables can be rendered with `:W` * let request_headers = #{request_headers:W}; * """, *codegenScope, "request_headers" to requestHeaders()) * ``` @@ -141,7 +141,7 @@ fun > T.rust( /* rewrite #{foo} to #{foo:T} (the smithy template format) */ private fun transformTemplate(template: String, scope: Array>, trim: Boolean = true): String { check(scope.distinctBy { it.first.lowercase() }.size == scope.size) { "Duplicate cased keys not supported" } - val output = template.replace(Regex("""#\{([a-zA-Z_0-9]+)(:\w)?\}""")) { matchResult -> + val output = template.replace(Regex("""#\{([a-zA-Z_0-9]+)(:\w)?}""")) { matchResult -> val keyName = matchResult.groupValues[1] val templateType = matchResult.groupValues[2].ifEmpty { ":T" } if (!scope.toMap().keys.contains(keyName)) { @@ -158,7 +158,7 @@ private fun transformTemplate(template: String, scope: Array> T.rustBlockTemplate( @Language("Rust", prefix = "macro_rules! foo { () => {{ ", suffix = "}}}") contents: String, @@ -333,7 +333,7 @@ private fun Element.changeInto(tagName: String) { /** * Write _exactly_ the text as written into the code writer without newlines or formatting */ -fun RustWriter.raw(text: String) = writeInline(escape(text)) +fun RustWriter.raw(text: String): RustWriter = writeInline(escape(text)) /** * Rustdoc doesn't support `r#` for raw identifiers. @@ -504,10 +504,10 @@ class RustWriter private constructor( override fun toString(): String { val contents = super.toString() - val preheader = if (preamble.isNotEmpty()) { - val prewriter = RustWriter(filename, namespace, printWarning = false) - preamble.forEach { it(prewriter) } - prewriter.toString() + val preHeader = if (preamble.isNotEmpty()) { + val preWriter = RustWriter(filename, namespace, printWarning = false) + preamble.forEach { it(preWriter) } + preWriter.toString() } else null // Hack to support TOML: the [commentCharacter] is overridden to support writing TOML. @@ -517,7 +517,7 @@ class RustWriter private constructor( val useDecls = importContainer.toString().ifEmpty { null } - return listOfNotNull(preheader, header, useDecls, contents).joinToString(separator = "\n", postfix = "\n") + return listOfNotNull(preHeader, header, useDecls, contents).joinToString(separator = "\n", postfix = "\n") } fun format(r: Any) = formatter.apply(r, "") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt index ffe91eb170..a0bd15a1a3 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt @@ -32,8 +32,8 @@ const val CODEGEN_SETTINGS = "codegen" /** * [CoreCodegenConfig] contains code-generation configuration that is _common to all_ smithy-rs plugins. * - * If your configuration is specific to the `rust-codegen` client plugin, put it in [ClientCodegenContext] instead. - * If your configuration is specific to the `rust-server-codegen` server plugin, put it in [ServerCodegenContext] instead. + * If your configuration is specific to the `rust-codegen` client plugin, put it in [software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext] instead. + * If your configuration is specific to the `rust-server-codegen` server plugin, put it in [software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext] instead. * * [formatTimeoutSeconds]: Timeout for running cargo fmt at the end of code generation * [debugMode]: Generate comments in the generated code indicating where code was generated from @@ -65,9 +65,9 @@ open class CoreCodegenConfig( * [CoreRustSettings] contains crate settings that are _common to all_ smithy-rs plugins. * * If your setting is specific to the crate that the `rust-codegen` client plugin generates, put it in - * [ClientCodegenContext] instead. + * [software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext] instead. * If your setting is specific to the crate that the `rust-server-codegen` server plugin generates, put it in - * [ServerCodegenContext] instead. + * [software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext] instead. */ open class CoreRustSettings( open val service: ShapeId, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt index d79059065f..63b377cb3c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt @@ -88,7 +88,7 @@ data class RuntimeConfig( val path = node.getStringMember("relativePath").orNull()?.value val runtimeCrateLocation = RuntimeCrateLocation(path = path, versions = crateVersionMap) return RuntimeConfig( - node.getStringMemberOrDefault("cratePrefix", "aws-smithy"), + node.getStringMemberOrDefault("cratePrefix", "aws"), runtimeCrateLocation = runtimeCrateLocation, ) } @@ -96,7 +96,7 @@ data class RuntimeConfig( val crateSrcPrefix: String = cratePrefix.replace("-", "_") - fun runtimeCrate(runtimeCrateName: String, optional: Boolean = false, scope: DependencyScope = DependencyScope.Compile): CargoDependency { + fun smithyRuntimeCrate(runtimeCrateName: String, optional: Boolean = false, scope: DependencyScope = DependencyScope.Compile): CargoDependency { val crateName = "$cratePrefix-$runtimeCrateName" return CargoDependency( crateName, @@ -177,14 +177,14 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n companion object { fun errorKind(runtimeConfig: RuntimeConfig) = RuntimeType( "ErrorKind", - dependency = CargoDependency.SmithyTypes(runtimeConfig), - namespace = "${runtimeConfig.crateSrcPrefix}_types::retry", + dependency = CargoDependency.smithyTypes(runtimeConfig), + namespace = "${runtimeConfig.crateSrcPrefix}_smithy_types::retry", ) fun provideErrorKind(runtimeConfig: RuntimeConfig) = RuntimeType( "ProvideErrorKind", - dependency = CargoDependency.SmithyTypes(runtimeConfig), - namespace = "${runtimeConfig.crateSrcPrefix}_types::retry", + dependency = CargoDependency.smithyTypes(runtimeConfig), + namespace = "${runtimeConfig.crateSrcPrefix}_smithy_types::retry", ) val std = RuntimeType(null, dependency = null, namespace = "std") @@ -203,38 +203,38 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n val String = RuntimeType("String", dependency = null, namespace = "std::string") fun DateTime(runtimeConfig: RuntimeConfig) = - RuntimeType("DateTime", CargoDependency.SmithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_types") + RuntimeType("DateTime", CargoDependency.smithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_types") fun GenericError(runtimeConfig: RuntimeConfig) = - RuntimeType("Error", CargoDependency.SmithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_types") + RuntimeType("Error", CargoDependency.smithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_types") fun Blob(runtimeConfig: RuntimeConfig) = - RuntimeType("Blob", CargoDependency.SmithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_types") + RuntimeType("Blob", CargoDependency.smithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_types") fun ByteStream(runtimeConfig: RuntimeConfig) = - RuntimeType("ByteStream", CargoDependency.SmithyHttp(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http::byte_stream") + RuntimeType("ByteStream", CargoDependency.smithyHttp(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http::byte_stream") fun Document(runtimeConfig: RuntimeConfig): RuntimeType = - RuntimeType("Document", CargoDependency.SmithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_types") + RuntimeType("Document", CargoDependency.smithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_types") fun LabelFormat(runtimeConfig: RuntimeConfig, func: String) = - RuntimeType(func, CargoDependency.SmithyHttp(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http::label") + RuntimeType(func, CargoDependency.smithyHttp(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http::label") fun QueryFormat(runtimeConfig: RuntimeConfig, func: String) = - RuntimeType(func, CargoDependency.SmithyHttp(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http::query") + RuntimeType(func, CargoDependency.smithyHttp(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http::query") fun Base64Encode(runtimeConfig: RuntimeConfig): RuntimeType = RuntimeType( "encode", - CargoDependency.SmithyTypes(runtimeConfig), - "${runtimeConfig.crateSrcPrefix}_types::base64", + CargoDependency.smithyTypes(runtimeConfig), + "${runtimeConfig.crateSrcPrefix}_smithy_types::base64", ) fun Base64Decode(runtimeConfig: RuntimeConfig): RuntimeType = RuntimeType( "decode", - CargoDependency.SmithyTypes(runtimeConfig), - "${runtimeConfig.crateSrcPrefix}_types::base64", + CargoDependency.smithyTypes(runtimeConfig), + "${runtimeConfig.crateSrcPrefix}_smithy_types::base64", ) fun TimestampFormat(runtimeConfig: RuntimeConfig, format: TimestampFormatTrait.Format): RuntimeType { @@ -246,14 +246,14 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n } return RuntimeType( timestampFormat, - CargoDependency.SmithyTypes(runtimeConfig), - "${runtimeConfig.crateSrcPrefix}_types::date_time::Format", + CargoDependency.smithyTypes(runtimeConfig), + "${runtimeConfig.crateSrcPrefix}_smithy_types::date_time::Format", ) } fun ProtocolTestHelper(runtimeConfig: RuntimeConfig, func: String): RuntimeType = RuntimeType( - func, CargoDependency.SmithyProtocolTestHelpers(runtimeConfig), "aws_smithy_protocol_test", + func, CargoDependency.smithyProtocolTestHelpers(runtimeConfig), "aws_smithy_protocol_test", ) val http = CargoDependency.Http.asType() @@ -266,7 +266,7 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n fun eventStreamReceiver(runtimeConfig: RuntimeConfig): RuntimeType = RuntimeType( "Receiver", - dependency = CargoDependency.SmithyHttp(runtimeConfig), + dependency = CargoDependency.smithyHttp(runtimeConfig), "aws_smithy_http::event_stream", ) @@ -278,22 +278,22 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n fun operation(runtimeConfig: RuntimeConfig) = RuntimeType( "Operation", - dependency = CargoDependency.SmithyHttp(runtimeConfig), + dependency = CargoDependency.smithyHttp(runtimeConfig), namespace = "aws_smithy_http::operation", ) fun operationModule(runtimeConfig: RuntimeConfig) = RuntimeType( null, - dependency = CargoDependency.SmithyHttp(runtimeConfig), + dependency = CargoDependency.smithyHttp(runtimeConfig), namespace = "aws_smithy_http::operation", ) fun sdkBody(runtimeConfig: RuntimeConfig): RuntimeType = - RuntimeType("SdkBody", dependency = CargoDependency.SmithyHttp(runtimeConfig), "aws_smithy_http::body") + RuntimeType("SdkBody", dependency = CargoDependency.smithyHttp(runtimeConfig), "aws_smithy_http::body") fun parseStrictResponse(runtimeConfig: RuntimeConfig) = RuntimeType( "ParseStrictResponse", - dependency = CargoDependency.SmithyHttp(runtimeConfig), + dependency = CargoDependency.smithyHttp(runtimeConfig), namespace = "aws_smithy_http::response", ) @@ -310,7 +310,7 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n fun parseResponse(runtimeConfig: RuntimeConfig) = RuntimeType( "ParseHttpResponse", - dependency = CargoDependency.SmithyHttp(runtimeConfig), + dependency = CargoDependency.smithyHttp(runtimeConfig), namespace = "aws_smithy_http::response", ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt index a58c0c65be..6efab7b0ba 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt @@ -31,16 +31,16 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.HttpPrefixHeadersTrait import software.amazon.smithy.model.traits.StreamingTrait -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.conditionalBlock import software.amazon.smithy.rust.codegen.core.rustlang.escape 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.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig @@ -119,10 +119,12 @@ open class Instantiator( is StringNode -> { val numberSymbol = symbolProvider.toSymbol(shape) // support Smithy custom values, such as Infinity - writer.rust( - """<#T as #T>::parse_smithy_primitive(${data.value.dq()}).expect("invalid string for number")""", - numberSymbol, - CargoDependency.SmithyTypes(runtimeConfig).asType().member("primitive::Parse"), + writer.rustTemplate( + """ + <#{Number} as #{Parse}>::parse_smithy_primitive(${data.value.dq()}).expect("invalid string for number") + """, + "Number" to numberSymbol, + "Parse" to runtimeConfig.smithyTypes().member("primitive::Parse"), ) } @@ -131,15 +133,14 @@ open class Instantiator( is BooleanShape -> writer.rust(data.asBooleanNode().get().toString()) is DocumentShape -> writer.rustBlock("") { - val smithyJson = CargoDependency.smithyJson(runtimeConfig).asType() rustTemplate( """ let json_bytes = br##"${Node.prettyPrintJson(data)}"##; let mut tokens = #{json_token_iter}(json_bytes).peekable(); #{expect_document}(&mut tokens).expect("well formed json") """, - "expect_document" to smithyJson.member("deserialize::token::expect_document"), - "json_token_iter" to smithyJson.member("deserialize::json_token_iter"), + "expect_document" to runtimeConfig.smithyJson().member("deserialize::token::expect_document"), + "json_token_iter" to runtimeConfig.smithyJson().member("deserialize::json_token_iter"), ) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index cbd0a1395c..bf8b58663d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -54,12 +54,12 @@ open class StructureGenerator( ) { private val errorTrait = shape.getTrait() protected val members: List = shape.allMembers.values.toList() - protected val accessorMembers: List = when (errorTrait) { + private val accessorMembers: List = when (errorTrait) { null -> members // Let the ErrorGenerator render the error message accessor if this is an error struct else -> members.filter { "message" != symbolProvider.toMemberName(it) } } - protected val name = symbolProvider.toSymbol(shape).name + protected val name: String = symbolProvider.toSymbol(shape).name fun render(forWhom: CodegenTarget = CodegenTarget.CLIENT) { renderStructure() diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt index e1307e45fd..8278191340 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt @@ -249,7 +249,8 @@ class CombinedErrorGenerator( self.meta.code() } """, - "generic_error" to genericError, "std_error" to RuntimeType.StdError, + "generic_error" to genericError, + "std_error" to RuntimeType.StdError, ) errors.forEach { error -> val errorVariantSymbol = symbolProvider.toSymbol(error) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ErrorGenerator.kt index 07f9315b85..d0c8eaec9c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ErrorGenerator.kt @@ -116,7 +116,7 @@ class ErrorGenerator( writer.rustBlock("impl #T for ${symbol.name}", RuntimeType.Display) { rustBlock("fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result") { // If the error id and the Rust name don't match, print the actual error id for easy debugging - // Note: Exceptions cannot be renamed so it is OK to not call `getName(service)` here + // Note: Exceptions cannot be renamed, so it is OK to not call `getName(service)` here val errorDesc = symbol.name.letIf(symbol.name != shape.id.name) { symbolName -> "$symbolName [${shape.id.name}]" } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt index f83b8b4b3b..f5e5df5e31 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt @@ -50,7 +50,7 @@ class TopLevelErrorGenerator(private val codegenContext: CodegenContext, private .map { codegenContext.model.expectShape(it, StructureShape::class.java) } .sortedBy { it.id.getName(codegenContext.serviceShape) } - private val sdkError = CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType().member("result::SdkError") + private val sdkError = CargoDependency.smithyHttp(codegenContext.runtimeConfig).asType().member("result::SdkError") fun render(crate: RustCrate) { crate.withModule(RustModule.private("error_meta")) { renderDefinition() diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt index 8d089ef8bc..ecdd6ef502 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt @@ -21,18 +21,18 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.MediaTypeTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.asOptional -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref import software.amazon.smithy.rust.codegen.core.rustlang.render 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -97,7 +97,7 @@ class HttpBindingGenerator( private val model = codegenContext.model private val service = codegenContext.serviceShape private val index = HttpBindingIndex.of(model) - private val headerUtil = CargoDependency.SmithyHttp(runtimeConfig).asType().member("header") + private val headerUtil = runtimeConfig.smithyHttp().member("header") private val defaultTimestampFormat = TimestampFormatTrait.Format.EPOCH_SECONDS private val dateTime = RuntimeType.DateTime(runtimeConfig).toSymbol().rustType() private val httpSerdeModule = RustModule.private("http_serde") @@ -190,7 +190,7 @@ class HttpBindingGenerator( val outputT = symbolProvider.toSymbol(binding.member) rustBlock( "pub fn $fnName(body: &mut #T) -> std::result::Result<#T, #T>", - RuntimeType.sdkBody(runtimeConfig), + runtimeConfig.smithyHttp().member("body::SdkBody"), outputT, errorT, ) { @@ -234,7 +234,7 @@ class HttpBindingGenerator( let body = std::mem::replace(body, #{SdkBody}::taken()); Ok(#{Receiver}::new(unmarshaller, body)) """, - "SdkBody" to RuntimeType.sdkBody(runtimeConfig), + "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), "unmarshallerConstructorFn" to unmarshallerConstructorFn, "Receiver" to RuntimeType.eventStreamReceiver(runtimeConfig), ) @@ -250,7 +250,8 @@ class HttpBindingGenerator( let body = std::mem::replace(body, #{SdkBody}::taken()); Ok(#{ByteStream}::new(body)) """, - "ByteStream" to symbolProvider.toSymbol(member), "SdkBody" to RuntimeType.sdkBody(runtimeConfig), + "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), + "ByteStream" to symbolProvider.toSymbol(member), ) } @@ -481,7 +482,7 @@ class HttpBindingGenerator( listForEach(targetShape, field) { innerField, targetId -> val innerMemberType = model.expectShape(targetId) if (innerMemberType.isPrimitive()) { - val encoder = CargoDependency.SmithyTypes(runtimeConfig).asType().member("primitive::Encoder") + val encoder = runtimeConfig.smithyTypes().member("primitive::Encoder") rust("let mut encoder = #T::from(${autoDeref(innerField)});", encoder) } val formatted = headerFmtFun(this, innerMemberType, memberShape, innerField, isListHeader) @@ -492,10 +493,10 @@ class HttpBindingGenerator( """ let header_value = $safeName; let header_value = http::header::HeaderValue::try_from(&*header_value).map_err(|err| { - #{build_error}::InvalidField { - field: "$memberName", + #{build_error}::InvalidField { + field: "$memberName", details: format!( - "`{}` cannot be used as a header value: {}", + "`{}` cannot be used as a header value: {}", &${memberShape.redactIfNecessary(model, "header_value")}, err, ) @@ -531,7 +532,7 @@ class HttpBindingGenerator( #{build_error}::InvalidField { field: "$memberName", details: format!( - "`{}` cannot be used as a header value: {}", + "`{}` cannot be used as a header value: {}", ${memberShape.redactIfNecessary(model, "v")}, err, ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt index dafaeea252..5679bcb660 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt @@ -14,13 +14,12 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref 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.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.generators.OperationBuildError @@ -64,7 +63,7 @@ class RequestBindingGenerator( private val httpTrait = protocol.httpBindingResolver.httpTrait(operationShape) private val httpBindingGenerator = HttpBindingGenerator(protocol, codegenContext, operationShape) private val index = HttpBindingIndex.of(model) - private val Encoder = CargoDependency.SmithyTypes(runtimeConfig).asType().member("primitive::Encoder") + private val Encoder = runtimeConfig.smithyTypes().member("primitive::Encoder") private val codegenScope = arrayOf( "BuildError" to runtimeConfig.operationBuildError(), diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt index df401f7636..b6d5800a00 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt @@ -28,18 +28,17 @@ class RestRequestSpecGenerator( ) { fun generate(operationShape: OperationShape): Writable { val httpTrait = httpBindingResolver.httpTrait(operationShape) - val extraCodegenScope = - arrayOf( - "RequestSpec", - "UriSpec", - "PathAndQuerySpec", - "PathSpec", - "QuerySpec", - "PathSegment", - "QuerySegment", - ).map { - it to requestSpecModule.member(it) - }.toTypedArray() + val codegenScope = arrayOf( + "RequestSpec", + "UriSpec", + "PathAndQuerySpec", + "PathSpec", + "QuerySpec", + "PathSegment", + "QuerySegment", + ).map { + it to requestSpecModule.member(it) + }.toTypedArray() // TODO(https://github.com/awslabs/smithy-rs/issues/950): Support the `endpoint` trait. val pathSegmentsVec = writable { @@ -52,7 +51,7 @@ class RestRequestSpecGenerator( } rustTemplate( "#{PathSegment}::$variant,", - *extraCodegenScope, + *codegenScope, ) } } @@ -66,7 +65,7 @@ class RestRequestSpecGenerator( } else { """KeyValue(String::from("${queryLiteral.key}"), String::from("${queryLiteral.value}"))""" } - rustTemplate("#{QuerySegment}::$variant,", *extraCodegenScope) + rustTemplate("#{QuerySegment}::$variant,", *codegenScope) } } } @@ -84,7 +83,7 @@ class RestRequestSpecGenerator( ), ) """, - *extraCodegenScope, + *codegenScope, "PathSegmentsVec" to pathSegmentsVec, "QuerySegmentsVec" to querySegmentsVec, "Method" to CargoDependency.Http.asType().member("Method"), diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt index c77ef20c4a..209b170416 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt @@ -9,13 +9,12 @@ import software.amazon.smithy.aws.traits.ServiceTrait import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -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 import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -47,8 +46,7 @@ open class MakeOperationGenerator( protected val runtimeConfig = codegenContext.runtimeConfig protected val symbolProvider = codegenContext.symbolProvider protected val httpBindingResolver = protocol.httpBindingResolver - private val defaultClassifier = CargoDependency.SmithyHttp(runtimeConfig) - .asType().member("retry::DefaultResponseRetryClassifier") + private val defaultClassifier = runtimeConfig.smithyHttp().member("retry::DefaultResponseRetryClassifier") private val sdkId = codegenContext.serviceShape.getTrait()?.sdkId?.lowercase()?.replace(" ", "") @@ -56,12 +54,12 @@ open class MakeOperationGenerator( private val codegenScope = arrayOf( "config" to RuntimeType.Config, - "header_util" to CargoDependency.SmithyHttp(runtimeConfig).asType().member("header"), + "header_util" to runtimeConfig.smithyHttp().member("header"), "http" to RuntimeType.http, "HttpRequestBuilder" to RuntimeType.HttpRequestBuilder, - "OpBuildError" to codegenContext.runtimeConfig.operationBuildError(), + "OpBuildError" to runtimeConfig.operationBuildError(), "operation" to RuntimeType.operationModule(runtimeConfig), - "SdkBody" to RuntimeType.sdkBody(codegenContext.runtimeConfig), + "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), ) fun generateMakeOperation( @@ -96,7 +94,7 @@ open class MakeOperationGenerator( withBlock("let mut request = {", "};") { createHttpRequest(this, shape) } - rust("let mut properties = aws_smithy_http::property_bag::SharedPropertyBag::new();") + rust("let mut properties = #T::new();", runtimeConfig.smithyHttp().member("property_bag::SharedPropertyBag")) // When the payload is a `ByteStream`, `into_inner()` already returns an `SdkBody`, so we mute this // Clippy warning to make the codegen a little simpler in that case. diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt index 5869e77f89..07792aa3f6 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt @@ -12,11 +12,11 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ToShapeId import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp +import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.generators.serializationError @@ -83,7 +83,7 @@ class AwsJsonSerializerGenerator( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "Error" to runtimeConfig.serializationError(), - "SdkBody" to RuntimeType.sdkBody(runtimeConfig), + "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), ) override fun operationInputSerializer(operationShape: OperationShape): RuntimeType { @@ -113,7 +113,7 @@ open class AwsJson( "Bytes" to RuntimeType.Bytes, "Error" to RuntimeType.GenericError(runtimeConfig), "HeaderMap" to RuntimeType.http.member("HeaderMap"), - "JsonError" to CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::Error"), + "JsonError" to runtimeConfig.smithyJson().member("deserialize::Error"), "Response" to RuntimeType.http.member("Response"), "json_errors" to RuntimeType.jsonErrors(runtimeConfig), ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt index d2bd4eb9fc..50d407a108 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt @@ -12,11 +12,10 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ToShapeId import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.AwsQueryParserGenerator @@ -47,7 +46,7 @@ class AwsQueryProtocol(private val codegenContext: CodegenContext) : Protocol { "Error" to RuntimeType.GenericError(runtimeConfig), "HeaderMap" to RuntimeType.http.member("HeaderMap"), "Response" to RuntimeType.http.member("Response"), - "XmlError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlError"), + "XmlError" to runtimeConfig.smithyXml().member("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt index 3f9dca4ca6..1fcea534a1 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt @@ -9,11 +9,10 @@ import software.amazon.smithy.model.pattern.UriPattern import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.Ec2QueryParserGenerator @@ -29,7 +28,7 @@ class Ec2QueryProtocol(private val codegenContext: CodegenContext) : Protocol { "Error" to RuntimeType.GenericError(runtimeConfig), "HeaderMap" to RuntimeType.http.member("HeaderMap"), "Response" to RuntimeType.http.member("Response"), - "XmlError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlError"), + "XmlError" to runtimeConfig.smithyXml().member("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt index 69b9b84e0d..71dfbe7139 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt @@ -21,6 +21,8 @@ import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyEventStream +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -55,16 +57,13 @@ class HttpBoundProtocolPayloadGenerator( private val runtimeConfig = codegenContext.runtimeConfig private val target = codegenContext.target private val httpBindingResolver = protocol.httpBindingResolver - private val operationSerModule = RustModule.private("operation_ser") - - private val smithyEventStream = CargoDependency.SmithyEventStream(runtimeConfig) private val codegenScope = arrayOf( "hyper" to CargoDependency.HyperWithStream.asType(), - "SdkBody" to RuntimeType.sdkBody(runtimeConfig), + "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), "BuildError" to runtimeConfig.operationBuildError(), - "SmithyHttp" to CargoDependency.SmithyHttp(runtimeConfig).asType(), - "NoOpSigner" to RuntimeType("NoOpSigner", smithyEventStream, "aws_smithy_eventstream::frame"), + "SmithyHttp" to runtimeConfig.smithyHttp(), + "NoOpSigner" to runtimeConfig.smithyEventStream().member("frame::NoOpSigner"), ) override fun payloadMetadata(operationShape: OperationShape): ProtocolPayloadGenerator.PayloadMetadata { @@ -176,7 +175,7 @@ class HttpBoundProtocolPayloadGenerator( val contentType = when (target) { CodegenTarget.CLIENT -> httpBindingResolver.requestContentType(operationShape) CodegenTarget.SERVER -> httpBindingResolver.responseContentType(operationShape) - } + } ?: throw CodegenException("event streams must set a content type") val errorMarshallerConstructorFn = EventStreamErrorMarshallerGenerator( model, target, @@ -184,7 +183,7 @@ class HttpBoundProtocolPayloadGenerator( symbolProvider, unionShape, serializerGenerator, - contentType ?: throw CodegenException("event streams must set a content type"), + contentType, ).render() val marshallerConstructorFn = EventStreamMarshallerGenerator( model, @@ -193,7 +192,7 @@ class HttpBoundProtocolPayloadGenerator( symbolProvider, unionShape, serializerGenerator, - contentType ?: throw CodegenException("event streams must set a content type"), + contentType, ).render() // TODO(EventStream): [RPC] RPC protocols need to send an initial message with the diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Protocol.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Protocol.kt index c5d93ae3b0..eadd68f01d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Protocol.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Protocol.kt @@ -16,7 +16,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.Structure import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator /** - * Describes a protocol to the [HttpBoundProtocolGenerator]. + * Describes a protocol to the [software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBoundProtocolGenerator]. * * Each protocol (e.g. RestXml, RestJson, etc.) will provide its own implementation of the [Protocol] interface. */ diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt index 7a25fabfdb..8b9f682d4d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt @@ -14,10 +14,9 @@ import software.amazon.smithy.model.traits.JsonNameTrait import software.amazon.smithy.model.traits.MediaTypeTrait import software.amazon.smithy.model.traits.StreamingTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.JsonParserGenerator @@ -67,7 +66,7 @@ open class RestJson(val codegenContext: CodegenContext) : Protocol { "Bytes" to RuntimeType.Bytes, "Error" to RuntimeType.GenericError(runtimeConfig), "HeaderMap" to RuntimeType.http.member("HeaderMap"), - "JsonError" to CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::Error"), + "JsonError" to runtimeConfig.smithyJson().member("deserialize::Error"), "Response" to RuntimeType.http.member("Response"), "json_errors" to RuntimeType.jsonErrors(runtimeConfig), ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt index 268abc0d66..327b0885c4 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt @@ -8,11 +8,10 @@ package software.amazon.smithy.rust.codegen.core.smithy.protocols import software.amazon.smithy.aws.traits.protocols.RestXmlTrait import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.RestXmlParserGenerator @@ -29,7 +28,7 @@ open class RestXml(val codegenContext: CodegenContext) : Protocol { "Error" to RuntimeType.GenericError(runtimeConfig), "HeaderMap" to RuntimeType.http.member("HeaderMap"), "Response" to RuntimeType.http.member("Response"), - "XmlError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlError"), + "XmlError" to runtimeConfig.smithyXml().member("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt index 2d3e07957f..41f1c04885 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt @@ -30,6 +30,8 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyEventStream +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig @@ -56,31 +58,30 @@ class EventStreamUnmarshallerGenerator( private val target: CodegenTarget, ) { private val unionSymbol = symbolProvider.toSymbol(unionShape) - private val smithyEventStream = CargoDependency.SmithyEventStream(runtimeConfig) private val errorSymbol = if (target == CodegenTarget.SERVER && unionShape.eventStreamErrors().isEmpty()) { - RuntimeType("MessageStreamError", smithyEventStream, "aws_smithy_http::event_stream").toSymbol() + runtimeConfig.smithyEventStream().member("event_stream::MessageStreamError").toSymbol() } else { unionShape.eventStreamErrorSymbol(model, symbolProvider, target).toSymbol() } private val eventStreamSerdeModule = RustModule.private("event_stream_serde") private val codegenScope = arrayOf( - "Blob" to RuntimeType("Blob", CargoDependency.SmithyTypes(runtimeConfig), "aws_smithy_types"), - "Error" to RuntimeType("Error", smithyEventStream, "aws_smithy_eventstream::error"), - "expect_fns" to RuntimeType("smithy", smithyEventStream, "aws_smithy_eventstream"), - "Header" to RuntimeType("Header", smithyEventStream, "aws_smithy_eventstream::frame"), - "HeaderValue" to RuntimeType("HeaderValue", smithyEventStream, "aws_smithy_eventstream::frame"), - "Message" to RuntimeType("Message", smithyEventStream, "aws_smithy_eventstream::frame"), + "Blob" to runtimeConfig.smithyTypes().member("Blob"), + "Error" to runtimeConfig.smithyEventStream().member("error::Error"), + "expect_fns" to runtimeConfig.smithyEventStream().member("smithy"), + "Header" to runtimeConfig.smithyEventStream().member("frame::Header"), + "HeaderValue" to runtimeConfig.smithyEventStream().member("frame::HeaderValue"), + "Message" to runtimeConfig.smithyEventStream().member("frame::Message"), "OpError" to errorSymbol, - "SmithyError" to RuntimeType("Error", CargoDependency.SmithyTypes(runtimeConfig), "aws_smithy_types"), + "SmithyError" to runtimeConfig.smithyTypes().member("Error"), "tracing" to CargoDependency.Tracing.asType(), - "UnmarshalledMessage" to RuntimeType("UnmarshalledMessage", smithyEventStream, "aws_smithy_eventstream::frame"), - "UnmarshallMessage" to RuntimeType("UnmarshallMessage", smithyEventStream, "aws_smithy_eventstream::frame"), + "UnmarshalledMessage" to runtimeConfig.smithyEventStream().member("frame::UnmarshalledMessage"), + "UnmarshallMessage" to runtimeConfig.smithyEventStream().member("frame::UnmarshallMessage"), ) fun render(): RuntimeType { val unmarshallerType = unionShape.eventStreamUnmarshallerType() return RuntimeType.forInlineFun("${unmarshallerType.name}::new", eventStreamSerdeModule) { - renderUnmarshaller(unmarshallerType, unionSymbol) + renderUnmarshaller(unmarshallerType, symbolProvider.toSymbol(unionShape)) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt index 43c18287a5..cb11209463 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt @@ -21,16 +21,15 @@ import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.SparseTrait import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.escape 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -64,25 +63,25 @@ class JsonParserGenerator( private val symbolProvider = codegenContext.symbolProvider private val runtimeConfig = codegenContext.runtimeConfig private val target = codegenContext.target - private val smithyJson = CargoDependency.smithyJson(runtimeConfig).asType() + private val smithyJsonDeser = runtimeConfig.smithyJson().member("deserialize") private val jsonDeserModule = RustModule.private("json_deser") private val typeConversionGenerator = TypeConversionGenerator(model, symbolProvider, runtimeConfig) private val codegenScope = arrayOf( - "Error" to smithyJson.member("deserialize::Error"), - "ErrorReason" to smithyJson.member("deserialize::ErrorReason"), - "expect_blob_or_null" to smithyJson.member("deserialize::token::expect_blob_or_null"), - "expect_bool_or_null" to smithyJson.member("deserialize::token::expect_bool_or_null"), - "expect_document" to smithyJson.member("deserialize::token::expect_document"), - "expect_number_or_null" to smithyJson.member("deserialize::token::expect_number_or_null"), - "expect_start_array" to smithyJson.member("deserialize::token::expect_start_array"), - "expect_start_object" to smithyJson.member("deserialize::token::expect_start_object"), - "expect_string_or_null" to smithyJson.member("deserialize::token::expect_string_or_null"), - "expect_timestamp_or_null" to smithyJson.member("deserialize::token::expect_timestamp_or_null"), - "json_token_iter" to smithyJson.member("deserialize::json_token_iter"), + "Error" to smithyJsonDeser.member("Error"), + "ErrorReason" to smithyJsonDeser.member("ErrorReason"), + "expect_blob_or_null" to smithyJsonDeser.member("token::expect_blob_or_null"), + "expect_bool_or_null" to smithyJsonDeser.member("token::expect_bool_or_null"), + "expect_document" to smithyJsonDeser.member("token::expect_document"), + "expect_number_or_null" to smithyJsonDeser.member("token::expect_number_or_null"), + "expect_start_array" to smithyJsonDeser.member("token::expect_start_array"), + "expect_start_object" to smithyJsonDeser.member("token::expect_start_object"), + "expect_string_or_null" to smithyJsonDeser.member("token::expect_string_or_null"), + "expect_timestamp_or_null" to smithyJsonDeser.member("token::expect_timestamp_or_null"), + "json_token_iter" to smithyJsonDeser.member("json_token_iter"), "Peekable" to RuntimeType.std.member("iter::Peekable"), - "skip_value" to smithyJson.member("deserialize::token::skip_value"), - "skip_to_end" to smithyJson.member("deserialize::token::skip_to_end"), - "Token" to smithyJson.member("deserialize::Token"), + "skip_value" to smithyJsonDeser.member("token::skip_value"), + "skip_to_end" to smithyJsonDeser.member("token::skip_to_end"), + "Token" to smithyJsonDeser.member("Token"), "or_empty" to orEmptyJson(), ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt index 841975c229..79aa24c28b 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt @@ -25,17 +25,17 @@ import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.model.traits.XmlFlattenedTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.conditionalBlock import software.amazon.smithy.rust.codegen.core.rustlang.escape 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes +import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -85,7 +85,7 @@ class XmlBindingTraitParserGenerator( } /** - * Codegeneration Context + * Code generation Context * * [tag]: The symbol name of the current tag * [accum]: Flattened lists and maps need to be written into an accumulator. When a flattened list / map @@ -96,21 +96,16 @@ class XmlBindingTraitParserGenerator( data class Ctx(val tag: String, val accum: String?) private val symbolProvider = codegenContext.symbolProvider - private val smithyXml = CargoDependency.smithyXml(codegenContext.runtimeConfig).asType() - private val xmlError = smithyXml.member("decode::XmlError") - - private val scopedDecoder = smithyXml.member("decode::ScopedDecoder") private val runtimeConfig = codegenContext.runtimeConfig - - // The symbols we want all the time + private val xmlError = runtimeConfig.smithyXml().member("decode::XmlError") private val codegenScope = arrayOf( "Blob" to RuntimeType.Blob(runtimeConfig), - "Document" to smithyXml.member("decode::Document"), + "Document" to runtimeConfig.smithyXml().member("decode::Document"), "XmlError" to xmlError, - "next_start_element" to smithyXml.member("decode::next_start_element"), - "try_data" to smithyXml.member("decode::try_data"), - "ScopedDecoder" to scopedDecoder, - "aws_smithy_types" to CargoDependency.SmithyTypes(runtimeConfig).asType(), + "next_start_element" to runtimeConfig.smithyXml().member("decode::next_start_element"), + "try_data" to runtimeConfig.smithyXml().member("decode::try_data"), + "ScopedDecoder" to runtimeConfig.smithyXml().member("decode::ScopedDecoder"), + "aws_smithy_types" to runtimeConfig.smithyTypes(), ) private val model = codegenContext.model private val index = HttpBindingIndex.of(model) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt index f71b4a96e1..e515e9c3fd 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt @@ -21,6 +21,7 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyEventStream import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType @@ -45,7 +46,7 @@ class EventStreamErrorMarshallerGenerator( private val serializerGenerator: StructuredDataSerializerGenerator, payloadContentType: String, ) : EventStreamMarshallerGenerator(model, target, runtimeConfig, symbolProvider, unionShape, serializerGenerator, payloadContentType) { - private val smithyEventStream = CargoDependency.SmithyEventStream(runtimeConfig) + private val smithyEventStream = CargoDependency.smithyEventStream(runtimeConfig) private val operationErrorSymbol = if (target == CodegenTarget.SERVER && unionShape.eventStreamErrors().isEmpty()) { RuntimeType("MessageStreamError", smithyEventStream, "aws_smithy_http::event_stream").toSymbol() } else { @@ -54,11 +55,11 @@ class EventStreamErrorMarshallerGenerator( private val eventStreamSerdeModule = RustModule.private("event_stream_serde") private val errorsShape = unionShape.expectTrait() private val codegenScope = arrayOf( - "MarshallMessage" to RuntimeType("MarshallMessage", smithyEventStream, "aws_smithy_eventstream::frame"), - "Message" to RuntimeType("Message", smithyEventStream, "aws_smithy_eventstream::frame"), - "Header" to RuntimeType("Header", smithyEventStream, "aws_smithy_eventstream::frame"), - "HeaderValue" to RuntimeType("HeaderValue", smithyEventStream, "aws_smithy_eventstream::frame"), - "Error" to RuntimeType("Error", smithyEventStream, "aws_smithy_eventstream::error"), + "MarshallMessage" to runtimeConfig.smithyEventStream().member("frame::MarshallMessage"), + "Message" to runtimeConfig.smithyEventStream().member("frame::Message"), + "Header" to runtimeConfig.smithyEventStream().member("frame::Header"), + "HeaderValue" to runtimeConfig.smithyEventStream().member("frame::HeaderValue"), + "Error" to runtimeConfig.smithyEventStream().member("error::Error"), ) override fun render(): RuntimeType { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt index 918bb18925..dfd6471ce9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt @@ -21,7 +21,6 @@ import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EventHeaderTrait import software.amazon.smithy.model.traits.EventPayloadTrait -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.Writable @@ -30,6 +29,7 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyEventStream import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig @@ -53,14 +53,13 @@ open class EventStreamMarshallerGenerator( private val serializerGenerator: StructuredDataSerializerGenerator, private val payloadContentType: String, ) { - private val smithyEventStream = CargoDependency.SmithyEventStream(runtimeConfig) private val eventStreamSerdeModule = RustModule.private("event_stream_serde") private val codegenScope = arrayOf( - "MarshallMessage" to RuntimeType("MarshallMessage", smithyEventStream, "aws_smithy_eventstream::frame"), - "Message" to RuntimeType("Message", smithyEventStream, "aws_smithy_eventstream::frame"), - "Header" to RuntimeType("Header", smithyEventStream, "aws_smithy_eventstream::frame"), - "HeaderValue" to RuntimeType("HeaderValue", smithyEventStream, "aws_smithy_eventstream::frame"), - "Error" to RuntimeType("Error", smithyEventStream, "aws_smithy_eventstream::error"), + "MarshallMessage" to runtimeConfig.smithyEventStream().member("frame::MarshallMessage"), + "Message" to runtimeConfig.smithyEventStream().member("frame::Message"), + "Header" to runtimeConfig.smithyEventStream().member("frame::Header"), + "HeaderValue" to runtimeConfig.smithyEventStream().member("frame::HeaderValue"), + "Error" to runtimeConfig.smithyEventStream().member("error::Error"), ) open fun render(): RuntimeType { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt index 415a0a8de8..d7979b2e92 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt @@ -21,15 +21,16 @@ import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.TimestampFormatTrait.Format.EPOCH_SECONDS -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.asType 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp +import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType @@ -156,15 +157,14 @@ class JsonSerializerGenerator( private val symbolProvider = codegenContext.symbolProvider private val target = codegenContext.target private val runtimeConfig = codegenContext.runtimeConfig - private val smithyTypes = CargoDependency.SmithyTypes(runtimeConfig).asType() - private val smithyJson = CargoDependency.smithyJson(runtimeConfig).asType() private val codegenScope = arrayOf( - "String" to RuntimeType.String, - "Error" to runtimeConfig.serializationError(), - "SdkBody" to RuntimeType.sdkBody(runtimeConfig), - "JsonObjectWriter" to smithyJson.member("serialize::JsonObjectWriter"), - "JsonValueWriter" to smithyJson.member("serialize::JsonValueWriter"), "ByteSlab" to RuntimeType.ByteSlab, + "Error" to runtimeConfig.serializationError(), + "JsonObjectWriter" to runtimeConfig.smithyJson().member("serialize::JsonObjectWriter"), + "JsonValueWriter" to runtimeConfig.smithyJson().member("serialize::JsonValueWriter"), + "Number" to runtimeConfig.smithyTypes().member("Number"), + "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), + "String" to RuntimeType.String, ) private val serializerUtil = SerializerUtil(model) private val operationSerModule = RustModule.private("operation_ser") @@ -368,9 +368,9 @@ class JsonSerializerGenerator( is RustType.Integer -> "NegInt" else -> throw IllegalStateException("unreachable") } - rust( - "$writer.number(##[allow(clippy::useless_conversion)]#T::$numberType((${value.asValue()}).into()));", - smithyTypes.member("Number"), + rustTemplate( + "$writer.number(##[allow(clippy::useless_conversion)]#{Number}::$numberType((${value.asValue()}).into()));", + *codegenScope, ) } is BlobShape -> rust( diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt index 70808148df..5dda05091b 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt @@ -21,15 +21,16 @@ import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.model.traits.XmlNameTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.asType 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp +import software.amazon.smithy.rust.codegen.core.rustlang.smithyQuery +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType @@ -93,15 +94,13 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct private val target = codegenContext.target private val serviceShape = codegenContext.serviceShape private val serializerError = runtimeConfig.serializationError() - private val smithyTypes = CargoDependency.SmithyTypes(runtimeConfig).asType() - private val smithyQuery = CargoDependency.smithyQuery(runtimeConfig).asType() private val serdeUtil = SerializerUtil(model) private val codegenScope = arrayOf( "String" to RuntimeType.String, "Error" to serializerError, - "SdkBody" to RuntimeType.sdkBody(runtimeConfig), - "QueryWriter" to smithyQuery.member("QueryWriter"), - "QueryValueWriter" to smithyQuery.member("QueryValueWriter"), + "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), + "QueryWriter" to runtimeConfig.smithyQuery().member("QueryWriter"), + "QueryValueWriter" to runtimeConfig.smithyQuery().member("QueryValueWriter"), ) private val operationSerModule = RustModule.private("operation_ser") private val querySerModule = RustModule.private("query_ser") @@ -219,7 +218,7 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct } rust( "$writer.number(##[allow(clippy::useless_conversion)]#T::$numberType((${value.asValue()}).into()));", - smithyTypes.member("Number"), + runtimeConfig.smithyTypes().member("Number"), ) } is BlobShape -> rust( diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt index 2ca848e075..8a7bda57a8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt @@ -23,17 +23,18 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.model.traits.XmlFlattenedTrait import software.amazon.smithy.model.traits.XmlNamespaceTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref import software.amazon.smithy.rust.codegen.core.rustlang.render 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes +import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -62,13 +63,12 @@ class XmlBindingTraitSerializerGenerator( private val symbolProvider = codegenContext.symbolProvider private val runtimeConfig = codegenContext.runtimeConfig private val model = codegenContext.model - private val smithyXml = CargoDependency.smithyXml(runtimeConfig).asType() private val target = codegenContext.target private val codegenScope = arrayOf( - "XmlWriter" to smithyXml.member("encode::XmlWriter"), - "ElementWriter" to smithyXml.member("encode::ElWriter"), - "SdkBody" to RuntimeType.sdkBody(runtimeConfig), + "XmlWriter" to runtimeConfig.smithyXml().member("encode::XmlWriter"), + "ElementWriter" to runtimeConfig.smithyXml().member("encode::ElWriter"), + "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), "Error" to runtimeConfig.serializationError(), ) private val operationSerModule = RustModule.private("operation_ser") @@ -296,7 +296,7 @@ class XmlBindingTraitSerializerGenerator( is BooleanShape, is NumberShape -> { rust( "#T::from(${autoDeref(input)}).encode()", - CargoDependency.SmithyTypes(runtimeConfig).asType().member("primitive::Encoder"), + runtimeConfig.smithyTypes().member("primitive::Encoder"), ) } is BlobShape -> rust("#T($input.as_ref()).as_ref()", RuntimeType.Base64Encode(runtimeConfig)) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/RustBoxTrait.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/RustBoxTrait.kt index 2d5a313401..df349f3c9b 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/RustBoxTrait.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/RustBoxTrait.kt @@ -17,7 +17,7 @@ import software.amazon.smithy.model.traits.Trait * This trait is synthetic, applied during code generation, and never used in actual models. */ class RustBoxTrait : Trait { - val ID = ShapeId.from("software.amazon.smithy.rust.codegen.smithy.rust.synthetic#box") + val ID: ShapeId = ShapeId.from("software.amazon.smithy.rust.codegen.smithy.rust.synthetic#box") override fun toNode(): Node = Node.objectNode() override fun toShapeId(): ShapeId = ID diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/SyntheticEventStreamUnionTrait.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/SyntheticEventStreamUnionTrait.kt index a609a59fdf..73a3bbb212 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/SyntheticEventStreamUnionTrait.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/SyntheticEventStreamUnionTrait.kt @@ -14,6 +14,6 @@ class SyntheticEventStreamUnionTrait( val errorMembers: List, ) : AnnotationTrait(ID, Node.objectNode()) { companion object { - val ID = ShapeId.from("smithy.api.internal#syntheticEventStreamUnion") + val ID: ShapeId = ShapeId.from("smithy.api.internal#syntheticEventStreamUnion") } } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt index 0957405454..30ac1d70ea 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt @@ -25,6 +25,6 @@ object PythonServerCargoDependency { val NumCpus: CargoDependency = CargoDependency("num_cpus", CratesIo("1.13")) val ParkingLot: CargoDependency = CargoDependency("parking_lot", CratesIo("0.12")) - fun SmithyHttpServer(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("http-server") - fun SmithyHttpServerPython(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("http-server-python") + fun SmithyHttpServer(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http-server") + fun SmithyHttpServerPython(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http-server-python") } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt index 0452dacdf1..199d36a52a 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt @@ -16,17 +16,17 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType object PythonServerRuntimeType { fun PySocket(runtimeConfig: RuntimeConfig) = - RuntimeType("PySocket", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server_python") + RuntimeType("PySocket", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python") fun Blob(runtimeConfig: RuntimeConfig) = - RuntimeType("Blob", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server_python::types") + RuntimeType("Blob", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") fun ByteStream(runtimeConfig: RuntimeConfig) = - RuntimeType("ByteStream", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server_python::types") + RuntimeType("ByteStream", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") fun DateTime(runtimeConfig: RuntimeConfig) = - RuntimeType("DateTime", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server_python::types") + RuntimeType("DateTime", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") fun PyError(runtimeConfig: RuntimeConfig) = - RuntimeType("Error", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server_python") + RuntimeType("Error", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python") } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt index 2dd7c76aee..3cc6945fb3 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt @@ -77,7 +77,7 @@ class PythonApplicationGenerator( private val codegenScope = arrayOf( "SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig).asType(), - "SmithyServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), + "SmithyServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "pyo3" to PythonServerCargoDependency.PyO3.asType(), "pyo3_asyncio" to PythonServerCargoDependency.PyO3Asyncio.asType(), "tokio" to PythonServerCargoDependency.Tokio.asType(), diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt index 076a757014..6290e755b7 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt @@ -42,7 +42,7 @@ class PythonServerOperationHandlerGenerator( private val codegenScope = arrayOf( "SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig).asType(), - "SmithyServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), + "SmithyServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "pyo3" to PythonServerCargoDependency.PyO3.asType(), "pyo3_asyncio" to PythonServerCargoDependency.PyO3Asyncio.asType(), "tokio" to PythonServerCargoDependency.Tokio.asType(), diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCargoDependency.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCargoDependency.kt index 6058519abf..63f79027ff 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCargoDependency.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCargoDependency.kt @@ -26,7 +26,7 @@ object ServerCargoDependency { val Tower: CargoDependency = CargoDependency("tower", CratesIo("0.4")) val TokioDev: CargoDependency = CargoDependency("tokio", CratesIo("1.8.4"), scope = DependencyScope.Dev) - fun SmithyHttpServer(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("http-server") + fun smithyHttpServer(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http-server") } /** @@ -44,7 +44,7 @@ object ServerInlineDependency { fun serverOperationHandler(runtimeConfig: RuntimeConfig): InlineDependency = InlineDependency.forRustFile( "server_operation_handler_trait", - ServerCargoDependency.SmithyHttpServer(runtimeConfig), + ServerCargoDependency.smithyHttpServer(runtimeConfig), CargoDependency.Http, ServerCargoDependency.PinProjectLite, ServerCargoDependency.Tower, diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt index 4b7f18ba89..3a03931c2a 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt @@ -22,25 +22,25 @@ object ServerRuntimeType { val Cow = RuntimeType("Cow", dependency = null, namespace = "std::borrow") fun Router(runtimeConfig: RuntimeConfig) = - RuntimeType("Router", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::routing") + RuntimeType("Router", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::routing") fun RequestSpecModule(runtimeConfig: RuntimeConfig) = - RuntimeType("request_spec", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::routing") + RuntimeType("request_spec", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::routing") fun OperationHandler(runtimeConfig: RuntimeConfig) = forInlineDependency(ServerInlineDependency.serverOperationHandler(runtimeConfig)) fun RuntimeError(runtimeConfig: RuntimeConfig) = - RuntimeType("RuntimeError", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::runtime_error") + RuntimeType("RuntimeError", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::runtime_error") fun RequestRejection(runtimeConfig: RuntimeConfig) = - RuntimeType("RequestRejection", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::rejection") + RuntimeType("RequestRejection", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::rejection") fun ResponseRejection(runtimeConfig: RuntimeConfig) = - RuntimeType("ResponseRejection", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::rejection") + RuntimeType("ResponseRejection", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::rejection") fun Protocol(name: String, path: String, runtimeConfig: RuntimeConfig) = - RuntimeType(name, ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::proto::" + path) + RuntimeType(name, ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::proto::" + path) fun Protocol(runtimeConfig: RuntimeConfig) = Protocol("Protocol", "", runtimeConfig) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt index 5dace38b85..e8c9d01b8a 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt @@ -35,7 +35,7 @@ import java.util.Optional /** Models the ways status codes can be bound and sensitive. */ class StatusCodeSensitivity(private val sensitive: Boolean, runtimeConfig: RuntimeConfig) { private val codegenScope = arrayOf( - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), ) /** Returns the type of the `MakeFmt`. */ @@ -65,7 +65,7 @@ data class GreedyLabel( /** Models the ways labels can be bound and sensitive. */ class LabelSensitivity(internal val labelIndexes: List, internal val greedyLabel: GreedyLabel?, runtimeConfig: RuntimeConfig) { - private val codegenScope = arrayOf("SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType()) + private val codegenScope = arrayOf("SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType()) /** Returns the closure used during construction. */ fun closure(): Writable = writable { @@ -117,7 +117,7 @@ sealed class HeaderSensitivity( runtimeConfig: RuntimeConfig, ) { private val codegenScope = arrayOf( - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "Http" to CargoDependency.Http.asType(), ) @@ -219,7 +219,7 @@ sealed class QuerySensitivity( val allKeysSensitive: Boolean, runtimeConfig: RuntimeConfig, ) { - private val codegenScope = arrayOf("SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType()) + private val codegenScope = arrayOf("SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType()) /** The case where the `httpQueryParams` value is not sensitive. */ class NotSensitiveMapValue( @@ -307,7 +307,7 @@ class ServerHttpSensitivityGenerator( private val runtimeConfig: RuntimeConfig, ) { private val codegenScope = arrayOf( - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "Http" to CargoDependency.Http.asType(), ) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt index b61b1baa45..ee049222e6 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt @@ -25,7 +25,7 @@ class ServerOperationGenerator( private val codegenScope = arrayOf( "SmithyHttpServer" to - ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), + ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), ) private val symbolProvider = codegenContext.symbolProvider private val model = codegenContext.model diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt index 5a3c93b2be..5a2f6346fe 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt @@ -6,7 +6,6 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate @@ -40,8 +39,8 @@ open class ServerOperationHandlerGenerator( "AsyncTrait" to ServerCargoDependency.AsyncTrait.asType(), "Tower" to ServerCargoDependency.Tower.asType(), "FuturesUtil" to ServerCargoDependency.FuturesUtil.asType(), - "SmithyHttp" to CargoDependency.SmithyHttp(runtimeConfig).asType(), - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), + "SmithyHttp" to runtimeConfig.smithyHttp(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "Phantom" to ServerRuntimeType.Phantom, "ServerOperationHandler" to ServerRuntimeType.OperationHandler(runtimeConfig), "http" to RuntimeType.http, diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt index 1952c0f934..90cffc4edd 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt @@ -60,7 +60,7 @@ class ServerOperationRegistryGenerator( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "Router" to ServerRuntimeType.Router(runtimeConfig), - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "ServerOperationHandler" to ServerRuntimeType.OperationHandler(runtimeConfig), "Tower" to ServerCargoDependency.Tower.asType(), "Phantom" to ServerRuntimeType.Phantom, @@ -400,6 +400,6 @@ ${operationImplementationStubs(operations)} this, symbolProvider.toSymbol(this).name, serviceName, - ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType().member("routing::request_spec"), + ServerCargoDependency.smithyHttpServer(runtimeConfig).asType().member("routing::request_spec"), ) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt index eb44ffab1d..1458ea8885 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt @@ -33,7 +33,7 @@ class ServerServiceGeneratorV2( "Http" to CargoDependency.Http.asType(), "HttpBody" to CargoDependency.HttpBody.asType(), "SmithyHttpServer" to - ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), + ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "Tower" to CargoDependency.Tower.asType(), ) private val model = codegenContext.model diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt index 2dea2153b2..ebfc0a0cc3 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt @@ -84,7 +84,7 @@ class ServerAwsJsonProtocol( ) : AwsJson(codegenContext, awsJsonVersion), ServerProtocol { private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), ) private val symbolProvider = codegenContext.symbolProvider private val service = codegenContext.serviceShape @@ -107,7 +107,7 @@ class ServerAwsJsonProtocol( } } - override fun routerType() = RuntimeType("AwsJsonRouter", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::proto::aws_json::router") + override fun routerType() = RuntimeType("AwsJsonRouter", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::proto::aws_json::router") override fun routerConstruction(operationValues: Iterable): Writable = writable { val allOperationShapes = allOperations(codegenContext) @@ -158,7 +158,7 @@ class ServerAwsJsonProtocol( } } -private fun restRouterType(runtimeConfig: RuntimeConfig) = RuntimeType("RestRouter", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::proto::rest::router") +private fun restRouterType(runtimeConfig: RuntimeConfig) = RuntimeType("RestRouter", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::proto::rest::router") private fun restRouterConstruction( protocol: ServerProtocol, @@ -178,7 +178,7 @@ private fun restRouterConstruction( operationShape, operationName, serviceName, - ServerCargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).asType().member("routing::request_spec"), + ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).asType().member("routing::request_spec"), ) rustTemplate( """ @@ -189,7 +189,7 @@ private fun restRouterConstruction( """, "Key" to key, "OperationValue" to operationValue, - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).asType(), ) } } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt index ad28e4bc71..912b0bc876 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt @@ -103,12 +103,12 @@ class ServerProtocolTestGenerator( private val codegenScope = arrayOf( "Bytes" to RuntimeType.Bytes, - "SmithyHttp" to CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType(), + "SmithyHttp" to CargoDependency.smithyHttp(codegenContext.runtimeConfig).asType(), "Http" to CargoDependency.Http.asType(), "Hyper" to CargoDependency.Hyper.asType(), "Tokio" to ServerCargoDependency.TokioDev.asType(), "Tower" to CargoDependency.Tower.asType(), - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).asType(), "AssertEq" to CargoDependency.PrettyAssertions.asType().member("assert_eq!"), "Router" to ServerRuntimeType.Router(codegenContext.runtimeConfig), ) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt index 2cf86be5eb..64312be41e 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt @@ -37,6 +37,10 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp +import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson +import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes +import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable @@ -131,7 +135,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( "DateTime" to RuntimeType.DateTime(runtimeConfig), "FormUrlEncoded" to ServerCargoDependency.FormUrlEncoded.asType(), "HttpBody" to CargoDependency.HttpBody.asType(), - "header_util" to CargoDependency.SmithyHttp(runtimeConfig).asType().member("header"), + "header_util" to runtimeConfig.smithyHttp().member("header"), "Hyper" to CargoDependency.Hyper.asType(), "LazyStatic" to CargoDependency.LazyStatic.asType(), "Mime" to ServerCargoDependency.Mime.asType(), @@ -139,8 +143,8 @@ private class ServerHttpBoundProtocolTraitImplGenerator( "OnceCell" to ServerCargoDependency.OnceCell.asType(), "PercentEncoding" to CargoDependency.PercentEncoding.asType(), "Regex" to CargoDependency.Regex.asType(), - "SmithyHttp" to CargoDependency.SmithyHttp(runtimeConfig).asType(), - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), + "SmithyHttp" to runtimeConfig.smithyHttp(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "RuntimeError" to ServerRuntimeType.RuntimeError(runtimeConfig), "RequestRejection" to ServerRuntimeType.RequestRejection(runtimeConfig), "ResponseRejection" to ServerRuntimeType.ResponseRejection(runtimeConfig), @@ -965,7 +969,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( rustTemplate( "let mut query_params: #{HashMap} = #{HashMap}::new();", - "HashMap" to software.amazon.smithy.rust.codegen.core.rustlang.RustType.HashMap.RuntimeType, + "HashMap" to RustType.HashMap.RuntimeType, ) } val (queryBindingsTargettingCollection, queryBindingsTargettingSimple) = @@ -1033,7 +1037,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( """ let v = <_ as #T>::parse_smithy_primitive(&v)?; """.trimIndent(), - CargoDependency.SmithyTypes(runtimeConfig).asType().member("primitive::Parse"), + runtimeConfig.smithyTypes().member("primitive::Parse"), ) } } @@ -1215,10 +1219,10 @@ private class ServerHttpBoundProtocolTraitImplGenerator( } when (codegenContext.protocol) { RestJson1Trait.ID, AwsJson1_0Trait.ID, AwsJson1_1Trait.ID -> { - return CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize").member("Error") + return runtimeConfig.smithyJson().member("deserialize").member("Error") } RestXmlTrait.ID -> { - return CargoDependency.smithyXml(runtimeConfig).asType().member("decode").member("XmlError") + return runtimeConfig.smithyXml().member("decode").member("XmlError") } else -> { TODO("Protocol ${codegenContext.protocol} not supported yet") diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt index 55b7c462ac..1353d119fe 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt @@ -23,7 +23,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverTestSymb class ServerHttpSensitivityGeneratorTest { private val codegenScope = arrayOf( - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(TestRuntimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(TestRuntimeConfig).asType(), "Http" to CargoDependency.Http.asType(), ) diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt index 9b87304554..6b8638df69 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt @@ -47,7 +47,7 @@ class EventStreamMarshallerGeneratorTest { ) test.project.lib { - val protocolTestHelpers = CargoDependency.SmithyProtocolTestHelpers(TestRuntimeConfig) + val protocolTestHelpers = CargoDependency.smithyProtocolTestHelpers(TestRuntimeConfig) .copy(scope = DependencyScope.Compile) rustTemplate( """ From f652e30de339831da4255b070c76644c3fec3b76 Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Tue, 1 Nov 2022 16:52:57 -0500 Subject: [PATCH 05/19] fix: build.gradle.kts improper delegation issue add: missing imports to test --- aws/sdk-adhoc-test/build.gradle.kts | 3 +-- .../amazon/smithy/rustsdk/AwsPresigningDecoratorTest.kt | 5 +++++ aws/sdk/build.gradle.kts | 9 ++++++--- codegen-client-test/build.gradle.kts | 3 +-- codegen-server-test/build.gradle.kts | 3 +-- codegen-server-test/python/build.gradle.kts | 3 +-- settings.gradle.kts | 7 +++++++ 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/aws/sdk-adhoc-test/build.gradle.kts b/aws/sdk-adhoc-test/build.gradle.kts index b6d59ef47c..5137acd20e 100644 --- a/aws/sdk-adhoc-test/build.gradle.kts +++ b/aws/sdk-adhoc-test/build.gradle.kts @@ -9,8 +9,7 @@ extra["moduleName"] = "software.amazon.smithy.kotlin.codegen.test" tasks["jar"].enabled = false plugins { - val smithyGradlePluginVersion: String by project - id("software.amazon.smithy").version(smithyGradlePluginVersion) + id("software.amazon.smithy") } val smithyVersion: String by project diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecoratorTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecoratorTest.kt index e79617a716..23d73ae317 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecoratorTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecoratorTest.kt @@ -17,6 +17,11 @@ import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.orNull +import software.amazon.smithy.rustsdk.decorators.AwsPresigningDecorator +import software.amazon.smithy.rustsdk.decorators.MoveDocumentMembersToQueryParamsTransform +import software.amazon.smithy.rustsdk.decorators.OverrideHttpMethodTransform +import software.amazon.smithy.rustsdk.decorators.PayloadSigningType +import software.amazon.smithy.rustsdk.decorators.PresignableOperation import software.amazon.smithy.rustsdk.traits.PresignableTrait class AwsPresigningDecoratorTest { diff --git a/aws/sdk/build.gradle.kts b/aws/sdk/build.gradle.kts index e09f62b44a..fe8766babe 100644 --- a/aws/sdk/build.gradle.kts +++ b/aws/sdk/build.gradle.kts @@ -15,8 +15,7 @@ extra["moduleName"] = "software.amazon.smithy.rust.awssdk" tasks["jar"].enabled = false plugins { - val smithyGradlePluginVersion: String by project - id("software.amazon.smithy").version(smithyGradlePluginVersion) + id("software.amazon.smithy") } configure { @@ -397,7 +396,11 @@ tasks["assemble"].apply { project.registerCargoCommandsTasks(outputDir, defaultRustDocFlags) project.registerGenerateCargoConfigTomlTask(outputDir) -tasks["test"].finalizedBy(Cargo.CLIPPY, Cargo.TEST, Cargo.DOCS) +tasks["test"].finalizedBy( + Cargo.CHECK.toString, + Cargo.TEST.toString, + Cargo.DOCS.toString +) tasks.register("deleteSdk") { delete = setOf(outputDir) diff --git a/codegen-client-test/build.gradle.kts b/codegen-client-test/build.gradle.kts index c4c085bfd9..41a8999175 100644 --- a/codegen-client-test/build.gradle.kts +++ b/codegen-client-test/build.gradle.kts @@ -9,8 +9,7 @@ extra["moduleName"] = "software.amazon.smithy.kotlin.codegen.test" tasks["jar"].enabled = false plugins { - val smithyGradlePluginVersion: String by project - id("software.amazon.smithy").version(smithyGradlePluginVersion) + id("software.amazon.smithy") } val smithyVersion: String by project diff --git a/codegen-server-test/build.gradle.kts b/codegen-server-test/build.gradle.kts index 3d01b403ab..3947573900 100644 --- a/codegen-server-test/build.gradle.kts +++ b/codegen-server-test/build.gradle.kts @@ -10,8 +10,7 @@ extra["moduleName"] = "software.amazon.smithy.rust.kotlin.codegen.server.test" tasks["jar"].enabled = false plugins { - val smithyGradlePluginVersion: String by project - id("software.amazon.smithy").version(smithyGradlePluginVersion) + id("software.amazon.smithy") } val smithyVersion: String by project diff --git a/codegen-server-test/python/build.gradle.kts b/codegen-server-test/python/build.gradle.kts index 7a8f1b2f50..fede26a024 100644 --- a/codegen-server-test/python/build.gradle.kts +++ b/codegen-server-test/python/build.gradle.kts @@ -10,8 +10,7 @@ extra["moduleName"] = "software.amazon.smithy.rust.kotlin.codegen.server.python. tasks["jar"].enabled = false plugins { - val smithyGradlePluginVersion: String by project - id("software.amazon.smithy").version(smithyGradlePluginVersion) + id("software.amazon.smithy") } val smithyVersion: String by project diff --git a/settings.gradle.kts b/settings.gradle.kts index 4b5bf3d75e..48190cc2a1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -18,6 +18,13 @@ include(":aws:sdk-adhoc-test") include(":aws:sdk") include(":aws:rust-runtime") +pluginManagement { + val smithyGradlePluginVersion: String by settings + plugins { + id("software.amazon.smithy") version smithyGradlePluginVersion + } +} + buildscript { repositories { mavenLocal() From 9979d7648522145933ef7462c8b37e3df8881ab3 Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Tue, 1 Nov 2022 17:10:43 -0500 Subject: [PATCH 06/19] fix: set default RuntimeConfig cratePrefix to "aws" add: another missing import --- .../client/smithy/generators/EndpointTraitBindingsTest.kt | 1 + .../amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt index 872402c6ef..3d456639d1 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt @@ -20,6 +20,7 @@ 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.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt index 63b377cb3c..38afba52fc 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt @@ -71,7 +71,7 @@ value class CrateVersionMap( * Prefix & crate location for the runtime crates. */ data class RuntimeConfig( - val cratePrefix: String = "aws-smithy", + val cratePrefix: String = "aws", val runtimeCrateLocation: RuntimeCrateLocation = RuntimeCrateLocation.Path("../"), ) { companion object { From 9a50129394eadb4c778a00a1502df7b7470397df Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Tue, 1 Nov 2022 17:20:10 -0500 Subject: [PATCH 07/19] add: another missing import --- .../server/smithy/generators/ServerOperationHandlerGenerator.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt index 5a2f6346fe..fa8c99ad14 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt @@ -10,6 +10,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType From b8678ff17727602eda630a6c911c08125ebef1bd Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Wed, 2 Nov 2022 10:13:49 -0500 Subject: [PATCH 08/19] update: sha256 dep of crate-hasher tool --- tools/crate-hasher/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/crate-hasher/Cargo.toml b/tools/crate-hasher/Cargo.toml index da23737b2a..df6853542e 100644 --- a/tools/crate-hasher/Cargo.toml +++ b/tools/crate-hasher/Cargo.toml @@ -17,7 +17,7 @@ opt-level = 0 anyhow = "1.0" clap = { version = "~3.1.18", features = ["derive"] } ignore = "0.4" -sha256 = "1.0" +sha256 = "1.1" [dev-dependencies] flate2 = "1.0" From 263d9c6f42524b447b968d445491fb7ead642ddc Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Wed, 2 Nov 2022 10:18:47 -0500 Subject: [PATCH 09/19] update: Cargo.lock of crate-hasher tool --- tools/crate-hasher/Cargo.lock | 82 ++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/tools/crate-hasher/Cargo.lock b/tools/crate-hasher/Cargo.lock index 9fed13f46b..16b7a9e03f 100644 --- a/tools/crate-hasher/Cargo.lock +++ b/tools/crate-hasher/Cargo.lock @@ -19,9 +19,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.65" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" [[package]] name = "atty" @@ -152,9 +152,9 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.23" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" +checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" dependencies = [ "quote", "syn", @@ -177,9 +177,9 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94a7bbaa59354bc20dd75b67f23e2797b4490e9d6928203fb105c79e448c86c" +checksum = "4b9663d381d07ae25dc88dbdf27df458faa83a9b25336bcac83d5e452b5fc9d3" dependencies = [ "cfg-if", "libc", @@ -295,9 +295,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.134" +version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "log" @@ -325,9 +325,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "opaque-debug" @@ -337,9 +337,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "os_str_bytes" -version = "6.3.0" +version = "6.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" +checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9" [[package]] name = "output_vt100" @@ -388,9 +388,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.46" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] @@ -500,9 +500,9 @@ dependencies = [ [[package]] name = "sha256" -version = "1.0.3" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e84a7f596c081d359de5e06a83877138bc3c4483591e1af1916e1472e6e146e" +checksum = "e334db67871c14c18fc066ad14af13f9fdf5f9a91c61af432d1e3a39c8c6a141" dependencies = [ "hex", "sha2", @@ -516,9 +516,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.101" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ "proc-macro2", "quote", @@ -557,9 +557,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.1" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" +checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d" [[package]] name = "thread_local" @@ -578,9 +578,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "unicode-ident" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "version_check" @@ -632,46 +632,60 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ + "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_msvc", "windows_x86_64_gnu", + "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + [[package]] name = "windows_aarch64_msvc" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" [[package]] name = "windows_i686_gnu" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" [[package]] name = "windows_i686_msvc" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" [[package]] name = "windows_x86_64_gnu" -version = "0.36.1" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" [[package]] name = "windows_x86_64_msvc" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" [[package]] name = "xattr" From 52a55fd7a912e9359edcd904e6e52478556622cc Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Thu, 3 Nov 2022 12:08:32 -0500 Subject: [PATCH 10/19] update: make doc-only usage of awsConfig import it as a dev dependency add: missing copyright headers fix: endpoints test by differentiating between usages of aws-endpoints --- .../smithy/rustsdk/decorators/AwsFluentClientDecorator.kt | 6 ++++-- .../amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt | 5 +++++ .../amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt | 5 +++++ .../smithy/rustsdk/EndpointConfigCustomizationTest.kt | 6 +++--- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt index 4d8af2f257..fc3e5c93ae 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt @@ -17,11 +17,13 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.client.Fluen import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientSection import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope import software.amazon.smithy.rust.codegen.core.rustlang.Feature 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.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate @@ -38,8 +40,8 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware import software.amazon.smithy.rustsdk.SdkSettings -import software.amazon.smithy.rustsdk.awsConfig import software.amazon.smithy.rustsdk.awsHttp +import software.amazon.smithy.rustsdk.awsRuntimeCrate import software.amazon.smithy.rustsdk.awsTypes private class Types(runtimeConfig: RuntimeConfig) { @@ -259,7 +261,7 @@ private class AwsFluentClientDocs(private val codegenContext: CodegenContext) : /// let client = $crateName::Client::from_conf(config); /// ## } """, - "aws_config" to runtimeConfig.awsConfig(), + "aws_config" to runtimeConfig.awsRuntimeCrate("aws-config").copy(scope = DependencyScope.Dev).asType(), ) } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt index c72d5002f2..dfb3ddbea5 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt @@ -1,3 +1,8 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.model.shapes.OperationShape diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt index 283c25d39e..09b751616a 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt @@ -1,3 +1,8 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + package software.amazon.smithy.rustsdk.decorators import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt index 07935b2116..3234aef663 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt @@ -184,7 +184,7 @@ internal class EndpointConfigCustomizationTest { """ let conf = crate::config::Config::builder().build(); let endpoint = conf.endpoint_resolver - .resolve_endpoint(&#{PlaceholderParams}::new(Some(#{Region}::new("fips-ca-central-1")))) + .resolve_endpoint(&::#{PlaceholderParams}::new(Some(#{Region}::new("fips-ca-central-1")))) .expect("default resolver produces a valid endpoint"); assert_eq!(endpoint.url(), "https://access-analyzer-fips.ca-central-1.amazonaws.com/"); """, @@ -204,12 +204,12 @@ internal class EndpointConfigCustomizationTest { """ let conf = crate::config::Config::builder().build(); let endpoint = conf.endpoint_resolver - .resolve_endpoint(&#{PlaceholderParams}::new(Some(#{Region}::new("us-east-1")))) + .resolve_endpoint(&::#{PlaceholderParams}::new(Some(#{Region}::new("us-east-1")))) .expect("default resolver produces a valid endpoint"); assert_eq!(endpoint.url(), "https://iam.amazonaws.com/"); let endpoint = conf.endpoint_resolver - .resolve_endpoint(&#{PlaceholderParams}::new(Some(#{Region}::new("iam-fips")))) + .resolve_endpoint(&::#{PlaceholderParams}::new(Some(#{Region}::new("iam-fips")))) .expect("default resolver produces a valid endpoint"); assert_eq!(endpoint.url(), "https://iam-fips.amazonaws.com/"); """, From ced89c520d311677f5bef3559caa44fdb5ab5d49 Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Fri, 4 Nov 2022 10:47:51 -0500 Subject: [PATCH 11/19] update: move SleepImplFromSdkConfig into ResiliencyDecorator update: rename servicecustomizations to servicedecorators remove: decorator name field add: CHANGELOG.next.toml entries --- CHANGELOG.next.toml | 95 +++++++++++++++++++ .../decorators/AwsCombinedCodegenDecorator.kt | 16 ++-- .../decorators/AwsEndpointDecorator.kt | 1 - .../decorators/AwsFluentClientDecorator.kt | 2 - .../decorators/AwsPresigningDecorator.kt | 2 - .../rustsdk/decorators/AwsReadmeDecorator.kt | 1 - .../decorators/CrateLicenseDecorator.kt | 1 - .../CredentialsProviderDecorator.kt | 1 - .../HttpRequestChecksumDecorator.kt | 1 - .../HttpResponseChecksumDecorator.kt | 1 - .../decorators/IntegrationTestDecorator.kt | 1 - .../rustsdk/decorators/RegionDecorator.kt | 1 - .../rustsdk/decorators/ResiliencyDecorator.kt | 10 +- .../rustsdk/decorators/SdkConfigDecorator.kt | 1 - .../decorators/ServiceConfigDecorator.kt | 1 - .../decorators/SigV4SigningDecorator.kt | 1 - .../rustsdk/decorators/SleepImplDecorator.kt | 37 -------- .../rustsdk/decorators/UserAgentDecorator.kt | 1 - .../apigateway/ApiGatewayDecorator.kt | 3 +- .../auth/DisabledAuthDecorator.kt | 3 +- .../ec2/BoxPrimitiveShapes.kt | 2 +- .../ec2/Ec2Decorator.kt | 3 +- .../ec2/Ec2MakePrimitivesOptional.kt | 2 +- .../glacier/AccountIdAutofill.kt | 2 +- .../glacier/ApiVersionHeader.kt | 2 +- .../glacier/GlacierDecorator.kt | 3 +- .../glacier/TreeHashHeader.kt | 2 +- .../route53/Route53Decorator.kt | 3 +- .../route53/TrimResourceId.kt | 2 +- .../s3/S3Decorator.kt | 3 +- .../sts/STSDecorator.kt | 5 +- .../EndpointConfigCustomizationTest.kt | 1 - .../ec2/Ec2MakePrimitivesOptionalTest.kt | 2 +- .../customizations/ClientCustomizations.kt | 1 - .../customizations/DocsRsMetadataDecorator.kt | 1 - .../NoOpEventStreamSigningDecorator.kt | 1 - .../customize/RequiredCustomizations.kt | 1 - .../smithy/customize/RustCodegenDecorator.kt | 12 +-- .../client/FluentClientDecorator.kt | 1 - .../generators/EndpointTraitBindingsTest.kt | 1 - .../protocol/ProtocolTestGeneratorTest.kt | 1 - .../client/testutil/AddRustTestsDecorator.kt | 1 - .../PythonServerCodegenDecorator.kt | 3 - .../AdditionalErrorsDecorator.kt | 2 - .../ServerRequiredCustomizations.kt | 1 - 45 files changed, 128 insertions(+), 110 deletions(-) delete mode 100644 aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/apigateway/ApiGatewayDecorator.kt (95%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/auth/DisabledAuthDecorator.kt (94%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/ec2/BoxPrimitiveShapes.kt (97%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/ec2/Ec2Decorator.kt (93%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/ec2/Ec2MakePrimitivesOptional.kt (92%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/glacier/AccountIdAutofill.kt (95%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/glacier/ApiVersionHeader.kt (94%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/glacier/GlacierDecorator.kt (94%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/glacier/TreeHashHeader.kt (97%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/route53/Route53Decorator.kt (97%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/route53/TrimResourceId.kt (88%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/s3/S3Decorator.kt (98%) rename aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/sts/STSDecorator.kt (92%) rename aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/{servicecustomizations => servicedecorators}/ec2/Ec2MakePrimitivesOptionalTest.kt (95%) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index e99a447803..10da90aa27 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -79,3 +79,98 @@ message = "Fix cargo audit issue on criterion." references = ["smithy-rs#1923"] meta = { "breaking" = false, "tada" = false, "bug" = false } author = "ysaito1001" + +[[smithy-rs]] +message = """ +`awsRuntimeDependency` has been renamed to `awsRuntimeCrate` in order to match `smithyRuntimeCrate`. Additionally, +declaration of the runtime crates has been centralized in `software.amazon.smithy.rustsdk.AwsRuntimeDependency` for AWS + types and `software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency` for smithy types. + +The `RuntimeConfig` runtime crate functions now return `RuntimeTypes` instead of `CargoDependencies`. This better +matches their usage in codegen. If you want to access the cargo dependency, use the `awsRuntimeCrate`/`smithyRuntimeCrate` +functions directly. + +before: `rust("#T", CargoDependency.SmithyClient(runtimeConfig).asType())` +after: `rust("#T", runtimeConfig.smithyClient())` +""" +references = ["smithy-rs#1933"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"} +author = "Velfi" + +[[smithy-rs]] +message = """ +Service-specific decorators in SDK codegen have been moved into `software.amazon.smithy.rustsdk.servicedecorators`. +All other decorators have been moved to `software.amazon.smithy.rustsdk.decorators`. +""" +references = ["smithy-rs#1933"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client"} +author = "Velfi" + +[[smithy-rs]] +message = """ +`RustCodegenDecorator`'s name field has been removed. If you need to log the name of a decorator, +use Kotlin's builtin `class` field: + +```kotlin +val someDecorator = SomeDecorator() +print(someDecorator::class) +// prints "class SomeDecorator" +``` +""" +references = ["smithy-rs#1933"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"} +author = "Velfi" + +[[smithy-rs]] +message = """ +The class `AwsCodegenDecorator.kt` has been renamed to `AwsCombinedCodegenDecorator.kt`. A new class, now named +`AwsCodegenDecorator` is an AWS-specific subclass of `RustCodegenDecorator`. `AwsCodegenDecorator` supports the +customization of the `FromSdkConfigForBuilder` section. + +For example, adding this customization to codegen as part of a decorator: + +```kotlin +class SleepImplFromSdkConfig : AwsCustomization() { + override fun section(section: AwsSection): Writable = writable { + when (section) { + is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_sleep_impl(input.sleep_impl());") + } + } +} +``` + +would result in this Rust code being generated: + +```rust +// In aws-sdk-/src/config.rs +impl From<&SdkConfig> for Builder { + fn from(input: &#{SdkConfig}) -> Self { + let mut builder = Builder::default(); + builder.set_sleep_impl(input.sleep_impl()); + builder + } +} +``` +""" +references = ["smithy-rs#1933"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client"} +author = "Velfi" + +[[smithy-rs]] +message = """ +`CombinedCodegenDecorator`'s `orderedDecorators` field is now protected instead of private so that the new `AwsCodegenDecorator` subclass can use it. +""" +references = ["smithy-rs#1933"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"} +author = "Velfi" + +[[smithy-rs]] +message = """ +`runtimeCrate` has been renamed to `smithyRuntimeCrate` and now requires users to pass the "smithy-" prefix as part of the crate name: + +before: `val smithyHttp = runtimeCrate("http").asType()` +after: `val smithyHttp = smithyRuntimeCrate("smithy-http").asType()` +""" +references = ["smithy-rs#1933"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"} +author = "Velfi" diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt index 41f5d429d5..9962245bf0 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt @@ -20,13 +20,13 @@ import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizat import software.amazon.smithy.rustsdk.AwsCustomization import software.amazon.smithy.rustsdk.AwsSection import software.amazon.smithy.rustsdk.awsTypes -import software.amazon.smithy.rustsdk.servicecustomizations.apigateway.ApiGatewayDecorator -import software.amazon.smithy.rustsdk.servicecustomizations.auth.DisabledAuthDecorator -import software.amazon.smithy.rustsdk.servicecustomizations.ec2.Ec2Decorator -import software.amazon.smithy.rustsdk.servicecustomizations.glacier.GlacierDecorator -import software.amazon.smithy.rustsdk.servicecustomizations.route53.Route53Decorator -import software.amazon.smithy.rustsdk.servicecustomizations.s3.S3Decorator -import software.amazon.smithy.rustsdk.servicecustomizations.sts.STSDecorator +import software.amazon.smithy.rustsdk.servicedecorators.apigateway.ApiGatewayDecorator +import software.amazon.smithy.rustsdk.servicedecorators.auth.DisabledAuthDecorator +import software.amazon.smithy.rustsdk.servicedecorators.ec2.Ec2Decorator +import software.amazon.smithy.rustsdk.servicedecorators.glacier.GlacierDecorator +import software.amazon.smithy.rustsdk.servicedecorators.route53.Route53Decorator +import software.amazon.smithy.rustsdk.servicedecorators.s3.S3Decorator +import software.amazon.smithy.rustsdk.servicedecorators.sts.STSDecorator val DECORATORS = listOf( // General AWS Decorators @@ -44,7 +44,6 @@ val DECORATORS = listOf( SdkConfigDecorator(), ServiceConfigDecorator(), SigV4SigningDecorator(), - SleepImplDecorator(), UserAgentDecorator(), // Service specific decorators @@ -71,7 +70,6 @@ interface AwsCodegenDecorator : RustCodegenDecorator(DECORATORS) { - override val name: String = "AwsCombinedCodegen" override val order: Byte = -1 override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt index 87e2874706..a1a3083ac1 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt @@ -43,7 +43,6 @@ import software.amazon.smithy.rustsdk.awsTypes import kotlin.io.path.readText class AwsEndpointDecorator : AwsCodegenDecorator { - override val name: String = "AwsEndpoint" override val order: Byte = 0 private var endpointsCache: ObjectNode? = null diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt index fc3e5c93ae..8e67215245 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt @@ -89,8 +89,6 @@ private class AwsClientGenerics(private val types: Types) : FluentClientGenerics } class AwsFluentClientDecorator : RustCodegenDecorator { - override val name: String = "AwsFluentClient" - // Must run after the AwsPresigningDecorator so that the presignable trait is correctly added to operations override val order: Byte = (AwsPresigningDecorator.ORDER + 1).toByte() diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsPresigningDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsPresigningDecorator.kt index cb7e8ce9d3..a215aad4a5 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsPresigningDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsPresigningDecorator.kt @@ -94,8 +94,6 @@ class AwsPresigningDecorator internal constructor( companion object { const val ORDER: Byte = 0 } - - override val name: String = "AwsPresigning" override val order: Byte = ORDER override fun operationCustomizations( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsReadmeDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsReadmeDecorator.kt index b28017843c..812a0626f6 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsReadmeDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsReadmeDecorator.kt @@ -29,7 +29,6 @@ private const val SPACE_SIGIL = "[[smithy-rs-nbsp]]" * Generates a README.md for each service crate for display on crates.io. */ class AwsReadmeDecorator : RustCodegenDecorator { - override val name: String = "AwsReadme" override val order: Byte = 0 override fun supportsCodegenContext(clazz: Class): Boolean = diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CrateLicenseDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CrateLicenseDecorator.kt index 360de696a1..b6246043be 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CrateLicenseDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CrateLicenseDecorator.kt @@ -13,7 +13,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RustCrate class CrateLicenseDecorator : RustCodegenDecorator { - override val name: String = "CrateLicense" override val order: Byte = 0 override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CredentialsProviderDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CredentialsProviderDecorator.kt index 3755eb80fe..341c625866 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CredentialsProviderDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/CredentialsProviderDecorator.kt @@ -27,7 +27,6 @@ import software.amazon.smithy.rustsdk.awsHttp import software.amazon.smithy.rustsdk.awsTypes class CredentialsProviderDecorator : AwsCodegenDecorator { - override val name: String = "CredentialsProvider" override val order: Byte = 0 override fun configCustomizations( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt index 49d351c863..91d70ac64f 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt @@ -45,7 +45,6 @@ fun RuntimeConfig.awsInlineableBodyWithChecksum() = RuntimeType.forInlineDepende ) class HttpRequestChecksumDecorator : RustCodegenDecorator { - override val name: String = "HttpRequestChecksum" override val order: Byte = 0 override fun operationCustomizations( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpResponseChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpResponseChecksumDecorator.kt index 8beafbcad9..08e473ceb0 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpResponseChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpResponseChecksumDecorator.kt @@ -30,7 +30,6 @@ private fun HttpChecksumTrait.requestValidationModeMember( } class HttpResponseChecksumDecorator : RustCodegenDecorator { - override val name: String = "HttpResponseChecksum" override val order: Byte = 0 override fun operationCustomizations( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt index 104d6cc85a..e504725196 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt @@ -24,7 +24,6 @@ import java.nio.file.Files import java.nio.file.Paths class IntegrationTestDecorator : RustCodegenDecorator { - override val name: String = "IntegrationTest" override val order: Byte = 0 override fun libRsCustomizations( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt index 4ec3e3d5c3..dc90e2322c 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt @@ -72,7 +72,6 @@ fn test_1() { */ class RegionDecorator : AwsCodegenDecorator { - override val name: String = "Region" override val order: Byte = 0 override fun configCustomizations( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt index dfb3ddbea5..76856a7b6e 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt @@ -20,7 +20,6 @@ import software.amazon.smithy.rustsdk.AwsSection import software.amazon.smithy.rustsdk.awsHttp class ResiliencyDecorator : AwsCodegenDecorator { - override val name: String = "Resiliency" override val order: Byte = 0 override fun operationCustomizations( @@ -36,6 +35,7 @@ class ResiliencyDecorator : AwsCodegenDecorator { baseCustomizations: List, ): List { return baseCustomizations + + SleepImplFromSdkConfig() + RetryConfigFromSdkConfig() + TimeoutConfigFromSdkConfig() } @@ -57,6 +57,14 @@ class RetryClassifierFeature(private val runtimeConfig: RuntimeConfig) : Operati } } +class SleepImplFromSdkConfig : AwsCustomization() { + override fun section(section: AwsSection): Writable = writable { + when (section) { + is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_sleep_impl(input.sleep_impl());") + } + } +} + class RetryConfigFromSdkConfig : AwsCustomization() { override fun section(section: AwsSection): Writable = writable { when (section) { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt index 0bf7adc046..374cf43234 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt @@ -26,7 +26,6 @@ import software.amazon.smithy.rustsdk.awsTypes * - `pub fn new(&aws_types::SdkConfig) -> ::Config`: Direct construction without customization */ class SdkConfigDecorator : RustCodegenDecorator { - override val name: String = "SdkConfig" override val order: Byte = 0 override fun configCustomizations( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ServiceConfigDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ServiceConfigDecorator.kt index 2f10cf14cd..30b6397c57 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ServiceConfigDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ServiceConfigDecorator.kt @@ -16,7 +16,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext class ServiceConfigDecorator : RustCodegenDecorator { - override val name: String = "ServiceConfig" override val order: Byte = 0 override fun configCustomizations( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt index 9c5a5018df..5c04d2f174 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt @@ -45,7 +45,6 @@ import software.amazon.smithy.rustsdk.awsTypes * different behavior. */ class SigV4SigningDecorator : RustCodegenDecorator { - override val name: String = "SigV4Signing" override val order: Byte = 0 private fun applies(codegenContext: CodegenContext): Boolean = codegenContext.serviceShape.hasTrait() diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt deleted file mode 100644 index 09b751616a..0000000000 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SleepImplDecorator.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.rustsdk.decorators - -import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -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.writable -import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext -import software.amazon.smithy.rustsdk.AwsCustomization -import software.amazon.smithy.rustsdk.AwsSection - -class SleepImplDecorator : AwsCodegenDecorator { - override val name: String = "SleepImpl" - override val order: Byte = 0 - - override fun awsCustomizations( - codegenContext: ClientCodegenContext, - baseCustomizations: List, - ): List { - return baseCustomizations + SleepImplFromSdkConfig() - } - - override fun supportsCodegenContext(clazz: Class): Boolean = - clazz.isAssignableFrom(ClientCodegenContext::class.java) -} - -class SleepImplFromSdkConfig : AwsCustomization() { - override fun section(section: AwsSection): Writable = writable { - when (section) { - is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_sleep_impl(input.sleep_impl());") - } - } -} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt index c5a9a2ca76..8947c5c406 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt @@ -31,7 +31,6 @@ import software.amazon.smithy.rustsdk.awsTypes * Inserts a UserAgent configuration into the operation */ class UserAgentDecorator : AwsCodegenDecorator { - override val name: String = "UserAgent" override val order: Byte = 10 override fun configCustomizations( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/apigateway/ApiGatewayDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt similarity index 95% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/apigateway/ApiGatewayDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt index 836ea31a60..e23e645053 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/apigateway/ApiGatewayDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.apigateway +package software.amazon.smithy.rustsdk.servicedecorators.apigateway import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId @@ -20,7 +20,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSectio import software.amazon.smithy.rust.codegen.core.util.letIf class ApiGatewayDecorator : RustCodegenDecorator { - override val name: String = "ApiGateway" override val order: Byte = 0 private fun applies(codegenContext: CodegenContext) = diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/auth/DisabledAuthDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/auth/DisabledAuthDecorator.kt similarity index 94% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/auth/DisabledAuthDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/auth/DisabledAuthDecorator.kt index c4ffe34372..77efaa386b 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/auth/DisabledAuthDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/auth/DisabledAuthDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.auth +package software.amazon.smithy.rustsdk.servicedecorators.auth import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape @@ -20,7 +20,6 @@ private fun String.shapeId() = ShapeId.from(this) // / STS (and possibly other services) need to have auth manually set to [] class DisabledAuthDecorator : RustCodegenDecorator { - override val name: String = "DisabledAuth" override val order: Byte = 0 private val optionalAuth = diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/BoxPrimitiveShapes.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/BoxPrimitiveShapes.kt similarity index 97% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/BoxPrimitiveShapes.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/BoxPrimitiveShapes.kt index 01a094842c..5a70c919d6 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/BoxPrimitiveShapes.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/BoxPrimitiveShapes.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.ec2 +package software.amazon.smithy.rustsdk.servicedecorators.ec2 import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.AbstractShapeBuilder diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/Ec2Decorator.kt similarity index 93% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2Decorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/Ec2Decorator.kt index 5a41b8512a..97db496f60 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/Ec2Decorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.ec2 +package software.amazon.smithy.rustsdk.servicedecorators.ec2 import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -17,7 +17,6 @@ import software.amazon.smithy.rust.codegen.core.util.letIf private val Ec2 = ShapeId.from("com.amazonaws.ec2#AmazonEC2") class Ec2Decorator : RustCodegenDecorator { - override val name: String = "Ec2" override val order: Byte = 0 private fun applies(serviceShape: ServiceShape) = serviceShape.id == Ec2 diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptional.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/Ec2MakePrimitivesOptional.kt similarity index 92% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptional.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/Ec2MakePrimitivesOptional.kt index 918b90ab59..cf5ff18f7a 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptional.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/Ec2MakePrimitivesOptional.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.ec2 +package software.amazon.smithy.rustsdk.servicedecorators.ec2 import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.Shape diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/AccountIdAutofill.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/AccountIdAutofill.kt similarity index 95% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/AccountIdAutofill.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/AccountIdAutofill.kt index a4cf622b77..0e43595f56 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/AccountIdAutofill.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/AccountIdAutofill.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.glacier +package software.amazon.smithy.rustsdk.servicedecorators.glacier import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/ApiVersionHeader.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt similarity index 94% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/ApiVersionHeader.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt index b0f14f34df..3606df8bcb 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/ApiVersionHeader.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.glacier +package software.amazon.smithy.rustsdk.servicedecorators.glacier import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.rust diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/GlacierDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/GlacierDecorator.kt similarity index 94% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/GlacierDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/GlacierDecorator.kt index c0f76fed76..f43bb66896 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/GlacierDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/GlacierDecorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.glacier +package software.amazon.smithy.rustsdk.servicedecorators.glacier import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ServiceShape @@ -17,7 +17,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustom val Glacier: ShapeId = ShapeId.from("com.amazonaws.glacier#Glacier") class GlacierDecorator : RustCodegenDecorator { - override val name: String = "Glacier" override val order: Byte = 0 private fun applies(serviceShape: ServiceShape) = serviceShape.id == Glacier diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/TreeHashHeader.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/TreeHashHeader.kt similarity index 97% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/TreeHashHeader.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/TreeHashHeader.kt index 6d936a0f08..ddf37d83b4 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/glacier/TreeHashHeader.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/TreeHashHeader.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.glacier +package software.amazon.smithy.rustsdk.servicedecorators.glacier import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/Route53Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/route53/Route53Decorator.kt similarity index 97% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/Route53Decorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/route53/Route53Decorator.kt index 988df955f5..e0ccb2a405 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/Route53Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/route53/Route53Decorator.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.route53 +package software.amazon.smithy.rustsdk.servicedecorators.route53 import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.MemberShape @@ -31,7 +31,6 @@ import java.util.logging.Logger val Route53: ShapeId = ShapeId.from("com.amazonaws.route53#AWSDnsV20130401") class Route53Decorator : RustCodegenDecorator { - override val name: String = "Route53" override val order: Byte = 0 private val logger: Logger = Logger.getLogger(javaClass.name) private val resourceShapes = setOf(ShapeId.from("com.amazonaws.route53#ResourceId"), ShapeId.from("com.amazonaws.route53#ChangeId")) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/TrimResourceId.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/route53/TrimResourceId.kt similarity index 88% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/TrimResourceId.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/route53/TrimResourceId.kt index 8a398f1668..2431305c70 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/route53/TrimResourceId.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/route53/TrimResourceId.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.route53 +package software.amazon.smithy.rustsdk.servicedecorators.route53 import software.amazon.smithy.model.node.Node import software.amazon.smithy.model.shapes.ShapeId diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/s3/S3Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt similarity index 98% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/s3/S3Decorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt index fd11d1ae2b..b85bf5814b 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/s3/S3Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.s3 +package software.amazon.smithy.rustsdk.servicedecorators.s3 import software.amazon.smithy.aws.traits.protocols.RestXmlTrait import software.amazon.smithy.model.Model @@ -38,7 +38,6 @@ import java.util.logging.Logger val S3: ShapeId = ShapeId.from("com.amazonaws.s3#AmazonS3") class S3Decorator : RustCodegenDecorator { - override val name: String = "S3" override val order: Byte = 0 private val logger: Logger = Logger.getLogger(javaClass.name) private val invalidXmlRootAllowList = setOf( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/sts/STSDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/sts/STSDecorator.kt similarity index 92% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/sts/STSDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/sts/STSDecorator.kt index 01f2332abd..bc0c56f673 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/sts/STSDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/sts/STSDecorator.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.sts +package software.amazon.smithy.rustsdk.servicedecorators.sts import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -20,10 +20,9 @@ import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.letIf import java.util.logging.Logger -val Sts = ShapeId.from("com.amazonaws.sts#AWSSecurityTokenServiceV20110615") +val Sts: ShapeId = ShapeId.from("com.amazonaws.sts#AWSSecurityTokenServiceV20110615") class STSDecorator : RustCodegenDecorator { - override val name: String = "STS" override val order: Byte = 0 private val logger: Logger = Logger.getLogger(javaClass.name) diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt index 3234aef663..2015c9efba 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt @@ -131,7 +131,6 @@ internal class EndpointConfigCustomizationTest { private fun validateEndpointCustomizationForService(service: String, test: ((RustCrate) -> Unit)? = null) { val (context, testDir) = generatePluginContext(model, service = service, runtimeConfig = AwsTestRuntimeConfig) val codegenDecorator = object : RustCodegenDecorator { - override val name: String = "tests and config" override val order: Byte = 0 override fun configCustomizations( codegenContext: ClientCodegenContext, diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptionalTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/Ec2MakePrimitivesOptionalTest.kt similarity index 95% rename from aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptionalTest.kt rename to aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/Ec2MakePrimitivesOptionalTest.kt index f7f50cd91d..0b34371ca7 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/servicecustomizations/ec2/Ec2MakePrimitivesOptionalTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/servicedecorators/ec2/Ec2MakePrimitivesOptionalTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rustsdk.servicecustomizations.ec2 +package software.amazon.smithy.rustsdk.servicedecorators.ec2 import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientCustomizations.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientCustomizations.kt index 6ff57e85ab..18051f0ec6 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientCustomizations.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientCustomizations.kt @@ -15,7 +15,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomiza * Customizations that apply only to generated clients. */ class ClientCustomizations : RustCodegenDecorator { - override val name: String = "ClientCustomizations" override val order: Byte = 0 override fun libRsCustomizations( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/DocsRsMetadataDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/DocsRsMetadataDecorator.kt index 7809ccffbd..a8513046cf 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/DocsRsMetadataDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/DocsRsMetadataDecorator.kt @@ -52,7 +52,6 @@ fun DocsRsMetadataSettings.asMap(): Map { */ class DocsRsMetadataDecorator(private val docsRsMetadataSettings: DocsRsMetadataSettings) : RustCodegenDecorator { - override val name: String = "docsrs-metadata" override val order: Byte = 0 override fun crateManifestCustomizations(codegenContext: ClientCodegenContext): ManifestCustomizations { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt index 8c63b06d72..eb79c73c5a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt @@ -20,7 +20,6 @@ import software.amazon.smithy.rust.codegen.core.util.hasEventStreamOperations * - adds a `new_event_stream_signer()` method to `config` to create an Event Stream NoOp signer */ open class NoOpEventStreamSigningDecorator : RustCodegenDecorator { - override val name: String = "NoOpEventStreamSigning" override val order: Byte = Byte.MIN_VALUE private fun applies(codegenContext: CodegenContext, baseCustomizations: List): Boolean = diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt index 3ae662bfcd..b494f7ae8f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt @@ -30,7 +30,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomiza * This exists as a convenient place to gather these modifications, these are not true customizations. */ class RequiredCustomizations : RustCodegenDecorator { - override val name: String = "Required" override val order: Byte = -1 override fun operationCustomizations( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt index 38afef53ad..34a680a23a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt @@ -29,11 +29,6 @@ import java.util.logging.Logger * attributes to the generated classes. */ interface RustCodegenDecorator { - /** - * The name of this [RustCodegenDecorator], used for logging and debug information - */ - val name: String - /** * Enable a deterministic ordering to be applied, with the lowest numbered integrations being applied first */ @@ -58,7 +53,7 @@ interface RustCodegenDecorator { /** * Returns a map of Cargo.toml properties to change. For example, if a `homepage` needs to be - * added to the Cargo.toml `[package]` section, a `mapOf("package" to mapOf("homepage", "https://example.com"))` + * added to the Cargo.toml ```[package]``` section, a `mapOf("package" to mapOf("homepage", "https://example.com"))` * could be returned. Properties here overwrite the default properties. */ fun crateManifestCustomizations(codegenContext: C): ManifestCustomizations = emptyMap() @@ -80,10 +75,7 @@ interface RustCodegenDecorator { open class CombinedCodegenDecorator(decorators: List>) : RustCodegenDecorator { protected val orderedDecorators = decorators.sortedBy { it.order } - override val name: String - get() = "MetaDecorator" - override val order: Byte - get() = 0 + override val order: Byte = 0 fun withDecorator(decorator: RustCodegenDecorator) = CombinedCodegenDecorator(orderedDecorators + decorator) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt index db56f6f0f5..4ba7cf1890 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt @@ -26,7 +26,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomiza import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection class FluentClientDecorator : RustCodegenDecorator { - override val name: String = "FluentClient" override val order: Byte = 0 private fun applies(codegenContext: ClientCodegenContext): Boolean = diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt index 3d456639d1..45a475185c 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt @@ -149,7 +149,6 @@ internal class EndpointTraitBindingsTest { val (ctx, testDir) = generatePluginContext(model) val moduleName = ctx.settings.expectStringMember("module").value.replace('-', '_') val codegenDecorator = object : RustCodegenDecorator { - override val name: String = "add tests" override val order: Byte = 0 override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt index 57bd1ae277..cf520bb7fe 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt @@ -223,7 +223,6 @@ class ProtocolTestGeneratorTest { ): Path { val (pluginContext, testDir) = generatePluginContext(model) val codegenDecorator = object : RustCodegenDecorator { - override val name: String = "mock" override val order: Byte = 0 override fun protocols( serviceId: ShapeId, diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt index 7a7a45a735..7c2b204f55 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt @@ -13,7 +13,6 @@ open class AddRustTestsDecorator( private val testsFileName: String, private val testWritable: Writable, ) : RustCodegenDecorator { - override val name: String = "add tests" override val order: Byte = 0 override fun extras(codegenContext: C, rustCrate: RustCrate) { diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt index db4f71b301..faa65296d8 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt @@ -32,7 +32,6 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.Ser * crate-type = ["cdylib"] */ class CdylibManifestDecorator : RustCodegenDecorator { - override val name: String = "CdylibDecorator" override val order: Byte = 0 override fun crateManifestCustomizations( @@ -72,7 +71,6 @@ class PubUsePythonTypes(private val codegenContext: ServerCodegenContext) : LibR * Render the Python shared library module export. */ class PythonExportModuleDecorator : RustCodegenDecorator { - override val name: String = "PythonExportModuleDecorator" override val order: Byte = 0 override fun extras(codegenContext: ServerCodegenContext, rustCrate: RustCrate) { @@ -89,7 +87,6 @@ class PythonExportModuleDecorator : RustCodegenDecorator { - override val name: String = "PubUsePythonTypesDecorator" override val order: Byte = 0 override fun libRsCustomizations( diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt index 3f5e5cdab0..6ebfc85f73 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt @@ -34,7 +34,6 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.Ser * ``` */ class AddInternalServerErrorToInfallibleOperationsDecorator : RustCodegenDecorator { - override val name: String = "AddInternalServerErrorToInfallibleOperations" override val order: Byte = 0 override fun transformModel(service: ServiceShape, model: Model): Model = @@ -63,7 +62,6 @@ class AddInternalServerErrorToInfallibleOperationsDecorator : RustCodegenDecorat * ``` */ class AddInternalServerErrorToAllOperationsDecorator : RustCodegenDecorator { - override val name: String = "AddInternalServerErrorToAllOperations" override val order: Byte = 0 override fun transformModel(service: ServiceShape, model: Model): Model = diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt index a8063cf898..50ac1563c7 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt @@ -24,7 +24,6 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.Ser * See [RequiredCustomizations] from the `rust-codegen` subproject for the client version of this decorator. */ class ServerRequiredCustomizations : RustCodegenDecorator { - override val name: String = "ServerRequired" override val order: Byte = -1 override fun libRsCustomizations( From 74009220e328a53ce8993ddadabef292e5313b25 Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Fri, 4 Nov 2022 13:54:49 -0500 Subject: [PATCH 12/19] remove: CHANGELOG.next.toml entries only relevant to smithy contribs Info for smithy contribs: - `awsRuntimeDependency` has been renamed to `awsRuntimeCrate` in order to match `smithyRuntimeCrate`. Additionally, declaration of the runtime crates has been centralized in `software.amazon.smithy.rustsdk.AwsRuntimeDependency` for AWS types and `software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency` for smithy types. - The `RuntimeConfig` runtime crate functions now return `RuntimeTypes` instead of `CargoDependencies`. This better matches their usage in codegen. If you want to access the cargo dependency, use the `awsRuntimeCrate`/`smithyRuntimeCrate` functions directly. before: `rust("#T", CargoDependency.SmithyClient(runtimeConfig).asType())` after: `rust("#T", runtimeConfig.smithyClient())` - Service-specific decorators in SDK codegen have been moved into `software.amazon.smithy.rustsdk.servicedecorators`. All other decorators have been moved to `software.amazon.smithy.rustsdk.decorators`. -`RustCodegenDecorator`'s name field has been removed. If you need to log the name of a decorator, use Kotlin's builtin `class` field: ```kotlin val someDecorator = SomeDecorator() print(someDecorator::class) // prints "class SomeDecorator" ``` - The class `AwsCodegenDecorator.kt` has been renamed to `AwsCombinedCodegenDecorator.kt`. A new class, now named `AwsCodegenDecorator` is an AWS-specific subclass of `RustCodegenDecorator`. `AwsCodegenDecorator` supports the customization of the `FromSdkConfigForBuilder` section. For example, adding this customization to codegen as part of a decorator: ```kotlin class SleepImplFromSdkConfig : AwsCustomization() { override fun section(section: AwsSection): Writable = writable { when (section) { is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_sleep_impl(input.sleep_impl());") } } } ``` would result in this Rust code being generated: ```rust // In aws-sdk-/src/config.rs impl From<&SdkConfig> for Builder { fn from(input: &#{SdkConfig}) -> Self { let mut builder = Builder::default(); builder.set_sleep_impl(input.sleep_impl()); builder } } ``` - `CombinedCodegenDecorator`'s `orderedDecorators` field is now protected instead of private so that the new `AwsCodegenDecorator` subclass can use it. - `runtimeCrate` has been renamed to `smithyRuntimeCrate` and now requires users to pass the "smithy-" prefix as part of the crate name: before: `val smithyHttp = runtimeCrate("http").asType()` after: `val smithyHttp = smithyRuntimeCrate("smithy-http").asType()` --- CHANGELOG.next.toml | 96 --------------------------------------------- 1 file changed, 96 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index fe96576f75..0252fee249 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -80,101 +80,6 @@ references = ["smithy-rs#1923"] meta = { "breaking" = false, "tada" = false, "bug" = false } author = "ysaito1001" -[[smithy-rs]] -message = """ -`awsRuntimeDependency` has been renamed to `awsRuntimeCrate` in order to match `smithyRuntimeCrate`. Additionally, -declaration of the runtime crates has been centralized in `software.amazon.smithy.rustsdk.AwsRuntimeDependency` for AWS - types and `software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency` for smithy types. - -The `RuntimeConfig` runtime crate functions now return `RuntimeTypes` instead of `CargoDependencies`. This better -matches their usage in codegen. If you want to access the cargo dependency, use the `awsRuntimeCrate`/`smithyRuntimeCrate` -functions directly. - -before: `rust("#T", CargoDependency.SmithyClient(runtimeConfig).asType())` -after: `rust("#T", runtimeConfig.smithyClient())` -""" -references = ["smithy-rs#1933"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"} -author = "Velfi" - -[[smithy-rs]] -message = """ -Service-specific decorators in SDK codegen have been moved into `software.amazon.smithy.rustsdk.servicedecorators`. -All other decorators have been moved to `software.amazon.smithy.rustsdk.decorators`. -""" -references = ["smithy-rs#1933"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client"} -author = "Velfi" - -[[smithy-rs]] -message = """ -`RustCodegenDecorator`'s name field has been removed. If you need to log the name of a decorator, -use Kotlin's builtin `class` field: - -```kotlin -val someDecorator = SomeDecorator() -print(someDecorator::class) -// prints "class SomeDecorator" -``` -""" -references = ["smithy-rs#1933"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"} -author = "Velfi" - -[[smithy-rs]] -message = """ -The class `AwsCodegenDecorator.kt` has been renamed to `AwsCombinedCodegenDecorator.kt`. A new class, now named -`AwsCodegenDecorator` is an AWS-specific subclass of `RustCodegenDecorator`. `AwsCodegenDecorator` supports the -customization of the `FromSdkConfigForBuilder` section. - -For example, adding this customization to codegen as part of a decorator: - -```kotlin -class SleepImplFromSdkConfig : AwsCustomization() { - override fun section(section: AwsSection): Writable = writable { - when (section) { - is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_sleep_impl(input.sleep_impl());") - } - } -} -``` - -would result in this Rust code being generated: - -```rust -// In aws-sdk-/src/config.rs -impl From<&SdkConfig> for Builder { - fn from(input: &#{SdkConfig}) -> Self { - let mut builder = Builder::default(); - builder.set_sleep_impl(input.sleep_impl()); - builder - } -} -``` -""" -references = ["smithy-rs#1933"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client"} -author = "Velfi" - -[[smithy-rs]] -message = """ -`CombinedCodegenDecorator`'s `orderedDecorators` field is now protected instead of private so that the new `AwsCodegenDecorator` subclass can use it. -""" -references = ["smithy-rs#1933"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"} -author = "Velfi" - -[[smithy-rs]] -message = """ -`runtimeCrate` has been renamed to `smithyRuntimeCrate` and now requires users to pass the "smithy-" prefix as part of the crate name: - -before: `val smithyHttp = runtimeCrate("http").asType()` -after: `val smithyHttp = smithyRuntimeCrate("smithy-http").asType()` -""" -references = ["smithy-rs#1933"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"} -author = "Velfi" - [[aws-sdk-rust]] message = "Ability to add an inline policy or a list of policy ARNs to the `AssumeRoleProvider` builder." references = ["aws-sdk-rust#641", "smithy-rs#1892"] @@ -186,4 +91,3 @@ message = "Removed re-export of `aws_smithy_client::retry::Config` from the `mid references = ["smithy-rs#1935"] meta = { "breaking" = true, "tada" = false, "bug" = false } author = "jdisanti" - From 84acfd2e26d65b23001cb27b6be705aa9365348a Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Tue, 8 Nov 2022 15:05:13 -0600 Subject: [PATCH 13/19] undo: decorator ordering change remove: need to specify `CargoDependency` refactor: get runtime types from `RuntimeType` instead of `RuntimeConfig` --- .../smithy/rustsdk/AwsRuntimeDependency.kt | 25 +- .../decorators/AwsCombinedCodegenDecorator.kt | 20 +- .../decorators/AwsEndpointDecorator.kt | 22 +- .../decorators/AwsFluentClientDecorator.kt | 34 +-- .../decorators/AwsPresigningDecorator.kt | 14 +- .../CredentialsProviderDecorator.kt | 8 +- .../HttpRequestChecksumDecorator.kt | 4 +- .../decorators/IntegrationTestDecorator.kt | 42 ++-- .../rustsdk/decorators/RegionDecorator.kt | 4 +- .../rustsdk/decorators/ResiliencyDecorator.kt | 2 +- .../rustsdk/decorators/SdkConfigDecorator.kt | 4 +- .../decorators/SigV4SigningDecorator.kt | 12 +- .../rustsdk/decorators/UserAgentDecorator.kt | 10 +- .../apigateway/ApiGatewayDecorator.kt | 19 +- .../glacier/ApiVersionHeader.kt | 19 +- .../servicedecorators/s3/S3Decorator.kt | 15 +- .../EndpointConfigCustomizationTest.kt | 7 +- .../smithy/EventStreamSymbolProvider.kt | 8 +- .../smithy/StreamingTraitSymbolProvider.kt | 2 +- .../HttpChecksumRequiredGenerator.kt | 11 +- .../HttpVersionListCustomization.kt | 4 +- .../ResiliencyConfigCustomization.kt | 18 +- .../SmithyTypesPubUseGenerator.kt | 8 +- .../NoOpEventStreamSigningDecorator.kt | 8 +- .../EndpointTraitBindingGenerator.kt | 5 +- .../smithy/generators/PaginatorGenerator.kt | 16 +- .../client/CustomizableOperationGenerator.kt | 26 +- .../client/FluentClientDecorator.kt | 6 +- .../client/FluentClientGenerator.kt | 28 +-- .../config/EventStreamSigningConfig.kt | 16 +- .../protocol/ProtocolTestGenerator.kt | 64 ++--- .../protocols/HttpBoundProtocolGenerator.kt | 7 +- .../HttpVersionListGeneratorTest.kt | 28 +-- .../generators/EndpointTraitBindingsTest.kt | 4 +- .../protocol/ProtocolTestGeneratorTest.kt | 9 +- .../codegen/core/rustlang/CargoDependency.kt | 34 +-- .../rust/codegen/core/rustlang/Writable.kt | 2 +- .../rust/codegen/core/smithy/RuntimeType.kt | 155 ++++-------- .../rust/codegen/core/smithy/SymbolVisitor.kt | 6 +- .../core/smithy/generators/Instantiator.kt | 16 +- .../smithy/generators/StructureGenerator.kt | 2 +- .../generators/TypeConversionGenerator.kt | 4 +- .../error/CombinedErrorGenerator.kt | 4 +- .../generators/http/HttpBindingGenerator.kt | 235 ++++++++++-------- .../http/RequestBindingGenerator.kt | 47 ++-- .../protocol/MakeOperationGenerator.kt | 18 +- .../codegen/core/smithy/protocols/AwsJson.kt | 19 +- .../codegen/core/smithy/protocols/AwsQuery.kt | 15 +- .../codegen/core/smithy/protocols/Ec2Query.kt | 15 +- .../HttpBoundProtocolPayloadGenerator.kt | 10 +- .../codegen/core/smithy/protocols/RestJson.kt | 15 +- .../codegen/core/smithy/protocols/RestXml.kt | 15 +- .../parse/EventStreamUnmarshallerGenerator.kt | 24 +- .../protocols/parse/JsonParserGenerator.kt | 6 +- .../parse/XmlBindingTraitParserGenerator.kt | 24 +- .../EventStreamErrorMarshallerGenerator.kt | 14 +- .../EventStreamMarshallerGenerator.kt | 12 +- .../serialize/JsonSerializerGenerator.kt | 20 +- .../serialize/QuerySerializerGenerator.kt | 18 +- .../XmlBindingTraitSerializerGenerator.kt | 18 +- .../codegen/core/rustlang/RustWriterTest.kt | 6 +- .../http/RequestBindingGeneratorTest.kt | 7 +- .../smithy/PythonServerCargoDependency.kt | 4 +- .../python/smithy/PythonServerRuntimeType.kt | 10 +- .../generators/PythonApplicationGenerator.kt | 6 +- .../generators/PythonServerModuleGenerator.kt | 2 +- .../PythonServerOperationHandlerGenerator.kt | 2 +- .../ServerHttpSensitivityGenerator.kt | 6 +- .../ServerOperationHandlerGenerator.kt | 11 +- .../ServerOperationRegistryGenerator.kt | 2 +- .../generators/ServerServiceGeneratorV2.kt | 13 +- .../protocol/ServerProtocolTestGenerator.kt | 31 ++- .../ServerHttpBoundProtocolGenerator.kt | 31 ++- 73 files changed, 697 insertions(+), 711 deletions(-) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt index dc1bfc8869..9f36c5375e 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt @@ -7,6 +7,10 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Tower +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.smithyClient +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.smithyHttp +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.smithyHttpTower 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.smithy.RuntimeConfig @@ -51,10 +55,10 @@ object AwsRuntimeType { fun RuntimeConfig.defaultMiddleware() = RuntimeType.forInlineDependency( InlineAwsDependency.forRustFile( "middleware", visibility = Visibility.PUBLIC, - CargoDependency.smithyHttp(this), - CargoDependency.smithyHttpTower(this), - CargoDependency.smithyClient(this), - CargoDependency.Tower, + smithyHttp(this), + smithyHttpTower(this), + smithyClient(this), + Tower, awsRuntimeCrate("aws-http"), awsRuntimeCrate("aws-endpoint"), ), @@ -64,10 +68,9 @@ object AwsRuntimeType { fun RuntimeConfig.awsRuntimeCrate(name: String, features: Set = setOf()): CargoDependency = CargoDependency(name, awsRoot().crateLocation(null), features = features) -fun RuntimeConfig.awsConfig() = awsRuntimeCrate("aws-config").asType() -fun RuntimeConfig.awsEndpoint() = awsRuntimeCrate("aws-endpoint").asType() -fun RuntimeConfig.awsHttp() = awsRuntimeCrate("aws-http").asType() -fun RuntimeConfig.awsSigAuth() = awsRuntimeCrate("aws-sig-auth").asType() -fun RuntimeConfig.awsSigAuthEventStream() = awsRuntimeCrate("aws-sig-auth", setOf("sign-eventstream")).asType() -fun RuntimeConfig.awsSigv4() = awsRuntimeCrate("aws-sigv4").asType() -fun RuntimeConfig.awsTypes() = awsRuntimeCrate("aws-types").asType() +fun awsEndpoint(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-endpoint").asType() +fun awsHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-http").asType() +fun awsSigAuth(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sig-auth").asType() +fun awsSigAuthEventStream(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sig-auth", setOf("sign-eventstream")).asType() +fun awsSigv4(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sigv4").asType() +fun awsTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-types").asType() diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt index 9962245bf0..2022543ddc 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt @@ -30,21 +30,21 @@ import software.amazon.smithy.rustsdk.servicedecorators.sts.STSDecorator val DECORATORS = listOf( // General AWS Decorators - AwsEndpointDecorator(), - AwsFluentClientDecorator(), - AwsPresigningDecorator(), - AwsReadmeDecorator(), - CrateLicenseDecorator(), CredentialsProviderDecorator(), + RegionDecorator(), + AwsEndpointDecorator(), + UserAgentDecorator(), + SigV4SigningDecorator(), HttpRequestChecksumDecorator(), HttpResponseChecksumDecorator(), - IntegrationTestDecorator(), - RegionDecorator(), ResiliencyDecorator(), + IntegrationTestDecorator(), + AwsFluentClientDecorator(), + CrateLicenseDecorator(), SdkConfigDecorator(), ServiceConfigDecorator(), - SigV4SigningDecorator(), - UserAgentDecorator(), + AwsPresigningDecorator(), + AwsReadmeDecorator(), // Service specific decorators ApiGatewayDecorator(), @@ -88,7 +88,7 @@ fun generateImplFromRefSdkConfigForConfigBuilder( rustCrate: RustCrate, customizations: List, ) { - val codegenContext = arrayOf("SdkConfig" to runtimeConfig.awsTypes().member("sdk_config::SdkConfig")) + val codegenContext = arrayOf("SdkConfig" to awsTypes(runtimeConfig).member("sdk_config::SdkConfig")) rustCrate.withModule(RustModule.Config) { rustBlockTemplate("impl From<&#{SdkConfig}> for Builder", *codegenContext) { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt index a1a3083ac1..af56185065 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt @@ -20,13 +20,13 @@ 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.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization @@ -106,11 +106,11 @@ class EndpointConfigCustomization( private val runtimeConfig = codegenContext.runtimeConfig private val moduleUseName = codegenContext.moduleUseName() private val codegenScope = arrayOf( - "SmithyResolver" to runtimeConfig.smithyHttp().member("endpoint::ResolveEndpoint"), - "PlaceholderParams" to runtimeConfig.awsEndpoint().member("Params"), - "ResolveAwsEndpoint" to runtimeConfig.awsEndpoint().member("ResolveAwsEndpoint"), - "EndpointShim" to runtimeConfig.awsEndpoint().member("EndpointShim"), - "Region" to runtimeConfig.awsTypes().member("region::Region"), + "SmithyResolver" to smithyHttp(runtimeConfig).member("endpoint::ResolveEndpoint"), + "PlaceholderParams" to awsEndpoint(runtimeConfig).member("Params"), + "ResolveAwsEndpoint" to awsEndpoint(runtimeConfig).member("ResolveAwsEndpoint"), + "EndpointShim" to awsEndpoint(runtimeConfig).member("EndpointShim"), + "Region" to awsTypes(runtimeConfig).member("region::Region"), ) override fun section(section: ServiceConfig): Writable = writable { @@ -191,8 +191,8 @@ class EndpointConfigCustomization( class EndpointResolverFeature(runtimeConfig: RuntimeConfig) : OperationCustomization() { private val codegenScope = arrayOf( - "PlaceholderParams" to runtimeConfig.awsEndpoint().member("Params"), - "EndpointResult" to runtimeConfig.smithyHttp().member("endpoint::Result"), + "PlaceholderParams" to awsEndpoint(runtimeConfig).member("Params"), + "EndpointResult" to smithyHttp(runtimeConfig).member("endpoint::Result"), "BuildError" to runtimeConfig.operationBuildError(), ) @@ -223,7 +223,7 @@ class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat is LibRsSection.Body -> writable { rust( "pub use #T;", - runtimeConfig.smithyHttp().member("endpoint::Endpoint"), + smithyHttp(runtimeConfig).member("endpoint::Endpoint"), ) } @@ -235,8 +235,8 @@ class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat class EndpointResolverGenerator(codegenContext: CodegenContext, private val endpointData: ObjectNode) { private val runtimeConfig = codegenContext.runtimeConfig private val endpointPrefix = codegenContext.serviceShape.expectTrait().endpointPrefix - private val awsEndpoint = runtimeConfig.awsEndpoint() - private val awsTypes = runtimeConfig.awsTypes() + private val awsEndpoint = awsEndpoint(runtimeConfig) + private val awsTypes = awsTypes(runtimeConfig) private val codegenScope = arrayOf( "Partition" to awsEndpoint.member("Partition"), diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt index 8e67215245..4fc8f04488 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt @@ -27,13 +27,13 @@ import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyClient -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyClient +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection @@ -45,17 +45,17 @@ import software.amazon.smithy.rustsdk.awsRuntimeCrate import software.amazon.smithy.rustsdk.awsTypes private class Types(runtimeConfig: RuntimeConfig) { - val clientBuilder = runtimeConfig.smithyClient().member("Builder") - val connectorError = runtimeConfig.smithyHttp().member("result::ConnectorError") - val connectorSettings = runtimeConfig.smithyClient().member("http_connector::ConnectorSettings") + val clientBuilder = smithyClient(runtimeConfig).member("Builder") + val connectorError = smithyHttp(runtimeConfig).member("result::ConnectorError") + val connectorSettings = smithyClient(runtimeConfig).member("http_connector::ConnectorSettings") val defaultMiddleware = runtimeConfig.defaultMiddleware() - val dynConnector = runtimeConfig.smithyClient().member("erase::DynConnector") - val dynMiddleware = runtimeConfig.smithyClient().member("erase::DynMiddleware") - val retryConfig = runtimeConfig.smithyTypes().member("retry::RetryConfig") - val sdkConfig = runtimeConfig.awsTypes().member("SdkConfig") - val smithyClientRetry = runtimeConfig.smithyClient().member("retry") - val smithyConnector = runtimeConfig.smithyClient().member("bounds::SmithyConnector") - val timeoutConfig = runtimeConfig.smithyTypes().member("timeout::TimeoutConfig") + val dynConnector = smithyClient(runtimeConfig).member("erase::DynConnector") + val dynMiddleware = smithyClient(runtimeConfig).member("erase::DynMiddleware") + val retryConfig = smithyTypes(runtimeConfig).member("retry::RetryConfig") + val sdkConfig = awsTypes(runtimeConfig).member("SdkConfig") + val smithyClientRetry = smithyClient(runtimeConfig).member("retry") + val smithyConnector = smithyClient(runtimeConfig).member("bounds::SmithyConnector") + val timeoutConfig = smithyTypes(runtimeConfig).member("timeout::TimeoutConfig") } private class AwsClientGenerics(private val types: Types) : FluentClientGenerics { @@ -103,7 +103,7 @@ class AwsFluentClientDecorator : RustCodegenDecorator writable { rust( "pub use #T;", - runtimeConfig.awsTypes().member("Credentials"), + awsTypes(runtimeConfig).member("Credentials"), ) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt index 91d70ac64f..fcc4f5ed6b 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt @@ -15,10 +15,10 @@ 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 -import software.amazon.smithy.rust.codegen.core.rustlang.smithyChecksums import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyChecksums import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError @@ -106,7 +106,7 @@ private fun HttpChecksumTrait.checksumAlgorithmToStr( }; """, "BuildError" to runtimeConfig.operationBuildError(), - "ChecksumAlgorithm" to runtimeConfig.smithyChecksums().member("ChecksumAlgorithm"), + "ChecksumAlgorithm" to smithyChecksums(runtimeConfig).member("ChecksumAlgorithm"), ) // If a request checksum is not required and there's no way to set one, do nothing diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt index e504725196..9a70a0438e 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt @@ -9,9 +9,19 @@ import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.AsyncStd +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.AsyncStream import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.BytesUtils +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Criterion +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.FuturesCore +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.FuturesUtil +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Hound +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.SerdeJson +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Smol import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.TempFile -import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Tokio +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Tracing +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.TracingSubscriber import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.writable @@ -72,7 +82,7 @@ class IntegrationTestDependencies( addDependency(SerdeJson) addDependency(Tokio) addDependency(FuturesUtil) - addDependency(Tracing) + addDependency(Tracing.copy(scope = DependencyScope.Dev)) addDependency(TracingSubscriber) } if (hasBenches) { @@ -106,25 +116,19 @@ class S3TestDependencies( ) : LibRsCustomization() { override fun section(section: LibRsSection): Writable = writable { + val smithyClient = CargoDependency.smithyClient(runtimeConfig) + .copy(features = setOf("test-util"), scope = DependencyScope.Dev) + val smithyAsync = CargoDependency.smithyAsync(runtimeConfig).copy(scope = DependencyScope.Dev) + val smithyHttp = CargoDependency.smithyHttp(runtimeConfig).copy(scope = DependencyScope.Dev) + val smithyTypes = CargoDependency.smithyTypes(runtimeConfig).copy(scope = DependencyScope.Dev) + addDependency(AsyncStd) - addDependency(BytesUtils) + addDependency(BytesUtils.copy(scope = DependencyScope.Dev)) addDependency(Smol) addDependency(TempFile) - runtimeConfig.smithyRuntimeCrate("smithy-async", scope = DependencyScope.Dev) - runtimeConfig.smithyRuntimeCrate("smithy-client", scope = DependencyScope.Dev) - runtimeConfig.smithyRuntimeCrate("smithy-http", scope = DependencyScope.Dev) - runtimeConfig.smithyRuntimeCrate("smithy-types", scope = DependencyScope.Dev) + addDependency(smithyAsync) + addDependency(smithyClient) + addDependency(smithyHttp) + addDependency(smithyTypes) } } - -private val AsyncStd = CargoDependency("async-std", CratesIo("1.12.0"), scope = DependencyScope.Dev) -private val AsyncStream = CargoDependency("async-stream", CratesIo("0.3.0"), DependencyScope.Dev) -private val Criterion = CargoDependency("criterion", CratesIo("0.4.0"), scope = DependencyScope.Dev) -private val FuturesCore = CargoDependency("futures-core", CratesIo("0.3.0"), DependencyScope.Dev) -private val FuturesUtil = CargoDependency("futures-util", CratesIo("0.3.0"), scope = DependencyScope.Dev) -private val Hound = CargoDependency("hound", CratesIo("3.4.0"), DependencyScope.Dev) -private val SerdeJson = CargoDependency("serde_json", CratesIo("1.0.0"), features = emptySet(), scope = DependencyScope.Dev) -private val Smol = CargoDependency("smol", CratesIo("1.2.0"), scope = DependencyScope.Dev) -private val Tokio = CargoDependency("tokio", CratesIo("1.8.4"), features = setOf("macros", "test-util"), scope = DependencyScope.Dev) -private val Tracing = CargoDependency("tracing", CratesIo("0.1.0"), scope = DependencyScope.Dev) -private val TracingSubscriber = CargoDependency("tracing-subscriber", CratesIo("0.3.15"), scope = DependencyScope.Dev, features = setOf("env-filter")) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt index dc90e2322c..3eb0d97761 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt @@ -110,7 +110,7 @@ class RegionDecorator : AwsCodegenDecorator { class RegionProviderConfig(codegenContext: CodegenContext) : ConfigCustomization() { private val runtimeConfig = codegenContext.runtimeConfig private val moduleUseName = codegenContext.moduleUseName() - private val codegenScope = arrayOf("Region" to runtimeConfig.awsTypes().member("region::Region")) + private val codegenScope = arrayOf("Region" to awsTypes(runtimeConfig).member("region::Region")) override fun section(section: ServiceConfig) = writable { when (section) { is ServiceConfig.ConfigStruct -> rustTemplate("pub(crate) region: Option<#{Region}>,", *codegenScope) @@ -179,7 +179,7 @@ class PubUseRegion(private val runtimeConfig: RuntimeConfig) : LibRsCustomizatio is LibRsSection.Body -> writable { rust( "pub use #T;", - runtimeConfig.awsTypes().member("region::Region"), + awsTypes(runtimeConfig).member("region::Region"), ) } else -> emptySection diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt index 76856a7b6e..f25286d8b6 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt @@ -45,7 +45,7 @@ class ResiliencyDecorator : AwsCodegenDecorator { } class RetryClassifierFeature(private val runtimeConfig: RuntimeConfig) : OperationCustomization() { - override fun retryType(): RuntimeType = runtimeConfig.awsHttp().member("retry::AwsResponseRetryClassifier") + override fun retryType(): RuntimeType = awsHttp(runtimeConfig).member("retry::AwsResponseRetryClassifier") override fun section(section: OperationSection) = when (section) { is OperationSection.FinalizeOperation -> writable { rust( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt index 374cf43234..748fbca715 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt @@ -45,7 +45,7 @@ class SdkConfigDecorator : RustCodegenDecorator emptySection diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt index 5c04d2f174..ff8fe9626f 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt @@ -87,7 +87,7 @@ class SigV4SigningConfig( private val sigV4Trait: SigV4Trait, ) : EventStreamSigningConfig(runtimeConfig) { private val codegenScope = arrayOf( - "SigV4Signer" to runtimeConfig.awsSigAuthEventStream().member("event_stream::SigV4Signer"), + "SigV4Signer" to awsSigAuthEventStream(runtimeConfig).member("event_stream::SigV4Signer"), ) override fun configImplSection(): Writable { @@ -142,11 +142,11 @@ class SigV4SigningFeature( private val service: ServiceShape, ) : OperationCustomization() { private val codegenScope = arrayOf( - "OperationSigningConfig" to runtimeConfig.awsSigAuth().member("signer::OperationSigningConfig"), - "SignableBody" to runtimeConfig.awsSigAuth().member("signer::SignableBody"), - "SigningRegion" to runtimeConfig.awsTypes().member("region::SigningRegion"), - "SigningRequirements" to runtimeConfig.awsSigAuth().member("signer::SigningRequirements"), - "SigningService" to runtimeConfig.awsTypes().member("SigningService"), + "OperationSigningConfig" to awsSigAuth(runtimeConfig).member("signer::OperationSigningConfig"), + "SignableBody" to awsSigAuth(runtimeConfig).member("signer::SignableBody"), + "SigningRegion" to awsTypes(runtimeConfig).member("region::SigningRegion"), + "SigningRequirements" to awsSigAuth(runtimeConfig).member("signer::SigningRequirements"), + "SigningService" to awsTypes(runtimeConfig).member("SigningService"), ) private val serviceIndex = ServiceIndex.of(model) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt index 8947c5c406..42c24a2354 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt @@ -79,11 +79,11 @@ private class ApiVersionAndPubUse(private val runtimeConfig: RuntimeConfig, serv // PKG_VERSION comes from CrateVersionGenerator rustTemplate( "static API_METADATA: #{ApiMetadata} = #{ApiMetadata}::new(${serviceId.dq()}, PKG_VERSION);", - "ApiMetadata" to runtimeConfig.awsHttp().member("user_agent::ApiMetadata"), + "ApiMetadata" to awsHttp(runtimeConfig).member("user_agent::ApiMetadata"), ) // Re-export the app name so that it can be specified in config programmatically without an explicit dependency - rust("pub use #T;", runtimeConfig.awsTypes().member("app_name::AppName")) + rust("pub use #T;", awsTypes(runtimeConfig).member("app_name::AppName")) } else -> emptySection } @@ -103,8 +103,8 @@ private class UserAgentFeature(private val runtimeConfig: RuntimeConfig) : Opera } ${section.request}.properties_mut().insert(user_agent); """, - "AwsUserAgent" to runtimeConfig.awsHttp().member("user_agent::AwsUserAgent"), - "Env" to runtimeConfig.awsTypes().member("os_shim_internal::Env"), + "AwsUserAgent" to awsHttp(runtimeConfig).member("user_agent::AwsUserAgent"), + "Env" to awsTypes(runtimeConfig).member("os_shim_internal::Env"), ) } else -> emptySection @@ -112,7 +112,7 @@ private class UserAgentFeature(private val runtimeConfig: RuntimeConfig) : Opera } private class AppNameCustomization(runtimeConfig: RuntimeConfig) : ConfigCustomization() { - private val codegenScope = arrayOf("AppName" to runtimeConfig.awsTypes().member("app_name::AppName")) + private val codegenScope = arrayOf("AppName" to awsTypes(runtimeConfig).member("app_name::AppName")) override fun section(section: ServiceConfig): Writable = when (section) { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt index e23e645053..f52b643055 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt @@ -10,11 +10,12 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http 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.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.letIf @@ -42,12 +43,14 @@ class ApiGatewayDecorator : RustCodegenDecorator writable { - rust( - """${section.request} - .http_mut() - .headers_mut() - .insert("Accept", #T::HeaderValue::from_static("application/json"));""", - RuntimeType.http, + rustTemplate( + """ + ${section.request} + .http_mut() + .headers_mut() + .insert("Accept", #{HeaderValue}::from_static("application/json")); + """, + "HeaderValue" to Http.asType().member("HeaderValue"), ) } else -> emptySection diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt index 3606df8bcb..47ac503e5f 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt @@ -5,10 +5,11 @@ package software.amazon.smithy.rustsdk.servicedecorators.glacier +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http 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.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.dq @@ -22,12 +23,14 @@ class ApiVersionHeader( ) : OperationCustomization() { override fun section(section: OperationSection): Writable = when (section) { is OperationSection.MutateRequest -> writable { - rust( - """${section.request} - .http_mut() - .headers_mut() - .insert("x-amz-glacier-version", #T::HeaderValue::from_static(${apiVersion.dq()}));""", - RuntimeType.http, + rustTemplate( + """ + ${section.request} + .http_mut() + .headers_mut() + .insert("x-amz-glacier-version", #{HeaderValue}::from_static(${apiVersion.dq()})); + """, + "HeaderValue" to Http.asType().member("HeaderValue"), ) } else -> emptySection diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt index b85bf5814b..b028628212 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt @@ -17,15 +17,18 @@ import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.client.smithy.protocols.ClientRestXmlFactory +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap @@ -89,11 +92,11 @@ class S3Decorator : RustCodegenDecorator::digest(data); req.headers_mut().insert( - #{http}::header::HeaderName::from_static("content-md5"), + #{HeaderName}::from_static("content-md5"), #{base64_encode}(&checksum[..]).parse().expect("checksum is valid header value") ); Result::<_, #{BuildError}>::Ok(req) })?; """, - "md5" to CargoDependency.Md5.asType(), - "http" to CargoDependency.Http.asType(), - "base64_encode" to RuntimeType.Base64Encode(codegenContext.runtimeConfig), + "md5" to Md5.asType(), + "HeaderName" to Http.asType().member("header::HeaderName"), + "base64_encode" to RuntimeType.base64Encode(codegenContext.runtimeConfig), "BuildError" to codegenContext.runtimeConfig.operationBuildError(), ) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt index 6de29c2817..97a9017f68 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt @@ -9,9 +9,9 @@ import software.amazon.smithy.aws.traits.protocols.AwsProtocolTrait import software.amazon.smithy.model.shapes.OperationShape 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.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.getTrait @@ -21,7 +21,7 @@ class HttpVersionListCustomization( private val codegenContext: CodegenContext, private val operationShape: OperationShape, ) : OperationCustomization() { - private val defaultHttpVersions = codegenContext.runtimeConfig.smithyHttp().member("http_versions::DEFAULT_HTTP_VERSION_LIST").fullyQualifiedName() + private val defaultHttpVersions = smithyHttp(codegenContext.runtimeConfig).member("http_versions::DEFAULT_HTTP_VERSION_LIST").fullyQualifiedName() override fun section(section: OperationSection): Writable { val awsProtocolTrait = codegenContext.serviceShape.getTrait() diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt index 28be65b1f2..f892103bb7 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt @@ -9,21 +9,21 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.config.Confi import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyAsync -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyAsync +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.RustCrate class ResiliencyConfigCustomization(codegenContext: CodegenContext) : ConfigCustomization() { private val runtimeConfig = codegenContext.runtimeConfig private val moduleUseName = codegenContext.moduleUseName() private val codegenScope = arrayOf( - "AsyncSleep" to runtimeConfig.smithyAsync().member("rt::sleep::AsyncSleep"), - "RetryConfig" to runtimeConfig.smithyTypes().member("retry::RetryConfig"), - "Sleep" to runtimeConfig.smithyAsync().member("rt::sleep::Sleep"), - "TimeoutConfig" to runtimeConfig.smithyTypes().member("timeout::TimeoutConfig"), + "AsyncSleep" to smithyAsync(runtimeConfig).member("rt::sleep::AsyncSleep"), + "RetryConfig" to smithyTypes(runtimeConfig).member("retry::RetryConfig"), + "Sleep" to smithyAsync(runtimeConfig).member("rt::sleep::Sleep"), + "TimeoutConfig" to smithyTypes(runtimeConfig).member("timeout::TimeoutConfig"), ) override fun section(section: ServiceConfig) = @@ -244,9 +244,9 @@ class ResiliencyReExportCustomization(private val runtimeConfig: RuntimeConfig) pub use #{timeout}::{TimeoutConfig, TimeoutConfigBuilder}; } """, - "retry" to runtimeConfig.smithyTypes().member("retry"), - "sleep" to runtimeConfig.smithyAsync().member("rt::sleep"), - "timeout" to runtimeConfig.smithyTypes().member("timeout"), + "retry" to smithyTypes(runtimeConfig).member("retry"), + "sleep" to smithyAsync(runtimeConfig).member("rt::sleep"), + "timeout" to smithyTypes(runtimeConfig).member("timeout"), ) } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt index 722d35bb69..dbbcdbd2c4 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt @@ -10,10 +10,10 @@ import software.amazon.smithy.model.shapes.StructureShape 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.rustBlock -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.core.util.hasEventStreamMember @@ -56,9 +56,9 @@ private fun hasDateTimes(model: Model): Boolean { internal fun pubUseTypes(runtimeConfig: RuntimeConfig, model: Model): List { return ( listOf( - PubUseType(RuntimeType.Blob(runtimeConfig), ::hasBlobs), - PubUseType(RuntimeType.DateTime(runtimeConfig), ::hasDateTimes), - ) + runtimeConfig.smithyHttp().let { http -> + PubUseType(RuntimeType.blob(runtimeConfig), ::hasBlobs), + PubUseType(RuntimeType.dateTime(runtimeConfig), ::hasDateTimes), + ) + smithyHttp(runtimeConfig).let { http -> listOf( PubUseType(http.member("result::SdkError")) { true }, PubUseType(http.member("byte_stream::ByteStream"), ::hasStreamingOperations), diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt index eb79c73c5a..e9e1d0856d 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt @@ -7,12 +7,11 @@ package software.amazon.smithy.rust.codegen.client.smithy.customize import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.EventStreamSigningConfig -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyEventstream import software.amazon.smithy.rust.codegen.core.util.hasEventStreamOperations /** @@ -47,10 +46,7 @@ class NoOpEventStreamSigningConfig( private val serviceHasEventStream: Boolean, runtimeConfig: RuntimeConfig, ) : EventStreamSigningConfig(runtimeConfig) { - private val smithyEventStream = CargoDependency.smithyEventStream(runtimeConfig) - private val codegenScope = arrayOf( - "NoOpSigner" to RuntimeType("NoOpSigner", smithyEventStream, "aws_smithy_eventstream::frame"), - ) + private val codegenScope = arrayOf("NoOpSigner" to smithyEventstream(runtimeConfig).member("frame::NoOpSigner")) override fun configImplSection() = renderEventStreamSignerFn { writable { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt index fa8fa0e2bd..aab2eebc28 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt @@ -12,8 +12,8 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter 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.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.generators.OperationBuildError import software.amazon.smithy.rust.codegen.core.smithy.generators.http.rustFormatString @@ -32,8 +32,7 @@ class EndpointTraitBindings( private val endpointTrait: EndpointTrait, ) { private val inputShape = operationShape.inputShape(model) - private val smithyHttp = runtimeConfig.smithyHttp() - private val endpointPrefix = smithyHttp.member("endpoint::EndpointPrefix") + private val endpointPrefix = smithyHttp(runtimeConfig).member("endpoint::EndpointPrefix") /** * Render the `EndpointPrefix` struct. [input] refers to the symbol referring to the input of this operation. diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt index 2b149d68d3..63ec19d4a4 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt @@ -12,7 +12,7 @@ import software.amazon.smithy.model.shapes.ServiceShape 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.CargoDependency.Companion.TokioStream 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 @@ -22,14 +22,14 @@ import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.render 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.rustlang.smithyAsync -import software.amazon.smithy.rust.codegen.core.rustlang.smithyClient -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyAsync +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyClient +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.generators.builderSymbol import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol @@ -113,12 +113,12 @@ class PaginatorGenerator private constructor( "Builder" to operation.inputShape(model).builderSymbol(symbolProvider), // SDK Types - "SdkError" to runtimeConfig.smithyHttp().member("result::SdkError"), - "client" to runtimeConfig.smithyClient(), - "fn_stream" to runtimeConfig.smithyAsync().member("future::fn_stream"), + "SdkError" to smithyHttp(runtimeConfig).member("result::SdkError"), + "client" to smithyClient(runtimeConfig), + "fn_stream" to smithyAsync(runtimeConfig).member("future::fn_stream"), // External Types - "Stream" to CargoDependency.TokioStream.asType().member("Stream"), + "Stream" to TokioStream.asType().member("Stream"), ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt index d36e4f1f09..d5a23232a3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt @@ -5,7 +5,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.client -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http 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 @@ -15,10 +15,10 @@ 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 import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyClient -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyClient +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.RustCrate /** @@ -47,9 +47,9 @@ class CustomizableOperationGenerator( pub use #{ClassifyRetry}; pub use #{RetryKind}; """, - "Operation" to runtimeConfig.smithyHttp().member("operation::Operation"), - "ClassifyRetry" to runtimeConfig.smithyHttp().member("retry::ClassifyRetry"), - "RetryKind" to runtimeConfig.smithyTypes().member("retry::RetryKind"), + "Operation" to smithyHttp(runtimeConfig).member("operation::Operation"), + "ClassifyRetry" to smithyHttp(runtimeConfig).member("retry::ClassifyRetry"), + "RetryKind" to smithyTypes(runtimeConfig).member("retry::RetryKind"), ) renderCustomizableOperationModule(this) @@ -66,9 +66,9 @@ class CustomizableOperationGenerator( val codegenScope = arrayOf( // SDK Types - "http_result" to runtimeConfig.smithyHttp().member("result"), - "http_body" to runtimeConfig.smithyHttp().member("body"), - "HttpRequest" to CargoDependency.Http.asType().member("Request"), + "http_result" to smithyHttp(runtimeConfig).member("result"), + "http_body" to smithyHttp(runtimeConfig).member("body"), + "HttpRequest" to Http.asType().member("Request"), "handle_generics_decl" to handleGenerics.declaration(), "handle_generics_bounds" to handleGenerics.bounds(), "operation_generics_decl" to operationGenerics.declaration(), @@ -150,9 +150,9 @@ class CustomizableOperationGenerator( val codegenScope = arrayOf( "combined_generics_decl" to combinedGenerics.declaration(), "handle_generics_bounds" to handleGenerics.bounds(), - "ParseHttpResponse" to runtimeConfig.smithyHttp().member("response::ParseHttpResponse"), - "NewRequestPolicy" to runtimeConfig.smithyClient().member("retry::NewRequestPolicy"), - "SmithyRetryPolicy" to runtimeConfig.smithyClient().member("bounds::SmithyRetryPolicy"), + "ParseHttpResponse" to smithyHttp(runtimeConfig).member("response::ParseHttpResponse"), + "NewRequestPolicy" to smithyClient(runtimeConfig).member("retry::NewRequestPolicy"), + "SmithyRetryPolicy" to smithyClient(runtimeConfig).member("bounds::SmithyRetryPolicy"), ) writer.rustTemplate( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt index 4ba7cf1890..7920924166 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt @@ -10,15 +10,14 @@ import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.Feature import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType 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.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyClient import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.customize.NamedSectionGenerator import software.amazon.smithy.rust.codegen.core.smithy.customize.Section @@ -81,8 +80,7 @@ abstract class FluentClientCustomization : NamedSectionGenerator writable { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt index d4e5fd96e6..8d5a2489d2 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt @@ -15,14 +15,12 @@ import software.amazon.smithy.model.traits.DocumentationTrait import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.generators.PaginatorGenerator import software.amazon.smithy.rust.codegen.client.smithy.generators.isPaginated -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.asArgumentType import software.amazon.smithy.rust.codegen.core.rustlang.asOptional -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape import software.amazon.smithy.rust.codegen.core.rustlang.docLink import software.amazon.smithy.rust.codegen.core.rustlang.docs @@ -35,12 +33,12 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTypeParameters -import software.amazon.smithy.rust.codegen.core.rustlang.smithyClient -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyClient +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp 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.customize.writeCustomizations @@ -59,11 +57,11 @@ class FluentClientGenerator( private val generics: FluentClientGenerics = FlexibleClientGenerics( connectorDefault = null, middlewareDefault = null, - retryDefault = codegenContext.runtimeConfig.smithyClient().member("retry::Standard"), - client = codegenContext.runtimeConfig.smithyClient(), + retryDefault = smithyClient(codegenContext.runtimeConfig).member("retry::Standard"), + client = smithyClient(codegenContext.runtimeConfig), ), private val customizations: List = emptyList(), - private val retryClassifier: RuntimeType = codegenContext.runtimeConfig.smithyHttp().member("retry::DefaultResponseRetryClassifier"), + private val retryClassifier: RuntimeType = smithyHttp(codegenContext.runtimeConfig).member("retry::DefaultResponseRetryClassifier"), ) { companion object { fun clientOperationFnName(operationShape: OperationShape, symbolProvider: RustSymbolProvider): String = @@ -80,8 +78,8 @@ class FluentClientGenerator( TopDownIndex.of(codegenContext.model).getContainedOperations(serviceShape).sortedBy { it.id } private val symbolProvider = codegenContext.symbolProvider private val model = codegenContext.model - private val clientDep = CargoDependency.smithyClient(codegenContext.runtimeConfig) private val runtimeConfig = codegenContext.runtimeConfig + private val clientDep = smithyClient(runtimeConfig) private val core = FluentClientCore(model) fun render(crate: RustCrate) { @@ -145,7 +143,7 @@ class FluentClientGenerator( """, "generics_decl" to generics.decl, "smithy_inst" to generics.smithyInst, - "client" to clientDep.asType(), + "client" to clientDep, "client_docs" to writable { customizations.forEach { @@ -159,7 +157,7 @@ class FluentClientGenerator( ) writer.rustBlockTemplate( "impl${generics.inst} Client${generics.inst} #{bounds:W}", - "client" to clientDep.asType(), + "client" to clientDep, "bounds" to generics.bounds, ) { operations.forEach { operation -> @@ -254,14 +252,14 @@ class FluentClientGenerator( } """, "Inner" to input.builderSymbol(symbolProvider), - "client" to clientDep.asType(), + "client" to clientDep, "generics" to generics.decl, "operation" to operationSymbol, ) rustBlockTemplate( "impl${generics.inst} ${operationSymbol.name}${generics.inst} #{bounds:W}", - "client" to clientDep.asType(), + "client" to clientDep, "bounds" to generics.bounds, ) { val outputType = symbolProvider.toSymbol(operation.outputShape(model)) @@ -306,11 +304,11 @@ class FluentClientGenerator( self.handle.client.call(op).await } """, - "ClassifyRetry" to runtimeConfig.smithyHttp().member("retry::ClassifyRetry"), + "ClassifyRetry" to smithyHttp(runtimeConfig).member("retry::ClassifyRetry"), "OperationError" to errorType, "OperationOutput" to outputType, - "SdkError" to runtimeConfig.smithyHttp().member("result::SdkError"), - "SdkSuccess" to runtimeConfig.smithyHttp().member("result::SdkSuccess"), + "SdkError" to smithyHttp(runtimeConfig).member("result::SdkError"), + "SdkSuccess" to smithyHttp(runtimeConfig).member("result::SdkSuccess"), "send_bounds" to generics.sendBounds(operationSymbol, outputType, errorType, retryClassifier), "customizable_op_type_params" to rustTypeParameters( symbolProvider.toSymbol(operation), diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt index 6e6e167a5a..6cb91d53d3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt @@ -5,27 +5,19 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.config -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyEventstream +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp open class EventStreamSigningConfig( runtimeConfig: RuntimeConfig, ) : ConfigCustomization() { private val codegenScope = arrayOf( - "SharedPropertyBag" to RuntimeType( - "SharedPropertyBag", - CargoDependency.smithyHttp(runtimeConfig), - "aws_smithy_http::property_bag", - ), - "SignMessage" to RuntimeType( - "SignMessage", - CargoDependency.smithyEventStream(runtimeConfig), - "aws_smithy_eventstream::frame", - ), + "SharedPropertyBag" to smithyHttp(runtimeConfig).member("property_bag::SharedPropertyBag"), + "SignMessage" to smithyEventstream(runtimeConfig).member("frame::SignMessage"), ) override fun section(section: ServiceConfig): Writable { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt index a80c9db0b5..43d20282f9 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt @@ -21,7 +21,9 @@ import software.amazon.smithy.protocoltests.traits.HttpResponseTestCase import software.amazon.smithy.protocoltests.traits.HttpResponseTestsTrait import software.amazon.smithy.rust.codegen.client.smithy.generators.clientInstantiator import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.PrettyAssertions 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.RustWriter @@ -32,10 +34,11 @@ import software.amazon.smithy.rust.codegen.core.rustlang.escape 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.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyProtocolTest import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.testutil.TokioTest @@ -69,9 +72,8 @@ class ProtocolTestGenerator( private val instantiator = clientInstantiator(codegenContext) private val codegenScope = arrayOf( - "SmithyHttp" to runtimeConfig.smithyHttp(), - "Http" to CargoDependency.Http.asType(), - "AssertEq" to CargoDependency.PrettyAssertions.asType().member("assert_eq!"), + "SmithyHttp" to smithyHttp(runtimeConfig), + "AssertEq" to PrettyAssertions.asType().member("assert_eq!"), ) sealed class TestCase { @@ -188,10 +190,11 @@ class ProtocolTestGenerator( rustTemplate( """ let mut http_request = http_request; - let ep = #{SmithyHttp}::endpoint::Endpoint::mutable(#{Http}::Uri::from_static(${withScheme.dq()})); + let ep = #{Endpoint}::mutable(#{Uri}::from_static(${withScheme.dq()})); ep.set_endpoint(http_request.uri_mut(), parts.acquire().get()); """, - *codegenScope, + "Endpoint" to smithyHttp(runtimeConfig).member("endpoint::Endpoint"), + "Uri" to Http.asType().member("Uri"), ) } rustTemplate( @@ -252,10 +255,10 @@ class ProtocolTestGenerator( rust("/* test case disabled for this protocol (not yet supported) */") return } - writeInline("let expected_output =") + write("let expected_output =") instantiator.render(this, expectedShape, testCase.params) write(";") - write("let http_response = #T::new()", RuntimeType.HttpResponseBuilder) + rust("let http_response = #T::new()", Http.asType().member("response::Builder")) testCase.headers.forEach { (key, value) -> writeWithNoFormatting(".header(${key.dq()}, ${value.dq()})") } @@ -265,11 +268,11 @@ class ProtocolTestGenerator( .body(#T::from(${testCase.body.orNull()?.dq()?.replace("#", "##") ?: "vec![]"})) .unwrap(); """, - RuntimeType.sdkBody(runtimeConfig = codegenContext.runtimeConfig), + RuntimeType.sdkBody(runtimeConfig), ) - write( + rust( "let mut op_response = #T::new(http_response);", - RuntimeType.operationModule(codegenContext.runtimeConfig).member("Response"), + RuntimeType.operationModule(runtimeConfig).member("Response"), ) rustTemplate( """ @@ -283,9 +286,8 @@ class ProtocolTestGenerator( }); """, "op" to operationSymbol, - "bytes" to RuntimeType.Bytes, - "parse_http_response" to CargoDependency.smithyHttp(codegenContext.runtimeConfig).asType() - .member("response::ParseHttpResponse"), + "bytes" to Bytes.asType().member("Bytes"), + "parse_http_response" to smithyHttp(runtimeConfig).member("response::ParseHttpResponse"), ) if (expectedShape.hasTrait()) { val errorSymbol = operationShape.errorSymbol(codegenContext.model, codegenContext.symbolProvider, codegenContext.target) @@ -315,12 +317,14 @@ class ProtocolTestGenerator( when (codegenContext.model.expectShape(member.target)) { is DoubleShape, is FloatShape -> { addUseImports( - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "FloatEquals").toSymbol(), + smithyProtocolTest(codegenContext.runtimeConfig).member("FloatEquals").toSymbol(), ) rust( """ - assert!(parsed.$memberName.float_equals(&expected_output.$memberName), - "Unexpected value for `$memberName` {:?} vs. {:?}", expected_output.$memberName, parsed.$memberName); + assert!( + parsed.$memberName.float_equals(&expected_output.$memberName), + "Unexpected value for `$memberName` {:?} vs. {:?}", expected_output.$memberName, parsed.$memberName + ); """, ) } @@ -332,25 +336,25 @@ class ProtocolTestGenerator( } } - private fun checkBody(rustWriter: RustWriter, body: String, mediaType: String?) { + private fun checkBody(rustWriter: RustWriter, expectedBody: String, mediaType: String?) { rustWriter.write("""let body = http_request.body().bytes().expect("body should be strict");""") - if (body == "") { + if (expectedBody == "") { rustWriter.rustTemplate( """ // No body - #{AssertEq}(std::str::from_utf8(body).unwrap(), ""); + assert!(std::str::from_utf8(body).unwrap().is_empty()); """, *codegenScope, ) } else { // When we generate a body instead of a stub, drop the trailing `;` and enable the assertion assertOk(rustWriter) { - rustWriter.write( - "#T(&body, ${ - rustWriter.escape(body).dq() - }, #T::from(${(mediaType ?: "unknown").dq()}))", - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "validate_body"), - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "MediaType"), + val escapedExpectedBody = rustWriter.escape(expectedBody).dq() + val rawMediaType = (mediaType ?: "unknown").dq() + rustTemplate( + "#{validate_body}(&body, $escapedExpectedBody, #{MediaType}::from($rawMediaType))", + "validate_body" to smithyProtocolTest(runtimeConfig).member("validate_body"), + "MediaType" to smithyProtocolTest(runtimeConfig).member("MediaType"), ) } } @@ -391,7 +395,7 @@ class ProtocolTestGenerator( assertOk(rustWriter) { write( "#T($actualExpression, $variableName)", - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "validate_headers"), + RuntimeType.protocolTest(runtimeConfig, "validate_headers"), ) } } @@ -445,7 +449,7 @@ class ProtocolTestGenerator( assertOk(rustWriter) { write( "#T($actualExpression, $expectedVariableName)", - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, checkFunction), + RuntimeType.protocolTest(runtimeConfig, checkFunction), ) } } @@ -455,7 +459,7 @@ class ProtocolTestGenerator( * for pretty printing protocol test helper results */ private fun assertOk(rustWriter: RustWriter, inner: Writable) { - rustWriter.write("#T(", RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "assert_ok")) + rustWriter.write("#T(", RuntimeType.protocolTest(runtimeConfig, "assert_ok")) inner(rustWriter) rustWriter.write(");") } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt index 912a0f668a..419b9ad68a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt @@ -11,9 +11,12 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http 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.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.assignment import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock @@ -77,9 +80,9 @@ class HttpBoundProtocolTraitImplGenerator( private val codegenScope = arrayOf( "ParseStrict" to RuntimeType.parseStrictResponse(runtimeConfig), "ParseResponse" to RuntimeType.parseResponse(runtimeConfig), - "http" to RuntimeType.http, + "http" to Http.asType(), "operation" to RuntimeType.operationModule(runtimeConfig), - "Bytes" to RuntimeType.Bytes, + "Bytes" to Bytes.asType().member("Bytes"), ) override fun generateTraitImpls( diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt index cdb30ad046..e2526b5ea0 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt @@ -14,13 +14,13 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.config.Confi import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.client.testutil.AddRustTestsDecorator -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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 import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyEventstream +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.testutil.TokioTest import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext @@ -222,26 +222,10 @@ class FakeSigningConfig( runtimeConfig: RuntimeConfig, ) : ConfigCustomization() { private val codegenScope = arrayOf( - "SharedPropertyBag" to RuntimeType( - "SharedPropertyBag", - CargoDependency.smithyHttp(runtimeConfig), - "aws_smithy_http::property_bag", - ), - "SignMessageError" to RuntimeType( - "SignMessageError", - CargoDependency.smithyEventStream(runtimeConfig), - "aws_smithy_eventstream::frame", - ), - "SignMessage" to RuntimeType( - "SignMessage", - CargoDependency.smithyEventStream(runtimeConfig), - "aws_smithy_eventstream::frame", - ), - "Message" to RuntimeType( - "Message", - CargoDependency.smithyEventStream(runtimeConfig), - "aws_smithy_eventstream::frame", - ), + "SharedPropertyBag" to smithyHttp(runtimeConfig).member("property_bag::SharedPropertyBag"), + "SignMessageError" to smithyEventstream(runtimeConfig).member("frame::SignMessageError"), + "SignMessage" to smithyEventstream(runtimeConfig).member("frame::SignMessage"), + "Message" to smithyEventstream(runtimeConfig).member("frame::Message"), ) override fun section(section: ServiceConfig): Writable { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt index 45a475185c..39fd6f3fe3 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt @@ -20,8 +20,8 @@ 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.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError @@ -79,7 +79,7 @@ internal class EndpointTraitBindingsTest { implBlock(model.lookup("test#GetStatusInput"), sym) { rustBlock( "fn endpoint_prefix(&self) -> std::result::Result<#T::endpoint::EndpointPrefix, #T>", - TestRuntimeConfig.smithyHttp(), + smithyHttp(TestRuntimeConfig), TestRuntimeConfig.operationBuildError(), ) { endpointBindingGenerator.render(this, "self") diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt index cf520bb7fe..220e1c8fe5 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt @@ -14,7 +14,10 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.CodegenVisitor import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.escape import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate @@ -65,8 +68,8 @@ private class TestProtocolTraitImplGenerator( "parse_strict" to RuntimeType.parseStrictResponse(codegenContext.runtimeConfig), "output" to symbolProvider.toSymbol(operationShape.outputShape(codegenContext.model)), "error" to operationShape.errorSymbol(codegenContext.model, symbolProvider, codegenContext.target), - "response" to RuntimeType.Http("Response"), - "bytes" to RuntimeType.Bytes, + "response" to Http.asType().member("Response"), + "bytes" to Bytes.asType().member("Bytes"), ) } } @@ -84,7 +87,7 @@ private class TestProtocolMakeOperationGenerator( includeDefaultPayloadHeaders = true, ) { override fun createHttpRequest(writer: RustWriter, operationShape: OperationShape) { - writer.rust("#T::new()", RuntimeType.HttpRequestBuilder) + writer.rust("#T::new()", Http.asType().member("request::Builder")) writer.writeWithNoFormatting(httpRequestBuilder) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt index e89d3e41ea..d5166c841c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt @@ -185,43 +185,49 @@ data class CargoDependency( } companion object { + // Regular dependencies val Bytes: CargoDependency = CargoDependency("bytes", CratesIo("1.0.0")) val BytesUtils: CargoDependency = CargoDependency("bytes-utils", CratesIo("0.1.0")) val FastRand: CargoDependency = CargoDependency("fastrand", CratesIo("1.0.0")) val Hex: CargoDependency = CargoDependency("hex", CratesIo("0.4.3")) - val HttpBody: CargoDependency = CargoDependency("http-body", CratesIo("0.4.4")) val Http: CargoDependency = CargoDependency("http", CratesIo("0.2.0")) + val HttpBody: CargoDependency = CargoDependency("http-body", CratesIo("0.4.4")) val Hyper: CargoDependency = CargoDependency("hyper", CratesIo("0.14.12")) val HyperWithStream: CargoDependency = Hyper.withFeature("stream") val LazyStatic: CargoDependency = CargoDependency("lazy_static", CratesIo("1.4.0")) val Md5: CargoDependency = CargoDependency("md-5", CratesIo("0.10.0"), rustName = "md5") val PercentEncoding: CargoDependency = CargoDependency("percent-encoding", CratesIo("2.0.0")) - val PrettyAssertions: CargoDependency = CargoDependency("pretty_assertions", CratesIo("1.0.0"), scope = DependencyScope.Dev) val Regex: CargoDependency = CargoDependency("regex", CratesIo("1.5.5")) val Ring: CargoDependency = CargoDependency("ring", CratesIo("0.16.0")) - val TempFile: CargoDependency = CargoDependency("tempfile", CratesIo("3.2.0"), scope = DependencyScope.Dev) val TokioStream: CargoDependency = CargoDependency("tokio-stream", CratesIo("0.1.7")) val Tower: CargoDependency = CargoDependency("tower", CratesIo("0.4")) val Tracing: CargoDependency = CargoDependency("tracing", CratesIo("0.1")) + // Test-only dependencies + val AsyncStd: CargoDependency = CargoDependency("async-std", CratesIo("1.12.0"), DependencyScope.Dev) + val AsyncStream: CargoDependency = CargoDependency("async-stream", CratesIo("0.3.0"), DependencyScope.Dev) + val Criterion: CargoDependency = CargoDependency("criterion", CratesIo("0.4.0"), DependencyScope.Dev) + val FuturesCore: CargoDependency = CargoDependency("futures-core", CratesIo("0.3.0"), DependencyScope.Dev) + val FuturesUtil: CargoDependency = CargoDependency("futures-util", CratesIo("0.3.0"), DependencyScope.Dev) + val Hound: CargoDependency = CargoDependency("hound", CratesIo("3.4.0"), DependencyScope.Dev) + val PrettyAssertions: CargoDependency = CargoDependency("pretty_assertions", CratesIo("1.0.0"), DependencyScope.Dev) + val SerdeJson: CargoDependency = CargoDependency("serde_json", CratesIo("1.0.0"), DependencyScope.Dev) + val Smol: CargoDependency = CargoDependency("smol", CratesIo("1.2.0"), DependencyScope.Dev) + val TempFile: CargoDependency = CargoDependency("tempfile", CratesIo("3.2.0"), DependencyScope.Dev) + val Tokio: CargoDependency = CargoDependency("tokio", CratesIo("1.8.4"), DependencyScope.Dev, features = setOf("macros", "test-util")) + val TracingSubscriber: CargoDependency = CargoDependency("tracing-subscriber", CratesIo("0.3.15"), DependencyScope.Dev, features = setOf("env-filter")) + + fun smithyAsync(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-async") fun smithyChecksums(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-checksums") fun smithyClient(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-client") - fun smithyEventStream(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-eventstream") + fun smithyEventstream(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-eventstream") fun smithyHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http") fun smithyHttpTower(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http-tower") + fun smithyJson(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-json") fun smithyProtocolTestHelpers(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-protocol-test", scope = DependencyScope.Dev) + fun smithyQuery(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-query") fun smithyTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-types") fun smithyXml(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-xml") } } - -fun RuntimeConfig.smithyAsync() = smithyRuntimeCrate("smithy-async").asType() -fun RuntimeConfig.smithyChecksums() = smithyRuntimeCrate("smithy-checksums").asType() -fun RuntimeConfig.smithyClient() = smithyRuntimeCrate("smithy-client").asType() -fun RuntimeConfig.smithyEventStream() = smithyRuntimeCrate("smithy-eventstream").asType() -fun RuntimeConfig.smithyHttp() = smithyRuntimeCrate("smithy-http").asType() -fun RuntimeConfig.smithyJson() = smithyRuntimeCrate("smithy-json").asType() -fun RuntimeConfig.smithyQuery() = smithyRuntimeCrate("smithy-query").asType() -fun RuntimeConfig.smithyTypes() = smithyRuntimeCrate("smithy-types").asType() -fun RuntimeConfig.smithyXml() = smithyRuntimeCrate("smithy-xml").asType() diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/Writable.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/Writable.kt index 5cf2180ee2..e5131979f4 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/Writable.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/Writable.kt @@ -83,7 +83,7 @@ fun Array.join(separator: Writable) = asIterable().join(separator) * "type_params" to rustTypeParameters( * symbolProvider.toSymbol(operation), * RustType.Unit, - * runtimeConfig.smithyHttp().member("body::SdkBody"), + * smithyHttp(runtimeConfig).member("body::SdkBody"), * GenericsGenerator(GenericTypeArg("A"), GenericTypeArg("B")), * ) * ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt index 38afba52fc..a253163eb0 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt @@ -175,129 +175,66 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n * The companion object contains commonly used RuntimeTypes */ companion object { - fun errorKind(runtimeConfig: RuntimeConfig) = RuntimeType( - "ErrorKind", - dependency = CargoDependency.smithyTypes(runtimeConfig), - namespace = "${runtimeConfig.crateSrcPrefix}_smithy_types::retry", - ) - - fun provideErrorKind(runtimeConfig: RuntimeConfig) = RuntimeType( - "ProvideErrorKind", - dependency = CargoDependency.smithyTypes(runtimeConfig), - namespace = "${runtimeConfig.crateSrcPrefix}_smithy_types::retry", - ) - + // stdlib types val std = RuntimeType(null, dependency = null, namespace = "std") - val stdfmt = std.member("fmt") - + val stdFmt = std.member("fmt") val AsRef = RuntimeType("AsRef", dependency = null, namespace = "std::convert") val ByteSlab = RuntimeType("Vec", dependency = null, namespace = "std::vec") val Clone = std.member("clone::Clone") - val Debug = stdfmt.member("Debug") + val Debug = stdFmt.member("Debug") val Default: RuntimeType = RuntimeType("Default", dependency = null, namespace = "std::default") - val Display = stdfmt.member("Display") + val Display = stdFmt.member("Display") val From = RuntimeType("From", dependency = null, namespace = "std::convert") val TryFrom = RuntimeType("TryFrom", dependency = null, namespace = "std::convert") val PartialEq = std.member("cmp::PartialEq") val StdError = RuntimeType("Error", dependency = null, namespace = "std::error") val String = RuntimeType("String", dependency = null, namespace = "std::string") - fun DateTime(runtimeConfig: RuntimeConfig) = - RuntimeType("DateTime", CargoDependency.smithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_types") - - fun GenericError(runtimeConfig: RuntimeConfig) = - RuntimeType("Error", CargoDependency.smithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_types") - - fun Blob(runtimeConfig: RuntimeConfig) = - RuntimeType("Blob", CargoDependency.smithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_types") - - fun ByteStream(runtimeConfig: RuntimeConfig) = - RuntimeType("ByteStream", CargoDependency.smithyHttp(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http::byte_stream") - - fun Document(runtimeConfig: RuntimeConfig): RuntimeType = - RuntimeType("Document", CargoDependency.smithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_types") - - fun LabelFormat(runtimeConfig: RuntimeConfig, func: String) = - RuntimeType(func, CargoDependency.smithyHttp(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http::label") - - fun QueryFormat(runtimeConfig: RuntimeConfig, func: String) = - RuntimeType(func, CargoDependency.smithyHttp(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http::query") - - fun Base64Encode(runtimeConfig: RuntimeConfig): RuntimeType = - RuntimeType( - "encode", - CargoDependency.smithyTypes(runtimeConfig), - "${runtimeConfig.crateSrcPrefix}_smithy_types::base64", - ) - - fun Base64Decode(runtimeConfig: RuntimeConfig): RuntimeType = - RuntimeType( - "decode", - CargoDependency.smithyTypes(runtimeConfig), - "${runtimeConfig.crateSrcPrefix}_smithy_types::base64", - ) + // codegen types + val Config = RuntimeType("config", null, "crate") - fun TimestampFormat(runtimeConfig: RuntimeConfig, format: TimestampFormatTrait.Format): RuntimeType { + // smithy runtime types + fun smithyAsync(runtimeConfig: RuntimeConfig) = CargoDependency.smithyAsync(runtimeConfig).asType() + fun smithyChecksums(runtimeConfig: RuntimeConfig) = CargoDependency.smithyChecksums(runtimeConfig).asType() + fun smithyClient(runtimeConfig: RuntimeConfig) = CargoDependency.smithyClient(runtimeConfig).asType() + fun smithyEventstream(runtimeConfig: RuntimeConfig) = CargoDependency.smithyEventstream(runtimeConfig).asType() + fun smithyHttp(runtimeConfig: RuntimeConfig) = CargoDependency.smithyHttp(runtimeConfig).asType() + fun smithyJson(runtimeConfig: RuntimeConfig) = CargoDependency.smithyJson(runtimeConfig).asType() + fun smithyQuery(runtimeConfig: RuntimeConfig) = CargoDependency.smithyQuery(runtimeConfig).asType() + fun smithyTypes(runtimeConfig: RuntimeConfig) = CargoDependency.smithyTypes(runtimeConfig).asType() + fun smithyXml(runtimeConfig: RuntimeConfig) = CargoDependency.smithyXml(runtimeConfig).asType() + fun smithyProtocolTest(runtimeConfig: RuntimeConfig) = CargoDependency.smithyProtocolTestHelpers(runtimeConfig).asType() + + // smithy runtime type members + fun base64Decode(runtimeConfig: RuntimeConfig): RuntimeType = smithyTypes(runtimeConfig).member("base64::decode") + fun base64Encode(runtimeConfig: RuntimeConfig): RuntimeType = smithyTypes(runtimeConfig).member("base64::encode") + fun blob(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).member("Blob") + fun byteStream(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).member("byte_stream::ByteStream") + fun dateTime(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).member("DateTime") + fun document(runtimeConfig: RuntimeConfig): RuntimeType = smithyTypes(runtimeConfig).member("Document") + fun errorKind(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).member("retry::ErrorKind") + fun eventStreamReceiver(runtimeConfig: RuntimeConfig): RuntimeType = smithyHttp(runtimeConfig).member("event_stream::Receiver") + fun genericError(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).member("Error") + fun jsonErrors(runtimeConfig: RuntimeConfig) = forInlineDependency(InlineDependency.jsonErrors(runtimeConfig)) + fun labelFormat(runtimeConfig: RuntimeConfig, func: String) = smithyHttp(runtimeConfig).member("label::$func") + fun operation(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).member("operation::Operation") + fun operationModule(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).member("operation") + fun parseResponse(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).member("response::ParseHttpResponse") + fun parseStrictResponse(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).member("response::ParseStrictResponse") + fun protocolTest(runtimeConfig: RuntimeConfig, func: String): RuntimeType = smithyProtocolTest(runtimeConfig).member(func) + fun provideErrorKind(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).member("retry::ProvideErrorKind") + fun queryFormat(runtimeConfig: RuntimeConfig, func: String) = smithyHttp(runtimeConfig).member("query::$func") + fun sdkBody(runtimeConfig: RuntimeConfig): RuntimeType = smithyHttp(runtimeConfig).member("body::SdkBody") + fun timestampFormat(runtimeConfig: RuntimeConfig, format: TimestampFormatTrait.Format): RuntimeType { val timestampFormat = when (format) { TimestampFormatTrait.Format.EPOCH_SECONDS -> "EpochSeconds" TimestampFormatTrait.Format.DATE_TIME -> "DateTime" TimestampFormatTrait.Format.HTTP_DATE -> "HttpDate" TimestampFormatTrait.Format.UNKNOWN -> TODO() } - return RuntimeType( - timestampFormat, - CargoDependency.smithyTypes(runtimeConfig), - "${runtimeConfig.crateSrcPrefix}_smithy_types::date_time::Format", - ) - } - - fun ProtocolTestHelper(runtimeConfig: RuntimeConfig, func: String): RuntimeType = - RuntimeType( - func, CargoDependency.smithyProtocolTestHelpers(runtimeConfig), "aws_smithy_protocol_test", - ) - - val http = CargoDependency.Http.asType() - fun Http(path: String): RuntimeType = - RuntimeType(name = path, dependency = CargoDependency.Http, namespace = "http") - val HttpRequestBuilder = Http("request::Builder") - val HttpResponseBuilder = Http("response::Builder") - - fun eventStreamReceiver(runtimeConfig: RuntimeConfig): RuntimeType = - RuntimeType( - "Receiver", - dependency = CargoDependency.smithyHttp(runtimeConfig), - "aws_smithy_http::event_stream", - ) - - fun jsonErrors(runtimeConfig: RuntimeConfig) = forInlineDependency(InlineDependency.jsonErrors(runtimeConfig)) - - val IdempotencyToken by lazy { forInlineDependency(InlineDependency.idempotencyToken()) } - - val Config = RuntimeType("config", null, "crate") - - fun operation(runtimeConfig: RuntimeConfig) = RuntimeType( - "Operation", - dependency = CargoDependency.smithyHttp(runtimeConfig), - namespace = "aws_smithy_http::operation", - ) - - fun operationModule(runtimeConfig: RuntimeConfig) = RuntimeType( - null, - dependency = CargoDependency.smithyHttp(runtimeConfig), - namespace = "aws_smithy_http::operation", - ) - - fun sdkBody(runtimeConfig: RuntimeConfig): RuntimeType = - RuntimeType("SdkBody", dependency = CargoDependency.smithyHttp(runtimeConfig), "aws_smithy_http::body") - - fun parseStrictResponse(runtimeConfig: RuntimeConfig) = RuntimeType( - "ParseStrictResponse", - dependency = CargoDependency.smithyHttp(runtimeConfig), - namespace = "aws_smithy_http::response", - ) - - val Bytes = RuntimeType("Bytes", dependency = CargoDependency.Bytes, namespace = "bytes") + return smithyTypes(runtimeConfig).member("date_time::Format::$timestampFormat") + } fun forInlineDependency(inlineDependency: InlineDependency) = RuntimeType(inlineDependency.name, inlineDependency, namespace = "crate") @@ -308,19 +245,13 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n namespace = "crate::${module.name}", ) - fun parseResponse(runtimeConfig: RuntimeConfig) = RuntimeType( - "ParseHttpResponse", - dependency = CargoDependency.smithyHttp(runtimeConfig), - namespace = "aws_smithy_http::response", - ) - + // inlinable types fun ec2QueryErrors(runtimeConfig: RuntimeConfig) = forInlineDependency(InlineDependency.ec2QueryErrors(runtimeConfig)) - fun wrappedXmlErrors(runtimeConfig: RuntimeConfig) = forInlineDependency(InlineDependency.wrappedXmlErrors(runtimeConfig)) - fun unwrappedXmlErrors(runtimeConfig: RuntimeConfig) = forInlineDependency(InlineDependency.unwrappedXmlErrors(runtimeConfig)) + val IdempotencyToken by lazy { forInlineDependency(InlineDependency.idempotencyToken()) } } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt index d72bafb5b9..0d91273541 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt @@ -205,7 +205,7 @@ open class SymbolVisitor( } override fun blobShape(shape: BlobShape?): Symbol { - return RuntimeType.Blob(config.runtimeConfig).toSymbol() + return RuntimeType.blob(config.runtimeConfig).toSymbol() } private fun handleOptionality(symbol: Symbol, member: MemberShape): Symbol = @@ -272,7 +272,7 @@ open class SymbolVisitor( } override fun documentShape(shape: DocumentShape?): Symbol { - return RuntimeType.Document(config.runtimeConfig).toSymbol() + return RuntimeType.document(config.runtimeConfig).toSymbol() } override fun bigIntegerShape(shape: BigIntegerShape?): Symbol { @@ -332,7 +332,7 @@ open class SymbolVisitor( } override fun timestampShape(shape: TimestampShape?): Symbol { - return RuntimeType.DateTime(config.runtimeConfig).toSymbol() + return RuntimeType.dateTime(config.runtimeConfig).toSymbol() } private fun symbolBuilder(rustType: RustType): Symbol.Builder { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt index 6efab7b0ba..1319851194 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt @@ -39,12 +39,12 @@ import software.amazon.smithy.rust.codegen.core.rustlang.escape 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.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyJson +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.isOptional import software.amazon.smithy.rust.codegen.core.smithy.rustType @@ -93,7 +93,7 @@ open class Instantiator( // Wrapped Shapes is TimestampShape -> writer.rust( "#T::from_secs(${(data as NumberNode).value})", - RuntimeType.DateTime(runtimeConfig), + RuntimeType.dateTime(runtimeConfig), ) /** @@ -104,12 +104,12 @@ open class Instantiator( is BlobShape -> if (shape.hasTrait()) { writer.rust( "#T::from_static(b${(data as StringNode).value.dq()})", - RuntimeType.ByteStream(runtimeConfig), + RuntimeType.byteStream(runtimeConfig), ) } else { writer.rust( "#T::new(${(data as StringNode).value.dq()})", - RuntimeType.Blob(runtimeConfig), + RuntimeType.blob(runtimeConfig), ) } @@ -124,7 +124,7 @@ open class Instantiator( <#{Number} as #{Parse}>::parse_smithy_primitive(${data.value.dq()}).expect("invalid string for number") """, "Number" to numberSymbol, - "Parse" to runtimeConfig.smithyTypes().member("primitive::Parse"), + "Parse" to smithyTypes(runtimeConfig).member("primitive::Parse"), ) } @@ -139,8 +139,8 @@ open class Instantiator( let mut tokens = #{json_token_iter}(json_bytes).peekable(); #{expect_document}(&mut tokens).expect("well formed json") """, - "expect_document" to runtimeConfig.smithyJson().member("deserialize::token::expect_document"), - "json_token_iter" to runtimeConfig.smithyJson().member("deserialize::json_token_iter"), + "expect_document" to smithyJson(runtimeConfig).member("deserialize::token::expect_document"), + "json_token_iter" to smithyJson(runtimeConfig).member("deserialize::json_token_iter"), ) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index bf8b58663d..d1455bdbf7 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -105,7 +105,7 @@ open class StructureGenerator( */ private fun renderDebugImpl() { writer.rustBlock("impl ${lifetimeDeclaration()} #T for $name ${lifetimeDeclaration()}", RuntimeType.Debug) { - writer.rustBlock("fn fmt(&self, f: &mut #1T::Formatter<'_>) -> #1T::Result", RuntimeType.stdfmt) { + writer.rustBlock("fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result") { rust("""let mut formatter = f.debug_struct(${name.dq()});""") members.forEach { member -> val memberName = symbolProvider.toMemberName(member) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/TypeConversionGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/TypeConversionGenerator.kt index dd46fcba42..b79200f952 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/TypeConversionGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/TypeConversionGenerator.kt @@ -28,8 +28,8 @@ import software.amazon.smithy.rust.codegen.core.smithy.rustType class TypeConversionGenerator(private val model: Model, private val symbolProvider: RustSymbolProvider, private val runtimeConfig: RuntimeConfig) { private fun findOldSymbol(shape: Shape): Symbol { return when (shape) { - is BlobShape -> RuntimeType.Blob(runtimeConfig).toSymbol() - is TimestampShape -> RuntimeType.DateTime(runtimeConfig).toSymbol() + is BlobShape -> RuntimeType.blob(runtimeConfig).toSymbol() + is TimestampShape -> RuntimeType.dateTime(runtimeConfig).toSymbol() else -> symbolProvider.toSymbol(shape) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt index 8278191340..d15edc7e88 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt @@ -123,7 +123,7 @@ class CombinedErrorGenerator( private val errors: List, ) { private val runtimeConfig = symbolProvider.config().runtimeConfig - private val genericError = RuntimeType.GenericError(symbolProvider.config().runtimeConfig) + private val genericError = RuntimeType.genericError(symbolProvider.config().runtimeConfig) fun render(writer: RustWriter) { val errorSymbol = RuntimeType("${operationSymbol.name}Error", null, "crate::error") @@ -151,7 +151,7 @@ class CombinedErrorGenerator( /// Additional metadata about the error, including error code, message, and request ID. pub (crate) meta: #T """, - RuntimeType.GenericError(runtimeConfig), + RuntimeType.genericError(runtimeConfig), ) } writer.rust("/// Types of errors that can occur for the `${operationSymbol.name}` operation.") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt index ecdd6ef502..5594230bae 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt @@ -21,23 +21,27 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.MediaTypeTrait import software.amazon.smithy.model.traits.TimestampFormatTrait +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http 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.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.asOptional +import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref import software.amazon.smithy.rust.codegen.core.rustlang.render 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.core.smithy.makeOptional import software.amazon.smithy.rust.codegen.core.smithy.mapRustType @@ -97,9 +101,9 @@ class HttpBindingGenerator( private val model = codegenContext.model private val service = codegenContext.serviceShape private val index = HttpBindingIndex.of(model) - private val headerUtil = runtimeConfig.smithyHttp().member("header") + private val headerUtil = smithyHttp(runtimeConfig).member("header") private val defaultTimestampFormat = TimestampFormatTrait.Format.EPOCH_SECONDS - private val dateTime = RuntimeType.DateTime(runtimeConfig).toSymbol().rustType() + private val dateTime = RuntimeType.dateTime(runtimeConfig).toSymbol().rustType() private val httpSerdeModule = RustModule.private("http_serde") /** @@ -119,15 +123,21 @@ class HttpBindingGenerator( val outputT = symbolProvider.toSymbol(binding.member).makeOptional() val fnName = "deser_header_${fnName(operationShape, binding)}" return RuntimeType.forInlineFun(fnName, httpSerdeModule) { - rustBlock( - "pub fn $fnName(header_map: &#T::HeaderMap) -> std::result::Result<#T, #T::ParseError>", - RuntimeType.http, - outputT, - headerUtil, - ) { - rust("let headers = header_map.get_all(${binding.locationName.dq()}).iter();") - deserializeFromHeader(model.expectShape(binding.member.target), binding.member) - } + rustTemplate( + """ + pub fn $fnName(header_map: &#{HeaderMap}) -> std::result::Result<#{Output}, #{ParseError}> { + let headers = header_map.get_all(${binding.locationName.dq()}).iter(); + #{deserializeFromHeader:W} + } + """, + "HeaderMap" to Http.asType().member("HeaderMap"), + "Output" to outputT, + "ParseError" to smithyHttp(runtimeConfig).member("header::ParseError"), + "deserializeFromHeader" to deserializeFromHeader( + model.expectShape(binding.member.target), + binding.member, + ), + ) } } @@ -139,37 +149,43 @@ class HttpBindingGenerator( check(target is MapShape) val fnName = "deser_prefix_header_${fnName(operationShape, binding)}" val inner = RuntimeType.forInlineFun("${fnName}_inner", httpSerdeModule) { - rustBlock( - "pub fn ${fnName}_inner(headers: #T::header::ValueIter) -> std::result::Result, #T::ParseError>", - RuntimeType.http, - symbolProvider.toSymbol(model.expectShape(target.value.target)), - headerUtil, - ) { - deserializeFromHeader(model.expectShape(target.value.target), binding.member) - } + rustTemplate( + """ + pub fn ${fnName}_inner(headers: #{ValueIter}) -> std::result::Result, #{ParseError}> { + #{deserializeFromHeader:W} + } + """, + "ValueIter" to Http.asType().member("header::ValueIter"), + "HeaderValue" to Http.asType().member("HeaderValue"), + "Output" to symbolProvider.toSymbol(model.expectShape(target.value.target)), + "ParseError" to smithyHttp(runtimeConfig).member("header::ParseError"), + "deserializeFromHeader" to deserializeFromHeader( + model.expectShape(target.value.target), + binding.member, + ), + ) } - val returnTypeSymbol = outputSymbol.mapRustType { it.asOptional() } + return RuntimeType.forInlineFun(fnName, httpSerdeModule) { - rustBlock( - "pub fn $fnName(header_map: &#T::HeaderMap) -> std::result::Result<#T, #T::ParseError>", - RuntimeType.http, - returnTypeSymbol, - headerUtil, - ) { - rust( - """ - let headers = #T::headers_for_prefix(header_map, ${binding.locationName.dq()}); + rustTemplate( + """ + pub fn $fnName(header_map: &#{HeaderMap}) -> std::result::Result<#{Output}, #{ParseError}> { + let headers = #{headers_for_prefix}(header_map, ${binding.locationName.dq()}); let out: std::result::Result<_, _> = headers.map(|(key, header_name)| { let values = header_map.get_all(header_name); - #T(values.iter()).map(|v| (key.to_string(), v.expect( + #{inner}(values.iter()).map(|v| (key.to_string(), v.expect( "we have checked there is at least one value for this header name; please file a bug report under https://github.com/awslabs/smithy-rs/issues "))) }).collect(); out.map(Some) - """, - headerUtil, inner, - ) - } + } + """, + "HeaderMap" to Http.asType().member("HeaderMap"), + "Output" to outputSymbol.mapRustType { it.asOptional() }, + "ParseError" to smithyHttp(runtimeConfig).member("header::ParseError"), + "headers_for_prefix" to smithyHttp(runtimeConfig).member("header::headers_for_prefix"), + "inner" to inner, + ) } } @@ -190,7 +206,7 @@ class HttpBindingGenerator( val outputT = symbolProvider.toSymbol(binding.member) rustBlock( "pub fn $fnName(body: &mut #T) -> std::result::Result<#T, #T>", - runtimeConfig.smithyHttp().member("body::SdkBody"), + smithyHttp(runtimeConfig).member("body::SdkBody"), outputT, errorT, ) { @@ -234,7 +250,7 @@ class HttpBindingGenerator( let body = std::mem::replace(body, #{SdkBody}::taken()); Ok(#{Receiver}::new(unmarshaller, body)) """, - "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), + "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), "unmarshallerConstructorFn" to unmarshallerConstructorFn, "Receiver" to RuntimeType.eventStreamReceiver(runtimeConfig), ) @@ -250,7 +266,7 @@ class HttpBindingGenerator( let body = std::mem::replace(body, #{SdkBody}::taken()); Ok(#{ByteStream}::new(body)) """, - "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), + "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), "ByteStream" to symbolProvider.toSymbol(member), ) } @@ -276,6 +292,7 @@ class HttpBindingGenerator( "error_symbol" to errorSymbol, ) } + HttpMessageType.REQUEST -> { rust("let body_str = std::str::from_utf8(body)?;") } @@ -296,6 +313,7 @@ class HttpBindingGenerator( rust("Ok(body_str.to_string())") } } + is BlobShape -> rust( "Ok(#T::new(body))", symbolProvider.toSymbol(targetShape), @@ -313,82 +331,85 @@ class HttpBindingGenerator( * Parse a value from a header. * This function produces an expression which produces the precise type required by the target shape. */ - private fun RustWriter.deserializeFromHeader(targetType: Shape, memberShape: MemberShape) { + private fun deserializeFromHeader(targetType: Shape, memberShape: MemberShape): Writable { val rustType = symbolProvider.toSymbol(targetType).rustType().stripOuter() // Normally, we go through a flow that looks for `,`s but that's wrong if the output // is just a single string (which might include `,`s.). // MediaType doesn't include `,` since it's base64, send that through the normal path if (targetType is StringShape && !targetType.hasTrait()) { - rust("#T::one_or_none(headers)", headerUtil) - return + return writable { rust("#T::one_or_none(headers)", headerUtil) } } - val (coreType, coreShape) = if (targetType is CollectionShape) { - rustType.stripOuter() to model.expectShape(targetType.member.target) - } else { - rustType to targetType - } - val parsedValue = safeName() - if (coreType == dateTime) { - val timestampFormat = - index.determineTimestampFormat( - memberShape, - HttpBinding.Location.HEADER, - defaultTimestampFormat, + + return writable { + val (coreType, coreShape) = if (targetType is CollectionShape) { + rustType.stripOuter() to model.expectShape(targetType.member.target) + } else { + rustType to targetType + } + val parsedValue = safeName() + if (coreType == dateTime) { + val timestampFormat = + index.determineTimestampFormat( + memberShape, + HttpBinding.Location.HEADER, + defaultTimestampFormat, + ) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) + rust( + "let $parsedValue: Vec<${coreType.render(true)}> = #T::many_dates(headers, #T)?;", + headerUtil, + timestampFormatType, ) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) - rust( - "let $parsedValue: Vec<${coreType.render(true)}> = #T::many_dates(headers, #T)?;", - headerUtil, - timestampFormatType, - ) - } else if (coreShape.isPrimitive()) { - rust( - "let $parsedValue = #T::read_many_primitive::<${coreType.render(fullyQualified = true)}>(headers)?;", - headerUtil, - ) - } else { - rust( - "let $parsedValue: Vec<${coreType.render(fullyQualified = true)}> = #T::read_many_from_str(headers)?;", - headerUtil, - ) - if (coreShape.hasTrait()) { - rustTemplate( - """ + } else if (coreShape.isPrimitive()) { + rust( + "let $parsedValue = #T::read_many_primitive::<${coreType.render(fullyQualified = true)}>(headers)?;", + headerUtil, + ) + } else { + rust( + "let $parsedValue: Vec<${coreType.render(fullyQualified = true)}> = #T::read_many_from_str(headers)?;", + headerUtil, + ) + if (coreShape.hasTrait()) { + rustTemplate( + """ let $parsedValue: std::result::Result, _> = $parsedValue .iter().map(|s| #{base_64_decode}(s).map_err(|_|#{header}::ParseError::new_with_message("failed to decode base64")) .and_then(|bytes|String::from_utf8(bytes).map_err(|_|#{header}::ParseError::new_with_message("base64 encoded data was not valid utf-8"))) ).collect(); """, - "base_64_decode" to RuntimeType.Base64Decode(runtimeConfig), - "header" to headerUtil, - ) - rust("let $parsedValue = $parsedValue?;") + "base_64_decode" to RuntimeType.base64Decode(runtimeConfig), + "header" to headerUtil, + ) + rust("let $parsedValue = $parsedValue?;") + } } - } - when (rustType) { - is RustType.Vec -> - rust( - """ + when (rustType) { + is RustType.Vec -> + rust( + """ Ok(if !$parsedValue.is_empty() { Some($parsedValue) } else { None }) """, - ) - is RustType.HashSet -> - rust( - """ + ) + + is RustType.HashSet -> + rust( + """ Ok(if !$parsedValue.is_empty() { Some($parsedValue.into_iter().collect()) } else { None }) """, - ) - else -> rustTemplate( - """ + ) + + else -> rustTemplate( + """ if $parsedValue.len() > 1 { Err(#{header_util}::ParseError::new_with_message(format!("expected one item but found {}", $parsedValue.len()))) } else { @@ -396,8 +417,9 @@ class HttpBindingGenerator( Ok($parsedValue.pop()) } """, - "header_util" to headerUtil, - ) + "header_util" to headerUtil, + ) + } } } @@ -406,7 +428,9 @@ class HttpBindingGenerator( */ // Rename here technically not required, operations and members cannot be renamed. private fun fnName(operationShape: OperationShape, binding: HttpBindingDescriptor) = - "${operationShape.id.getName(service).toSnakeCase()}_${binding.member.container.name.toSnakeCase()}_${binding.memberName.toSnakeCase()}" + "${ + operationShape.id.getName(service).toSnakeCase() + }_${binding.member.container.name.toSnakeCase()}_${binding.memberName.toSnakeCase()}" /** * Returns a function to set headers on an HTTP message for the given [shape]. @@ -424,6 +448,7 @@ class HttpBindingGenerator( // Only a single structure member can be bound by `httpPrefixHeaders`, hence the `getOrNull(0)`. HttpMessageType.REQUEST -> index.getRequestBindings(shape, HttpLocation.HEADER) to index.getRequestBindings(shape, HttpLocation.PREFIX_HEADERS).getOrNull(0) + HttpMessageType.RESPONSE -> index.getResponseBindings(shape, HttpLocation.HEADER) to index.getResponseBindings(shape, HttpLocation.PREFIX_HEADERS).getOrNull(0) } @@ -448,8 +473,8 @@ class HttpBindingGenerator( ) val codegenScope = arrayOf( "BuildError" to runtimeConfig.operationBuildError(), - HttpMessageType.REQUEST.name to RuntimeType.HttpRequestBuilder, - HttpMessageType.RESPONSE.name to RuntimeType.HttpResponseBuilder, + HttpMessageType.REQUEST.name to Http.asType().member("request::Builder"), + HttpMessageType.RESPONSE.name to Http.asType().member("response::Builder"), "Shape" to shapeSymbol, ) rustBlockTemplate( @@ -482,8 +507,10 @@ class HttpBindingGenerator( listForEach(targetShape, field) { innerField, targetId -> val innerMemberType = model.expectShape(targetId) if (innerMemberType.isPrimitive()) { - val encoder = runtimeConfig.smithyTypes().member("primitive::Encoder") - rust("let mut encoder = #T::from(${autoDeref(innerField)});", encoder) + rust( + "let mut encoder = #T::from(${autoDeref(innerField)});", + smithyTypes(runtimeConfig).member("primitive::Encoder"), + ) } val formatted = headerFmtFun(this, innerMemberType, memberShape, innerField, isListHeader) val safeName = safeName("formatted") @@ -549,7 +576,13 @@ class HttpBindingGenerator( /** * Format [member] when used as an HTTP header. */ - private fun headerFmtFun(writer: RustWriter, target: Shape, member: MemberShape, targetName: String, isListHeader: Boolean): String { + private fun headerFmtFun( + writer: RustWriter, + target: Shape, + member: MemberShape, + targetName: String, + isListHeader: Boolean, + ): String { fun quoteValue(value: String): String { // Timestamp shapes are not quoted in header lists return if (isListHeader && !target.isTimestampShape) { @@ -562,24 +595,28 @@ class HttpBindingGenerator( return when { target.isStringShape -> { if (target.hasTrait()) { - val func = writer.format(RuntimeType.Base64Encode(runtimeConfig)) + val func = writer.format(RuntimeType.base64Encode(runtimeConfig)) "$func(&$targetName)" } else { quoteValue("AsRef::::as_ref($targetName)") } } + target.isTimestampShape -> { val timestampFormat = index.determineTimestampFormat(member, HttpBinding.Location.HEADER, defaultTimestampFormat) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) quoteValue("$targetName.fmt(${writer.format(timestampFormatType)})?") } + target.isListShape || target.isMemberShape -> { throw IllegalArgumentException("lists should be handled at a higher level") } + target.isPrimitive() -> { "encoder.encode()" } + else -> throw CodegenException("unexpected shape: $target") } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt index 5679bcb660..7243f306cd 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt @@ -14,14 +14,16 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref 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.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.generators.OperationBuildError import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.core.smithy.isOptional @@ -48,7 +50,7 @@ fun SmithyPattern.rustFormatString(prefix: String, separator: String): String { * Generates methods to serialize and deserialize requests based on the HTTP trait. Specifically: * 1. `fn update_http_request(builder: http::request::Builder) -> Builder` * - * This method takes a builder (perhaps pre configured with some headers) from the caller and sets the HTTP + * This method takes a builder (perhaps pre-configured with some headers) from the caller and sets the HTTP * headers & URL based on the HTTP trait implementation. */ class RequestBindingGenerator( @@ -63,11 +65,11 @@ class RequestBindingGenerator( private val httpTrait = protocol.httpBindingResolver.httpTrait(operationShape) private val httpBindingGenerator = HttpBindingGenerator(protocol, codegenContext, operationShape) private val index = HttpBindingIndex.of(model) - private val Encoder = runtimeConfig.smithyTypes().member("primitive::Encoder") + private val Encoder = smithyTypes(runtimeConfig).member("primitive::Encoder") private val codegenScope = arrayOf( "BuildError" to runtimeConfig.operationBuildError(), - "HttpRequestBuilder" to RuntimeType.HttpRequestBuilder, + "HttpRequestBuilder" to Http.asType().member("request::Builder"), "Input" to symbolProvider.toSymbol(inputShape), ) @@ -89,20 +91,15 @@ class RequestBindingGenerator( """, *codegenScope, ) { - write("let mut uri = String::new();") - write("uri_base(input, &mut uri)?;") + rust("let mut uri = String::new();") + rust("uri_base(input, &mut uri)?;") if (hasQuery) { - write("uri_query(input, &mut uri)?;") + rust("uri_query(input, &mut uri)?;") } if (addHeadersFn != null) { - rust( - """ - let builder = #{T}(input, builder)?; - """.trimIndent(), - addHeadersFn, - ) + rust("let builder = #{T}(input, builder)?;", addHeadersFn) } - write("Ok(builder.method(${httpTrait.method.dq()}).uri(uri))") + rust("Ok(builder.method(${httpTrait.method.dq()}).uri(uri))") } } @@ -120,7 +117,7 @@ class RequestBindingGenerator( "${label.content} = ${local(member)}" } val combinedArgs = listOf(formatString, *args.toTypedArray()) - writer.addImport(RuntimeType.stdfmt.member("Write").toSymbol(), null) + writer.addImport(RuntimeType.stdFmt.member("Write").toSymbol(), null) writer.rustBlockTemplate( "fn uri_base(_input: &#{Input}, output: &mut String) -> Result<(), #{BuildError}>", *codegenScope, @@ -163,7 +160,7 @@ class RequestBindingGenerator( "fn uri_query(_input: &#{Input}, mut output: &mut String) -> Result<(), #{BuildError}>", *codegenScope, ) { - write("let mut query = #T::new(&mut output);", RuntimeType.QueryFormat(runtimeConfig, "Writer")) + write("let mut query = #T::new(&mut output);", RuntimeType.queryFormat(runtimeConfig, "Writer")) literalParams.forEach { (k, v) -> // When `v` is an empty string, no value should be set. // this generates a query string like `?k=v&xyz` @@ -182,7 +179,7 @@ class RequestBindingGenerator( val memberSymbol = symbolProvider.toSymbol(memberShape) val memberName = symbolProvider.toMemberName(memberShape) val targetShape = model.expectShape(memberShape.target, MapShape::class.java) - val stringFormatter = RuntimeType.QueryFormat(runtimeConfig, "fmt_string") + val stringFormatter = RuntimeType.queryFormat(runtimeConfig, "fmt_string") ifSet(model.expectShape(param.member.target), memberSymbol, "&_input.$memberName") { field -> rustBlock("for (k, v) in $field") { // if v is a list, generate another level of iteration @@ -223,14 +220,14 @@ class RequestBindingGenerator( private fun paramFmtFun(writer: RustWriter, target: Shape, member: MemberShape, targetName: String): String { return when { target.isStringShape -> { - val func = writer.format(RuntimeType.QueryFormat(runtimeConfig, "fmt_string")) + val func = writer.format(RuntimeType.queryFormat(runtimeConfig, "fmt_string")) "&$func(&$targetName)" } target.isTimestampShape -> { val timestampFormat = index.determineTimestampFormat(member, HttpBinding.Location.QUERY, protocol.defaultTimestampFormat) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) - val func = writer.format(RuntimeType.QueryFormat(runtimeConfig, "fmt_timestamp")) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) + val func = writer.format(RuntimeType.queryFormat(runtimeConfig, "fmt_timestamp")) "&$func($targetName, ${writer.format(timestampFormatType)})?" } target.isListShape || target.isMemberShape -> { @@ -259,19 +256,19 @@ class RequestBindingGenerator( } when { target.isStringShape -> { - val func = format(RuntimeType.LabelFormat(runtimeConfig, "fmt_string")) + val func = format(RuntimeType.labelFormat(runtimeConfig, "fmt_string")) val encodingStrategy = if (label.isGreedyLabel) { - RuntimeType.LabelFormat(runtimeConfig, "EncodingStrategy::Greedy") + RuntimeType.labelFormat(runtimeConfig, "EncodingStrategy::Greedy") } else { - RuntimeType.LabelFormat(runtimeConfig, "EncodingStrategy::Default") + RuntimeType.labelFormat(runtimeConfig, "EncodingStrategy::Default") } rust("let $outputVar = $func($input, #T);", encodingStrategy) } target.isTimestampShape -> { val timestampFormat = index.determineTimestampFormat(member, HttpBinding.Location.LABEL, protocol.defaultTimestampFormat) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) - val func = format(RuntimeType.LabelFormat(runtimeConfig, "fmt_timestamp")) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) + val func = format(RuntimeType.labelFormat(runtimeConfig, "fmt_timestamp")) rust("let $outputVar = $func($input, ${format(timestampFormatType)})?;") } else -> { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt index 209b170416..00ef5c3668 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt @@ -9,16 +9,18 @@ import software.amazon.smithy.aws.traits.ServiceTrait import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +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 import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations @@ -46,7 +48,7 @@ open class MakeOperationGenerator( protected val runtimeConfig = codegenContext.runtimeConfig protected val symbolProvider = codegenContext.symbolProvider protected val httpBindingResolver = protocol.httpBindingResolver - private val defaultClassifier = runtimeConfig.smithyHttp().member("retry::DefaultResponseRetryClassifier") + private val defaultClassifier = smithyHttp(runtimeConfig).member("retry::DefaultResponseRetryClassifier") private val sdkId = codegenContext.serviceShape.getTrait()?.sdkId?.lowercase()?.replace(" ", "") @@ -54,12 +56,12 @@ open class MakeOperationGenerator( private val codegenScope = arrayOf( "config" to RuntimeType.Config, - "header_util" to runtimeConfig.smithyHttp().member("header"), - "http" to RuntimeType.http, - "HttpRequestBuilder" to RuntimeType.HttpRequestBuilder, + "header_util" to smithyHttp(runtimeConfig).member("header"), + "http" to Http.asType(), + "HttpRequestBuilder" to Http.asType().member("request::Builder"), "OpBuildError" to runtimeConfig.operationBuildError(), "operation" to RuntimeType.operationModule(runtimeConfig), - "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), + "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), ) fun generateMakeOperation( @@ -94,7 +96,7 @@ open class MakeOperationGenerator( withBlock("let mut request = {", "};") { createHttpRequest(this, shape) } - rust("let mut properties = #T::new();", runtimeConfig.smithyHttp().member("property_bag::SharedPropertyBag")) + rust("let mut properties = #T::new();", smithyHttp(runtimeConfig).member("property_bag::SharedPropertyBag")) // When the payload is a `ByteStream`, `into_inner()` already returns an `SdkBody`, so we mute this // Clippy warning to make the codegen a little simpler in that case. @@ -170,7 +172,7 @@ open class MakeOperationGenerator( val contentType = httpBindingResolver.requestContentType(operationShape) httpBindingGenerator.renderUpdateHttpBuilder(writer) - writer.rust("let mut builder = update_http_builder(&self, #T::new())?;", RuntimeType.HttpRequestBuilder) + writer.rust("let mut builder = update_http_builder(&self, #T::new())?;", Http.asType().member("request::Builder")) if (includeDefaultPayloadHeaders && contentType != null) { writer.rustTemplate( "builder = #{header_util}::set_request_header_if_absent(builder, #{http}::header::CONTENT_TYPE, ${contentType.dq()});", diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt index 07792aa3f6..564f293952 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt @@ -12,13 +12,16 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ToShapeId import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp -import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyJson import software.amazon.smithy.rust.codegen.core.smithy.generators.serializationError import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.JsonParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator @@ -83,7 +86,7 @@ class AwsJsonSerializerGenerator( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "Error" to runtimeConfig.serializationError(), - "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), + "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), ) override fun operationInputSerializer(operationShape: OperationShape): RuntimeType { @@ -110,11 +113,11 @@ open class AwsJson( ) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( - "Bytes" to RuntimeType.Bytes, - "Error" to RuntimeType.GenericError(runtimeConfig), - "HeaderMap" to RuntimeType.http.member("HeaderMap"), - "JsonError" to runtimeConfig.smithyJson().member("deserialize::Error"), - "Response" to RuntimeType.http.member("Response"), + "Bytes" to Bytes.asType().member("Bytes"), + "Error" to RuntimeType.genericError(runtimeConfig), + "HeaderMap" to Http.asType().member("HeaderMap"), + "JsonError" to smithyJson(runtimeConfig).member("deserialize::Error"), + "Response" to Http.asType().member("Response"), "json_errors" to RuntimeType.jsonErrors(runtimeConfig), ) private val jsonDeserModule = RustModule.private("json_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt index 50d407a108..d46424a198 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt @@ -12,12 +12,15 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ToShapeId import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.AwsQueryParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.AwsQuerySerializerGenerator @@ -42,11 +45,11 @@ class AwsQueryProtocol(private val codegenContext: CodegenContext) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val awsQueryErrors: RuntimeType = RuntimeType.wrappedXmlErrors(runtimeConfig) private val errorScope = arrayOf( - "Bytes" to RuntimeType.Bytes, - "Error" to RuntimeType.GenericError(runtimeConfig), - "HeaderMap" to RuntimeType.http.member("HeaderMap"), - "Response" to RuntimeType.http.member("Response"), - "XmlError" to runtimeConfig.smithyXml().member("decode::XmlError"), + "Bytes" to Bytes.asType().member("Bytes"), + "Error" to RuntimeType.genericError(runtimeConfig), + "HeaderMap" to Http.asType().member("HeaderMap"), + "Response" to Http.asType().member("Response"), + "XmlError" to smithyXml(runtimeConfig).member("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt index 1fcea534a1..84f1c029b2 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt @@ -9,12 +9,15 @@ import software.amazon.smithy.model.pattern.UriPattern import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.Ec2QueryParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.Ec2QuerySerializerGenerator @@ -24,11 +27,11 @@ class Ec2QueryProtocol(private val codegenContext: CodegenContext) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val ec2QueryErrors: RuntimeType = RuntimeType.ec2QueryErrors(runtimeConfig) private val errorScope = arrayOf( - "Bytes" to RuntimeType.Bytes, - "Error" to RuntimeType.GenericError(runtimeConfig), - "HeaderMap" to RuntimeType.http.member("HeaderMap"), - "Response" to RuntimeType.http.member("Response"), - "XmlError" to runtimeConfig.smithyXml().member("decode::XmlError"), + "Bytes" to Bytes.asType().member("Bytes"), + "Error" to RuntimeType.genericError(runtimeConfig), + "HeaderMap" to Http.asType().member("HeaderMap"), + "Response" to Http.asType().member("Response"), + "XmlError" to smithyXml(runtimeConfig).member("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt index 71dfbe7139..c25243b1a0 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt @@ -21,13 +21,13 @@ import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyEventStream -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyEventstream +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.generators.http.HttpMessageType import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolPayloadGenerator @@ -60,10 +60,10 @@ class HttpBoundProtocolPayloadGenerator( private val operationSerModule = RustModule.private("operation_ser") private val codegenScope = arrayOf( "hyper" to CargoDependency.HyperWithStream.asType(), - "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), + "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), "BuildError" to runtimeConfig.operationBuildError(), - "SmithyHttp" to runtimeConfig.smithyHttp(), - "NoOpSigner" to runtimeConfig.smithyEventStream().member("frame::NoOpSigner"), + "SmithyHttp" to smithyHttp(runtimeConfig), + "NoOpSigner" to smithyEventstream(runtimeConfig).member("frame::NoOpSigner"), ) override fun payloadMetadata(operationShape: OperationShape): ProtocolPayloadGenerator.PayloadMetadata { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt index 8b9f682d4d..d153d4cf77 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt @@ -14,11 +14,14 @@ import software.amazon.smithy.model.traits.JsonNameTrait import software.amazon.smithy.model.traits.MediaTypeTrait import software.amazon.smithy.model.traits.StreamingTrait import software.amazon.smithy.model.traits.TimestampFormatTrait +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyJson import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.JsonParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonSerializerGenerator @@ -63,11 +66,11 @@ class RestJsonHttpBindingResolver( open class RestJson(val codegenContext: CodegenContext) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( - "Bytes" to RuntimeType.Bytes, - "Error" to RuntimeType.GenericError(runtimeConfig), - "HeaderMap" to RuntimeType.http.member("HeaderMap"), - "JsonError" to runtimeConfig.smithyJson().member("deserialize::Error"), - "Response" to RuntimeType.http.member("Response"), + "Bytes" to Bytes.asType().member("Bytes"), + "Error" to RuntimeType.genericError(runtimeConfig), + "HeaderMap" to Http.asType().member("HeaderMap"), + "JsonError" to smithyJson(runtimeConfig).member("deserialize::Error"), + "Response" to Http.asType().member("Response"), "json_errors" to RuntimeType.jsonErrors(runtimeConfig), ) private val jsonDeserModule = RustModule.private("json_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt index 327b0885c4..48bf4877fe 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt @@ -8,12 +8,15 @@ package software.amazon.smithy.rust.codegen.core.smithy.protocols import software.amazon.smithy.aws.traits.protocols.RestXmlTrait import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.TimestampFormatTrait +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.RestXmlParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator @@ -24,11 +27,11 @@ open class RestXml(val codegenContext: CodegenContext) : Protocol { private val restXml = codegenContext.serviceShape.expectTrait() private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( - "Bytes" to RuntimeType.Bytes, - "Error" to RuntimeType.GenericError(runtimeConfig), - "HeaderMap" to RuntimeType.http.member("HeaderMap"), - "Response" to RuntimeType.http.member("Response"), - "XmlError" to runtimeConfig.smithyXml().member("decode::XmlError"), + "Bytes" to Bytes.asType().member("Bytes"), + "Error" to RuntimeType.genericError(runtimeConfig), + "HeaderMap" to Http.asType().member("HeaderMap"), + "Response" to Http.asType().member("Response"), + "XmlError" to smithyXml(runtimeConfig).member("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt index 41f1c04885..9578a604b5 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt @@ -30,12 +30,12 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyEventStream -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyEventstream +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.error.eventStreamErrorSymbol @@ -59,23 +59,23 @@ class EventStreamUnmarshallerGenerator( ) { private val unionSymbol = symbolProvider.toSymbol(unionShape) private val errorSymbol = if (target == CodegenTarget.SERVER && unionShape.eventStreamErrors().isEmpty()) { - runtimeConfig.smithyEventStream().member("event_stream::MessageStreamError").toSymbol() + smithyEventstream(runtimeConfig).member("event_stream::MessageStreamError").toSymbol() } else { unionShape.eventStreamErrorSymbol(model, symbolProvider, target).toSymbol() } private val eventStreamSerdeModule = RustModule.private("event_stream_serde") private val codegenScope = arrayOf( - "Blob" to runtimeConfig.smithyTypes().member("Blob"), - "Error" to runtimeConfig.smithyEventStream().member("error::Error"), - "expect_fns" to runtimeConfig.smithyEventStream().member("smithy"), - "Header" to runtimeConfig.smithyEventStream().member("frame::Header"), - "HeaderValue" to runtimeConfig.smithyEventStream().member("frame::HeaderValue"), - "Message" to runtimeConfig.smithyEventStream().member("frame::Message"), + "Blob" to smithyTypes(runtimeConfig).member("Blob"), + "Error" to smithyEventstream(runtimeConfig).member("error::Error"), + "expect_fns" to smithyEventstream(runtimeConfig).member("smithy"), + "Header" to smithyEventstream(runtimeConfig).member("frame::Header"), + "HeaderValue" to smithyEventstream(runtimeConfig).member("frame::HeaderValue"), + "Message" to smithyEventstream(runtimeConfig).member("frame::Message"), "OpError" to errorSymbol, - "SmithyError" to runtimeConfig.smithyTypes().member("Error"), + "SmithyError" to smithyTypes(runtimeConfig).member("Error"), "tracing" to CargoDependency.Tracing.asType(), - "UnmarshalledMessage" to runtimeConfig.smithyEventStream().member("frame::UnmarshalledMessage"), - "UnmarshallMessage" to runtimeConfig.smithyEventStream().member("frame::UnmarshallMessage"), + "UnmarshalledMessage" to smithyEventstream(runtimeConfig).member("frame::UnmarshalledMessage"), + "UnmarshallMessage" to smithyEventstream(runtimeConfig).member("frame::UnmarshallMessage"), ) fun render(): RuntimeType { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt index cb11209463..4176fd8e37 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt @@ -29,12 +29,12 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyJson import software.amazon.smithy.rust.codegen.core.smithy.canUseDefault import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.TypeConversionGenerator @@ -63,7 +63,7 @@ class JsonParserGenerator( private val symbolProvider = codegenContext.symbolProvider private val runtimeConfig = codegenContext.runtimeConfig private val target = codegenContext.target - private val smithyJsonDeser = runtimeConfig.smithyJson().member("deserialize") + private val smithyJsonDeser = smithyJson(runtimeConfig).member("deserialize") private val jsonDeserModule = RustModule.private("json_deser") private val typeConversionGenerator = TypeConversionGenerator(model, symbolProvider, runtimeConfig) private val codegenScope = arrayOf( @@ -300,7 +300,7 @@ class JsonParserGenerator( member, HttpLocation.DOCUMENT, TimestampFormatTrait.Format.EPOCH_SECONDS, ) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) rustTemplate( "#{expect_timestamp_or_null}(tokens.next(), #{T})?#{ConvertFrom:W}", "T" to timestampFormatType, "ConvertFrom" to typeConversionGenerator.convertViaFrom(shape), *codegenScope, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt index 79aa24c28b..215276901a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt @@ -34,13 +34,13 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes -import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.builderSymbol @@ -97,15 +97,15 @@ class XmlBindingTraitParserGenerator( private val symbolProvider = codegenContext.symbolProvider private val runtimeConfig = codegenContext.runtimeConfig - private val xmlError = runtimeConfig.smithyXml().member("decode::XmlError") + private val xmlError = smithyXml(runtimeConfig).member("decode::XmlError") private val codegenScope = arrayOf( - "Blob" to RuntimeType.Blob(runtimeConfig), - "Document" to runtimeConfig.smithyXml().member("decode::Document"), + "Blob" to RuntimeType.blob(runtimeConfig), + "Document" to smithyXml(runtimeConfig).member("decode::Document"), "XmlError" to xmlError, - "next_start_element" to runtimeConfig.smithyXml().member("decode::next_start_element"), - "try_data" to runtimeConfig.smithyXml().member("decode::try_data"), - "ScopedDecoder" to runtimeConfig.smithyXml().member("decode::ScopedDecoder"), - "aws_smithy_types" to runtimeConfig.smithyTypes(), + "next_start_element" to smithyXml(runtimeConfig).member("decode::next_start_element"), + "try_data" to smithyXml(runtimeConfig).member("decode::try_data"), + "ScopedDecoder" to smithyXml(runtimeConfig).member("decode::ScopedDecoder"), + "aws_smithy_types" to smithyTypes(runtimeConfig), ) private val model = codegenContext.model private val index = HttpBindingIndex.of(model) @@ -628,8 +628,8 @@ class XmlBindingTraitParserGenerator( HttpBinding.Location.DOCUMENT, TimestampFormatTrait.Format.DATE_TIME, ) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) - withBlock("#T::from_str(", ")", RuntimeType.DateTime(runtimeConfig)) { + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) + withBlock("#T::from_str(", ")", RuntimeType.dateTime(runtimeConfig)) { provider() rust(", #T", timestampFormatType) } @@ -639,7 +639,7 @@ class XmlBindingTraitParserGenerator( ) } is BlobShape -> { - withBlock("#T(", ")", RuntimeType.Base64Decode(runtimeConfig)) { + withBlock("#T(", ")", RuntimeType.base64Decode(runtimeConfig)) { provider() } rustTemplate( diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt index e515e9c3fd..604e5eee9d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt @@ -21,10 +21,10 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyEventStream import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyEventstream import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.generators.error.eventStreamErrorSymbol import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant @@ -46,7 +46,7 @@ class EventStreamErrorMarshallerGenerator( private val serializerGenerator: StructuredDataSerializerGenerator, payloadContentType: String, ) : EventStreamMarshallerGenerator(model, target, runtimeConfig, symbolProvider, unionShape, serializerGenerator, payloadContentType) { - private val smithyEventStream = CargoDependency.smithyEventStream(runtimeConfig) + private val smithyEventStream = CargoDependency.smithyEventstream(runtimeConfig) private val operationErrorSymbol = if (target == CodegenTarget.SERVER && unionShape.eventStreamErrors().isEmpty()) { RuntimeType("MessageStreamError", smithyEventStream, "aws_smithy_http::event_stream").toSymbol() } else { @@ -55,11 +55,11 @@ class EventStreamErrorMarshallerGenerator( private val eventStreamSerdeModule = RustModule.private("event_stream_serde") private val errorsShape = unionShape.expectTrait() private val codegenScope = arrayOf( - "MarshallMessage" to runtimeConfig.smithyEventStream().member("frame::MarshallMessage"), - "Message" to runtimeConfig.smithyEventStream().member("frame::Message"), - "Header" to runtimeConfig.smithyEventStream().member("frame::Header"), - "HeaderValue" to runtimeConfig.smithyEventStream().member("frame::HeaderValue"), - "Error" to runtimeConfig.smithyEventStream().member("error::Error"), + "MarshallMessage" to smithyEventstream(runtimeConfig).member("frame::MarshallMessage"), + "Message" to smithyEventstream(runtimeConfig).member("frame::Message"), + "Header" to smithyEventstream(runtimeConfig).member("frame::Header"), + "HeaderValue" to smithyEventstream(runtimeConfig).member("frame::HeaderValue"), + "Error" to smithyEventstream(runtimeConfig).member("error::Error"), ) override fun render(): RuntimeType { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt index dfd6471ce9..714c70d0be 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt @@ -29,11 +29,11 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyEventStream import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyEventstream import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant @@ -55,11 +55,11 @@ open class EventStreamMarshallerGenerator( ) { private val eventStreamSerdeModule = RustModule.private("event_stream_serde") private val codegenScope = arrayOf( - "MarshallMessage" to runtimeConfig.smithyEventStream().member("frame::MarshallMessage"), - "Message" to runtimeConfig.smithyEventStream().member("frame::Message"), - "Header" to runtimeConfig.smithyEventStream().member("frame::Header"), - "HeaderValue" to runtimeConfig.smithyEventStream().member("frame::HeaderValue"), - "Error" to runtimeConfig.smithyEventStream().member("error::Error"), + "MarshallMessage" to smithyEventstream(runtimeConfig).member("frame::MarshallMessage"), + "Message" to smithyEventstream(runtimeConfig).member("frame::Message"), + "Header" to smithyEventstream(runtimeConfig).member("frame::Header"), + "HeaderValue" to smithyEventstream(runtimeConfig).member("frame::HeaderValue"), + "Error" to smithyEventstream(runtimeConfig).member("error::Error"), ) open fun render(): RuntimeType { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt index d7979b2e92..1c143b3160 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt @@ -28,12 +28,12 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp -import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyJson +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.customize.NamedSectionGenerator import software.amazon.smithy.rust.codegen.core.smithy.customize.Section @@ -160,10 +160,10 @@ class JsonSerializerGenerator( private val codegenScope = arrayOf( "ByteSlab" to RuntimeType.ByteSlab, "Error" to runtimeConfig.serializationError(), - "JsonObjectWriter" to runtimeConfig.smithyJson().member("serialize::JsonObjectWriter"), - "JsonValueWriter" to runtimeConfig.smithyJson().member("serialize::JsonValueWriter"), - "Number" to runtimeConfig.smithyTypes().member("Number"), - "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), + "JsonObjectWriter" to smithyJson(runtimeConfig).member("serialize::JsonObjectWriter"), + "JsonValueWriter" to smithyJson(runtimeConfig).member("serialize::JsonValueWriter"), + "Number" to smithyTypes(runtimeConfig).member("Number"), + "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), "String" to RuntimeType.String, ) private val serializerUtil = SerializerUtil(model) @@ -269,7 +269,7 @@ class JsonSerializerGenerator( out.into_bytes() } """, - "Document" to RuntimeType.Document(runtimeConfig), *codegenScope, + "Document" to RuntimeType.document(runtimeConfig), *codegenScope, ) } } @@ -375,12 +375,12 @@ class JsonSerializerGenerator( } is BlobShape -> rust( "$writer.string_unchecked(&#T(${value.asRef()}));", - RuntimeType.Base64Encode(runtimeConfig), + RuntimeType.base64Encode(runtimeConfig), ) is TimestampShape -> { val timestampFormat = httpBindingResolver.timestampFormat(context.shape, HttpLocation.DOCUMENT, EPOCH_SECONDS) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) rustTemplate( "$writer.date_time(${value.asRef()}#{ConvertInto:W}, #{FormatType})?;", "FormatType" to timestampFormatType, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt index 5dda05091b..6d66a48727 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt @@ -28,12 +28,12 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp -import software.amazon.smithy.rust.codegen.core.rustlang.smithyQuery -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyQuery +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant @@ -98,9 +98,9 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct private val codegenScope = arrayOf( "String" to RuntimeType.String, "Error" to serializerError, - "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), - "QueryWriter" to runtimeConfig.smithyQuery().member("QueryWriter"), - "QueryValueWriter" to runtimeConfig.smithyQuery().member("QueryValueWriter"), + "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), + "QueryWriter" to smithyQuery(runtimeConfig).member("QueryWriter"), + "QueryValueWriter" to smithyQuery(runtimeConfig).member("QueryValueWriter"), ) private val operationSerModule = RustModule.private("operation_ser") private val querySerModule = RustModule.private("query_ser") @@ -218,16 +218,16 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct } rust( "$writer.number(##[allow(clippy::useless_conversion)]#T::$numberType((${value.asValue()}).into()));", - runtimeConfig.smithyTypes().member("Number"), + smithyTypes(runtimeConfig).member("Number"), ) } is BlobShape -> rust( "$writer.string(&#T(${value.name}));", - RuntimeType.Base64Encode(runtimeConfig), + RuntimeType.base64Encode(runtimeConfig), ) is TimestampShape -> { val timestampFormat = determineTimestampFormat(context.shape) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) rust("$writer.date_time(${value.name}, #T)?;", timestampFormatType) } is CollectionShape -> serializeCollection(context, Context(writer, context.valueExpression, target)) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt index 8a7bda57a8..d5fc2fdc7b 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt @@ -32,13 +32,13 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes -import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant import software.amazon.smithy.rust.codegen.core.smithy.generators.serializationError @@ -66,9 +66,9 @@ class XmlBindingTraitSerializerGenerator( private val target = codegenContext.target private val codegenScope = arrayOf( - "XmlWriter" to runtimeConfig.smithyXml().member("encode::XmlWriter"), - "ElementWriter" to runtimeConfig.smithyXml().member("encode::ElWriter"), - "SdkBody" to runtimeConfig.smithyHttp().member("body::SdkBody"), + "XmlWriter" to smithyXml(runtimeConfig).member("encode::XmlWriter"), + "ElementWriter" to smithyXml(runtimeConfig).member("encode::ElWriter"), + "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), "Error" to runtimeConfig.serializationError(), ) private val operationSerModule = RustModule.private("operation_ser") @@ -296,10 +296,10 @@ class XmlBindingTraitSerializerGenerator( is BooleanShape, is NumberShape -> { rust( "#T::from(${autoDeref(input)}).encode()", - runtimeConfig.smithyTypes().member("primitive::Encoder"), + smithyTypes(runtimeConfig).member("primitive::Encoder"), ) } - is BlobShape -> rust("#T($input.as_ref()).as_ref()", RuntimeType.Base64Encode(runtimeConfig)) + is BlobShape -> rust("#T($input.as_ref()).as_ref()", RuntimeType.base64Encode(runtimeConfig)) is TimestampShape -> { val timestampFormat = httpBindingResolver.timestampFormat( @@ -307,7 +307,7 @@ class XmlBindingTraitSerializerGenerator( HttpLocation.DOCUMENT, TimestampFormatTrait.Format.DATE_TIME, ) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) rust("$input.fmt(#T)?.as_ref()", timestampFormatType) } else -> TODO(member.toString()) diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt index a721b9ad66..f77fc8d029 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt @@ -14,7 +14,7 @@ import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.SetShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.testutil.compileAndRun import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest @@ -26,7 +26,7 @@ class RustWriterTest { @Test fun `inner modules correctly handle dependencies`() { val sut = RustWriter.forModule("parent") - val requestBuilder = RuntimeType.HttpRequestBuilder + val requestBuilder = Http.asType().member("request::Builder") sut.withModule(RustModule.public("inner")) { rustBlock("fn build(builder: #T)", requestBuilder) { } @@ -155,7 +155,7 @@ class RustWriterTest { sut.rustTemplate( "inner: #{Inner:W}, regular: #{http}", "Inner" to inner, - "http" to CargoDependency.Http.asType().member("foo"), + "http" to Http.asType().member("foo"), ) sut.toString().shouldContain("inner: hello, regular: http::foo") } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt index c9e292cdb7..57b869094e 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt @@ -11,11 +11,12 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.HttpTrait +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http 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.asType 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.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestJson import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer @@ -144,11 +145,11 @@ class RequestBindingGeneratorTest { rustBlock( "pub fn test_request_builder_base(&self) -> Result<#T, #T>", - RuntimeType.HttpRequestBuilder, + Http.asType().member("request::Builder"), TestRuntimeConfig.operationBuildError(), ) { bindingGen.renderUpdateHttpBuilder(this) - rust("let builder = #T::new();", RuntimeType.HttpRequestBuilder) + rust("let builder = #T::new();", Http.asType().member("request::Builder")) rust("update_http_builder(self, builder)") } } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt index 30ac1d70ea..f4c5d95dca 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt @@ -24,7 +24,5 @@ object PythonServerCargoDependency { val Hyper: CargoDependency = CargoDependency("hyper", CratesIo("0.14.12"), features = setOf("server", "http1", "http2", "tcp", "stream")) val NumCpus: CargoDependency = CargoDependency("num_cpus", CratesIo("1.13")) val ParkingLot: CargoDependency = CargoDependency("parking_lot", CratesIo("0.12")) - - fun SmithyHttpServer(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http-server") - fun SmithyHttpServerPython(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http-server-python") + fun smithyHttpServerPython(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http-server-python") } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt index 199d36a52a..660e87a057 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt @@ -16,17 +16,17 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType object PythonServerRuntimeType { fun PySocket(runtimeConfig: RuntimeConfig) = - RuntimeType("PySocket", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python") + RuntimeType("PySocket", PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python") fun Blob(runtimeConfig: RuntimeConfig) = - RuntimeType("Blob", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") + RuntimeType("Blob", PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") fun ByteStream(runtimeConfig: RuntimeConfig) = - RuntimeType("ByteStream", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") + RuntimeType("ByteStream", PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") fun DateTime(runtimeConfig: RuntimeConfig) = - RuntimeType("DateTime", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") + RuntimeType("DateTime", PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") fun PyError(runtimeConfig: RuntimeConfig) = - RuntimeType("Error", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python") + RuntimeType("Error", PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python") } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt index 3cc6945fb3..f81cfed731 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt @@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.generators import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.DocumentationTrait +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http 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.asType @@ -17,7 +18,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.Errors import software.amazon.smithy.rust.codegen.core.smithy.Inputs import software.amazon.smithy.rust.codegen.core.smithy.Outputs -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.outputShape @@ -76,7 +76,7 @@ class PythonApplicationGenerator( private val model = codegenContext.model private val codegenScope = arrayOf( - "SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig).asType(), + "SmithyPython" to PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig).asType(), "SmithyServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "pyo3" to PythonServerCargoDependency.PyO3.asType(), "pyo3_asyncio" to PythonServerCargoDependency.PyO3Asyncio.asType(), @@ -88,7 +88,7 @@ class PythonApplicationGenerator( "hyper" to PythonServerCargoDependency.Hyper.asType(), "HashMap" to RustType.HashMap.RuntimeType, "parking_lot" to PythonServerCargoDependency.ParkingLot.asType(), - "http" to RuntimeType.http, + "http" to Http.asType(), ) fun render(writer: RustWriter) { diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt index 4736719cec..b8b361d04a 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt @@ -26,7 +26,7 @@ class PythonServerModuleGenerator( private val serviceShapes: Set, ) { private val codegenScope = arrayOf( - "SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(codegenContext.runtimeConfig).asType(), + "SmithyPython" to PythonServerCargoDependency.smithyHttpServerPython(codegenContext.runtimeConfig).asType(), "pyo3" to PythonServerCargoDependency.PyO3.asType(), ) private val symbolProvider = codegenContext.symbolProvider diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt index 6290e755b7..27b3d87d30 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt @@ -41,7 +41,7 @@ class PythonServerOperationHandlerGenerator( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( - "SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig).asType(), + "SmithyPython" to PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig).asType(), "SmithyServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "pyo3" to PythonServerCargoDependency.PyO3.asType(), "pyo3_asyncio" to PythonServerCargoDependency.PyO3Asyncio.asType(), diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt index e8c9d01b8a..bdf9432859 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt @@ -17,7 +17,7 @@ import software.amazon.smithy.model.traits.HttpQueryParamsTrait import software.amazon.smithy.model.traits.HttpQueryTrait import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.SensitiveTrait -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.plus @@ -118,7 +118,7 @@ sealed class HeaderSensitivity( ) { private val codegenScope = arrayOf( "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), - "Http" to CargoDependency.Http.asType(), + "Http" to Http.asType(), ) /** The case where `prefixHeaders` value is not sensitive. */ @@ -308,7 +308,7 @@ class ServerHttpSensitivityGenerator( ) { private val codegenScope = arrayOf( "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), - "Http" to CargoDependency.Http.asType(), + "Http" to Http.asType(), ) /** Constructs `StatusCodeSensitivity` of a `Shape` */ diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt index fa8c99ad14..e06437fb53 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt @@ -6,20 +6,21 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.shapes.OperationShape +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol import software.amazon.smithy.rust.codegen.core.smithy.transformers.operationErrors import software.amazon.smithy.rust.codegen.core.util.hasStreamingMember import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.outputShape import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency +import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency.Tower import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpBoundProtocolGenerator @@ -38,13 +39,13 @@ open class ServerOperationHandlerGenerator( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "AsyncTrait" to ServerCargoDependency.AsyncTrait.asType(), - "Tower" to ServerCargoDependency.Tower.asType(), + "Tower" to Tower.asType(), "FuturesUtil" to ServerCargoDependency.FuturesUtil.asType(), - "SmithyHttp" to runtimeConfig.smithyHttp(), + "SmithyHttp" to smithyHttp(runtimeConfig), "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "Phantom" to ServerRuntimeType.Phantom, "ServerOperationHandler" to ServerRuntimeType.OperationHandler(runtimeConfig), - "http" to RuntimeType.http, + "http" to Http.asType(), ) open fun render(writer: RustWriter) { diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt index 90cffc4edd..32293f2efb 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt @@ -62,7 +62,7 @@ class ServerOperationRegistryGenerator( "Router" to ServerRuntimeType.Router(runtimeConfig), "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "ServerOperationHandler" to ServerRuntimeType.OperationHandler(runtimeConfig), - "Tower" to ServerCargoDependency.Tower.asType(), + "Tower" to ServerTower.asType(), "Phantom" to ServerRuntimeType.Phantom, "StdError" to RuntimeType.StdError, "Display" to RuntimeType.Display, diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt index 1458ea8885..899902a2f7 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt @@ -6,7 +6,9 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.knowledge.TopDownIndex -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.HttpBody import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable @@ -20,6 +22,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.util.toPascalCase import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency +import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency.Tower import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol class ServerServiceGeneratorV2( @@ -29,12 +32,12 @@ class ServerServiceGeneratorV2( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( - "Bytes" to CargoDependency.Bytes.asType(), - "Http" to CargoDependency.Http.asType(), - "HttpBody" to CargoDependency.HttpBody.asType(), + "Bytes" to Bytes.asType().member("Bytes"), + "Http" to Http.asType(), + "HttpBody" to HttpBody.asType(), "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), - "Tower" to CargoDependency.Tower.asType(), + "Tower" to Tower.asType(), ) private val model = codegenContext.model private val symbolProvider = codegenContext.symbolProvider diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt index 912b0bc876..549201091b 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt @@ -24,7 +24,10 @@ import software.amazon.smithy.protocoltests.traits.HttpRequestTestsTrait import software.amazon.smithy.protocoltests.traits.HttpResponseTestCase import software.amazon.smithy.protocoltests.traits.HttpResponseTestsTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Hyper +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.PrettyAssertions 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.RustReservedWords @@ -41,6 +44,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.smithy.transformers.allErrors import software.amazon.smithy.rust.codegen.core.testutil.TokioTest @@ -55,6 +59,7 @@ import software.amazon.smithy.rust.codegen.core.util.outputShape import software.amazon.smithy.rust.codegen.core.util.toPascalCase import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency +import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency.Tower import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType import software.amazon.smithy.rust.codegen.server.smithy.generators.serverInstantiator import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpBoundProtocolGenerator @@ -102,14 +107,14 @@ class ServerProtocolTestGenerator( private val instantiator = serverInstantiator(codegenContext) private val codegenScope = arrayOf( - "Bytes" to RuntimeType.Bytes, - "SmithyHttp" to CargoDependency.smithyHttp(codegenContext.runtimeConfig).asType(), - "Http" to CargoDependency.Http.asType(), - "Hyper" to CargoDependency.Hyper.asType(), + "Bytes" to Bytes.asType().member("Bytes"), + "SmithyHttp" to smithyHttp(codegenContext.runtimeConfig), + "Http" to Http.asType(), + "Hyper" to Hyper.asType(), "Tokio" to ServerCargoDependency.TokioDev.asType(), - "Tower" to CargoDependency.Tower.asType(), + "Tower" to Tower.asType(), "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).asType(), - "AssertEq" to CargoDependency.PrettyAssertions.asType().member("assert_eq!"), + "AssertEq" to PrettyAssertions.asType().member("assert_eq!"), "Router" to ServerRuntimeType.Router(codegenContext.runtimeConfig), ) @@ -690,7 +695,7 @@ class ServerProtocolTestGenerator( when (codegenContext.model.expectShape(member.target)) { is DoubleShape, is FloatShape -> { rustWriter.addUseImports( - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "FloatEquals") + RuntimeType.protocolTest(codegenContext.runtimeConfig, "FloatEquals") .toSymbol(), ) rustWriter.rust( @@ -788,8 +793,8 @@ class ServerProtocolTestGenerator( "#T(&body, ${ rustWriter.escape(body).dq() }, #T::from(${(mediaType ?: "unknown").dq()}))", - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "validate_body"), - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "MediaType"), + RuntimeType.protocolTest(codegenContext.runtimeConfig, "validate_body"), + RuntimeType.protocolTest(codegenContext.runtimeConfig, "MediaType"), ) } } @@ -842,7 +847,7 @@ class ServerProtocolTestGenerator( assertOk(rustWriter) { rust( "#T($actualExpression, $variableName)", - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "validate_headers"), + RuntimeType.protocolTest(codegenContext.runtimeConfig, "validate_headers"), ) } } @@ -863,7 +868,7 @@ class ServerProtocolTestGenerator( assertOk(rustWriter) { rustWriter.rust( "#T($actualExpression, $expectedVariableName)", - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, checkFunction), + RuntimeType.protocolTest(codegenContext.runtimeConfig, checkFunction), ) } } @@ -873,7 +878,7 @@ class ServerProtocolTestGenerator( * for pretty printing protocol test helper results */ private fun assertOk(rustWriter: RustWriter, inner: Writable) { - rustWriter.rust("#T(", RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "assert_ok")) + rustWriter.rust("#T(", RuntimeType.protocolTest(codegenContext.runtimeConfig, "assert_ok")) inner(rustWriter) rustWriter.write(");") } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt index 64312be41e..e365d8f482 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt @@ -26,6 +26,7 @@ import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.MediaTypeTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http 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.RustWriter @@ -37,15 +38,15 @@ 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.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.smithyHttp -import software.amazon.smithy.rust.codegen.core.rustlang.smithyJson -import software.amazon.smithy.rust.codegen.core.rustlang.smithyTypes -import software.amazon.smithy.rust.codegen.core.rustlang.smithyXml import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyJson +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyTypes +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyXml import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.extractSymbolFromOption import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator @@ -132,10 +133,10 @@ private class ServerHttpBoundProtocolTraitImplGenerator( private val codegenScope = arrayOf( "AsyncTrait" to ServerCargoDependency.AsyncTrait.asType(), "Cow" to ServerRuntimeType.Cow, - "DateTime" to RuntimeType.DateTime(runtimeConfig), + "DateTime" to RuntimeType.dateTime(runtimeConfig), "FormUrlEncoded" to ServerCargoDependency.FormUrlEncoded.asType(), "HttpBody" to CargoDependency.HttpBody.asType(), - "header_util" to runtimeConfig.smithyHttp().member("header"), + "header_util" to smithyHttp(runtimeConfig).member("header"), "Hyper" to CargoDependency.Hyper.asType(), "LazyStatic" to CargoDependency.LazyStatic.asType(), "Mime" to ServerCargoDependency.Mime.asType(), @@ -143,12 +144,12 @@ private class ServerHttpBoundProtocolTraitImplGenerator( "OnceCell" to ServerCargoDependency.OnceCell.asType(), "PercentEncoding" to CargoDependency.PercentEncoding.asType(), "Regex" to CargoDependency.Regex.asType(), - "SmithyHttp" to runtimeConfig.smithyHttp(), + "SmithyHttp" to smithyHttp(runtimeConfig), "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "RuntimeError" to ServerRuntimeType.RuntimeError(runtimeConfig), "RequestRejection" to ServerRuntimeType.RequestRejection(runtimeConfig), "ResponseRejection" to ServerRuntimeType.ResponseRejection(runtimeConfig), - "http" to RuntimeType.http, + "http" to Http.asType(), ) override fun generateTraitImpls(operationWriter: RustWriter, operationShape: OperationShape, customizations: List) { @@ -1022,7 +1023,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( it.location, protocol.defaultTimestampFormat, ) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) rustTemplate( """ let v = #{DateTime}::from_str(&v, #{format})?#{ConvertInto:W}; @@ -1034,10 +1035,8 @@ private class ServerHttpBoundProtocolTraitImplGenerator( } else -> { // Number or boolean. rust( - """ - let v = <_ as #T>::parse_smithy_primitive(&v)?; - """.trimIndent(), - runtimeConfig.smithyTypes().member("primitive::Parse"), + "let v = <_ as #T>::parse_smithy_primitive(&v)?;", + smithyTypes(runtimeConfig).member("primitive::Parse"), ) } } @@ -1158,7 +1157,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( binding.location, protocol.defaultTimestampFormat, ) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) if (percentDecoding) { rustTemplate( @@ -1219,10 +1218,10 @@ private class ServerHttpBoundProtocolTraitImplGenerator( } when (codegenContext.protocol) { RestJson1Trait.ID, AwsJson1_0Trait.ID, AwsJson1_1Trait.ID -> { - return runtimeConfig.smithyJson().member("deserialize").member("Error") + return smithyJson(runtimeConfig).member("deserialize").member("Error") } RestXmlTrait.ID -> { - return runtimeConfig.smithyXml().member("decode").member("XmlError") + return smithyXml(runtimeConfig).member("decode").member("XmlError") } else -> { TODO("Protocol ${codegenContext.protocol} not supported yet") From 840d13a5249aee25af44efa6b182792cd72d9b9a Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Tue, 8 Nov 2022 15:12:22 -0600 Subject: [PATCH 14/19] remove: code that didn't do anything --- .../rustsdk/decorators/IntegrationTestDecorator.kt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt index 9a70a0438e..6760ecfb93 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt @@ -116,19 +116,9 @@ class S3TestDependencies( ) : LibRsCustomization() { override fun section(section: LibRsSection): Writable = writable { - val smithyClient = CargoDependency.smithyClient(runtimeConfig) - .copy(features = setOf("test-util"), scope = DependencyScope.Dev) - val smithyAsync = CargoDependency.smithyAsync(runtimeConfig).copy(scope = DependencyScope.Dev) - val smithyHttp = CargoDependency.smithyHttp(runtimeConfig).copy(scope = DependencyScope.Dev) - val smithyTypes = CargoDependency.smithyTypes(runtimeConfig).copy(scope = DependencyScope.Dev) - addDependency(AsyncStd) addDependency(BytesUtils.copy(scope = DependencyScope.Dev)) addDependency(Smol) addDependency(TempFile) - addDependency(smithyAsync) - addDependency(smithyClient) - addDependency(smithyHttp) - addDependency(smithyTypes) } } From 8d48f5ca18e01ce79b5b2f33c2f333cdd74dd163 Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Wed, 9 Nov 2022 10:54:25 -0600 Subject: [PATCH 15/19] fix: server module missing import --- .../smithy/generators/ServerOperationRegistryGenerator.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt index 32293f2efb..928dc6d396 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt @@ -33,6 +33,7 @@ import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.outputShape import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency +import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency.Tower import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol @@ -62,7 +63,7 @@ class ServerOperationRegistryGenerator( "Router" to ServerRuntimeType.Router(runtimeConfig), "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "ServerOperationHandler" to ServerRuntimeType.OperationHandler(runtimeConfig), - "Tower" to ServerTower.asType(), + "Tower" to Tower.asType(), "Phantom" to ServerRuntimeType.Phantom, "StdError" to RuntimeType.StdError, "Display" to RuntimeType.Display, From f651183f554d96fcf6f0f10ac9f2d88eab511c03 Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Wed, 9 Nov 2022 14:09:23 -0600 Subject: [PATCH 16/19] refactor: simplify RuntimeType update: RuntimeType usage --- .../smithy/rustsdk/AwsRuntimeDependency.kt | 3 +- .../decorators/AwsCombinedCodegenDecorator.kt | 2 +- .../decorators/AwsEndpointDecorator.kt | 36 +++--- .../decorators/AwsFluentClientDecorator.kt | 29 ++--- .../decorators/AwsPresigningDecorator.kt | 19 ++- .../CredentialsProviderDecorator.kt | 10 +- .../HttpRequestChecksumDecorator.kt | 6 +- .../HttpResponseChecksumDecorator.kt | 4 +- .../rustsdk/decorators/RegionDecorator.kt | 4 +- .../rustsdk/decorators/ResiliencyDecorator.kt | 2 +- .../rustsdk/decorators/SdkConfigDecorator.kt | 4 +- .../decorators/SigV4SigningDecorator.kt | 12 +- .../rustsdk/decorators/UserAgentDecorator.kt | 10 +- .../apigateway/ApiGatewayDecorator.kt | 3 +- .../glacier/ApiVersionHeader.kt | 3 +- .../route53/Route53Decorator.kt | 12 +- .../servicedecorators/s3/S3Decorator.kt | 9 +- .../EndpointConfigCustomizationTest.kt | 4 +- .../smithy/EventStreamSymbolProvider.kt | 2 +- .../smithy/StreamingTraitSymbolProvider.kt | 12 +- .../HttpChecksumRequiredGenerator.kt | 3 +- .../HttpVersionListCustomization.kt | 2 +- .../ResiliencyConfigCustomization.kt | 14 +- .../SmithyTypesPubUseGenerator.kt | 6 +- .../NoOpEventStreamSigningDecorator.kt | 2 +- .../EndpointTraitBindingGenerator.kt | 2 +- .../smithy/generators/PaginatorGenerator.kt | 7 +- .../client/CustomizableOperationGenerator.kt | 19 ++- .../client/FluentClientGenerator.kt | 10 +- .../generators/client/FluentClientGenerics.kt | 6 +- .../config/EventStreamSigningConfig.kt | 4 +- .../protocol/ProtocolTestGenerator.kt | 21 ++- .../protocols/HttpBoundProtocolGenerator.kt | 3 +- .../HttpVersionListGeneratorTest.kt | 8 +- .../client/smithy/SymbolVisitorTest.kt | 4 +- .../protocol/ProtocolTestGeneratorTest.kt | 7 +- .../codegen/core/rustlang/CargoDependency.kt | 9 +- .../rust/codegen/core/rustlang/RustType.kt | 14 +- .../rust/codegen/core/smithy/RuntimeType.kt | 121 ++++++++++-------- .../core/smithy/SymbolMetadataProvider.kt | 8 +- .../smithy/generators/BuilderGenerator.kt | 4 +- .../core/smithy/generators/Instantiator.kt | 6 +- .../error/CombinedErrorGenerator.kt | 4 +- .../error/ServerCombinedErrorGenerator.kt | 2 +- .../error/TopLevelErrorGenerator.kt | 3 +- .../generators/http/HttpBindingGenerator.kt | 89 +++++++------ .../http/RequestBindingGenerator.kt | 7 +- .../http/RestRequestSpecGenerator.kt | 7 +- .../protocol/MakeOperationGenerator.kt | 13 +- .../codegen/core/smithy/protocols/AwsJson.kt | 11 +- .../codegen/core/smithy/protocols/AwsQuery.kt | 9 +- .../codegen/core/smithy/protocols/Ec2Query.kt | 9 +- .../HttpBoundProtocolPayloadGenerator.kt | 5 +- .../codegen/core/smithy/protocols/RestJson.kt | 9 +- .../codegen/core/smithy/protocols/RestXml.kt | 9 +- .../parse/EventStreamUnmarshallerGenerator.kt | 23 ++-- .../protocols/parse/JsonParserGenerator.kt | 32 ++--- .../parse/XmlBindingTraitParserGenerator.kt | 10 +- .../EventStreamErrorMarshallerGenerator.kt | 32 ++--- .../EventStreamMarshallerGenerator.kt | 12 +- .../serialize/JsonSerializerGenerator.kt | 8 +- .../serialize/QuerySerializerGenerator.kt | 8 +- .../XmlBindingTraitSerializerGenerator.kt | 8 +- .../rust/codegen/core/testutil/TestHelpers.kt | 1 - .../codegen/core/rustlang/RustGenericsTest.kt | 2 +- .../codegen/core/rustlang/RustWriterTest.kt | 8 +- .../codegen/core/rustlang/WritableTest.kt | 9 +- .../http/RequestBindingGeneratorTest.kt | 5 +- .../generators/PythonApplicationGenerator.kt | 5 +- .../PythonServerCombinedErrorGenerator.kt | 1 - .../generators/PythonServerEnumGenerator.kt | 1 - .../generators/PythonServerModuleGenerator.kt | 1 - .../PythonServerOperationHandlerGenerator.kt | 1 - .../PythonServerStructureGenerator.kt | 1 - .../server/smithy/ServerRuntimeType.kt | 27 ++-- .../ServerHttpSensitivityGenerator.kt | 1 - .../generators/ServerOperationGenerator.kt | 1 - .../ServerOperationHandlerGenerator.kt | 4 +- .../ServerOperationRegistryGenerator.kt | 5 +- .../generators/ServerServiceGeneratorV2.kt | 5 +- .../generators/protocol/ServerProtocol.kt | 33 +++-- .../protocol/ServerProtocolTestGenerator.kt | 7 +- .../ServerHttpBoundProtocolGenerator.kt | 13 +- .../ServerHttpSensitivityGeneratorTest.kt | 1 - .../EventStreamMarshallerGeneratorTest.kt | 8 +- 85 files changed, 443 insertions(+), 473 deletions(-) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt index 9f36c5375e..b76d6c083e 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt @@ -12,7 +12,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Compani import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.smithyHttpTower 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.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType @@ -62,7 +61,7 @@ object AwsRuntimeType { awsRuntimeCrate("aws-http"), awsRuntimeCrate("aws-endpoint"), ), - ).member("DefaultMiddleware") + ).resolve("DefaultMiddleware") } fun RuntimeConfig.awsRuntimeCrate(name: String, features: Set = setOf()): CargoDependency = diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt index 2022543ddc..9e1507c13e 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt @@ -88,7 +88,7 @@ fun generateImplFromRefSdkConfigForConfigBuilder( rustCrate: RustCrate, customizations: List, ) { - val codegenContext = arrayOf("SdkConfig" to awsTypes(runtimeConfig).member("sdk_config::SdkConfig")) + val codegenContext = arrayOf("SdkConfig" to awsTypes(runtimeConfig).resolve("sdk_config::SdkConfig")) rustCrate.withModule(RustModule.Config) { rustBlockTemplate("impl From<&#{SdkConfig}> for Builder", *codegenContext) { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt index af56185065..2c0a85f372 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsEndpointDecorator.kt @@ -106,11 +106,11 @@ class EndpointConfigCustomization( private val runtimeConfig = codegenContext.runtimeConfig private val moduleUseName = codegenContext.moduleUseName() private val codegenScope = arrayOf( - "SmithyResolver" to smithyHttp(runtimeConfig).member("endpoint::ResolveEndpoint"), - "PlaceholderParams" to awsEndpoint(runtimeConfig).member("Params"), - "ResolveAwsEndpoint" to awsEndpoint(runtimeConfig).member("ResolveAwsEndpoint"), - "EndpointShim" to awsEndpoint(runtimeConfig).member("EndpointShim"), - "Region" to awsTypes(runtimeConfig).member("region::Region"), + "SmithyResolver" to smithyHttp(runtimeConfig).resolve("endpoint::ResolveEndpoint"), + "PlaceholderParams" to awsEndpoint(runtimeConfig).resolve("Params"), + "ResolveAwsEndpoint" to awsEndpoint(runtimeConfig).resolve("ResolveAwsEndpoint"), + "EndpointShim" to awsEndpoint(runtimeConfig).resolve("EndpointShim"), + "Region" to awsTypes(runtimeConfig).resolve("region::Region"), ) override fun section(section: ServiceConfig): Writable = writable { @@ -191,8 +191,8 @@ class EndpointConfigCustomization( class EndpointResolverFeature(runtimeConfig: RuntimeConfig) : OperationCustomization() { private val codegenScope = arrayOf( - "PlaceholderParams" to awsEndpoint(runtimeConfig).member("Params"), - "EndpointResult" to smithyHttp(runtimeConfig).member("endpoint::Result"), + "PlaceholderParams" to awsEndpoint(runtimeConfig).resolve("Params"), + "EndpointResult" to smithyHttp(runtimeConfig).resolve("endpoint::Result"), "BuildError" to runtimeConfig.operationBuildError(), ) @@ -223,7 +223,7 @@ class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat is LibRsSection.Body -> writable { rust( "pub use #T;", - smithyHttp(runtimeConfig).member("endpoint::Endpoint"), + smithyHttp(runtimeConfig).resolve("endpoint::Endpoint"), ) } @@ -239,16 +239,16 @@ class EndpointResolverGenerator(codegenContext: CodegenContext, private val endp private val awsTypes = awsTypes(runtimeConfig) private val codegenScope = arrayOf( - "Partition" to awsEndpoint.member("Partition"), - "endpoint" to awsEndpoint.member("partition::endpoint"), - "CredentialScope" to awsEndpoint.member("CredentialScope"), - "Regionalized" to awsEndpoint.member("partition::Regionalized"), - "Protocol" to awsEndpoint.member("partition::endpoint::Protocol"), - "SignatureVersion" to awsEndpoint.member("partition::endpoint::SignatureVersion"), - "PartitionResolver" to awsEndpoint.member("PartitionResolver"), - "ResolveAwsEndpoint" to awsEndpoint.member("ResolveAwsEndpoint"), - "SigningService" to awsTypes.member("SigningService"), - "SigningRegion" to awsTypes.member("region::SigningRegion"), + "Partition" to awsEndpoint.resolve("Partition"), + "endpoint" to awsEndpoint.resolve("partition::endpoint"), + "CredentialScope" to awsEndpoint.resolve("CredentialScope"), + "Regionalized" to awsEndpoint.resolve("partition::Regionalized"), + "Protocol" to awsEndpoint.resolve("partition::endpoint::Protocol"), + "SignatureVersion" to awsEndpoint.resolve("partition::endpoint::SignatureVersion"), + "PartitionResolver" to awsEndpoint.resolve("PartitionResolver"), + "ResolveAwsEndpoint" to awsEndpoint.resolve("ResolveAwsEndpoint"), + "SigningService" to awsTypes.resolve("SigningService"), + "SigningRegion" to awsTypes.resolve("region::SigningRegion"), ) fun resolver(): RuntimeType { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt index 4fc8f04488..7ef36167b7 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt @@ -23,7 +23,6 @@ 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.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate @@ -45,17 +44,17 @@ import software.amazon.smithy.rustsdk.awsRuntimeCrate import software.amazon.smithy.rustsdk.awsTypes private class Types(runtimeConfig: RuntimeConfig) { - val clientBuilder = smithyClient(runtimeConfig).member("Builder") - val connectorError = smithyHttp(runtimeConfig).member("result::ConnectorError") - val connectorSettings = smithyClient(runtimeConfig).member("http_connector::ConnectorSettings") + val clientBuilder = smithyClient(runtimeConfig).resolve("Builder") + val connectorError = smithyHttp(runtimeConfig).resolve("result::ConnectorError") + val connectorSettings = smithyClient(runtimeConfig).resolve("http_connector::ConnectorSettings") val defaultMiddleware = runtimeConfig.defaultMiddleware() - val dynConnector = smithyClient(runtimeConfig).member("erase::DynConnector") - val dynMiddleware = smithyClient(runtimeConfig).member("erase::DynMiddleware") - val retryConfig = smithyTypes(runtimeConfig).member("retry::RetryConfig") - val sdkConfig = awsTypes(runtimeConfig).member("SdkConfig") - val smithyClientRetry = smithyClient(runtimeConfig).member("retry") - val smithyConnector = smithyClient(runtimeConfig).member("bounds::SmithyConnector") - val timeoutConfig = smithyTypes(runtimeConfig).member("timeout::TimeoutConfig") + val dynConnector = smithyClient(runtimeConfig).resolve("erase::DynConnector") + val dynMiddleware = smithyClient(runtimeConfig).resolve("erase::DynMiddleware") + val retryConfig = smithyTypes(runtimeConfig).resolve("retry::RetryConfig") + val sdkConfig = awsTypes(runtimeConfig).resolve("SdkConfig") + val smithyClientRetry = smithyClient(runtimeConfig).resolve("retry") + val smithyConnector = smithyClient(runtimeConfig).resolve("bounds::SmithyConnector") + val timeoutConfig = smithyTypes(runtimeConfig).resolve("timeout::TimeoutConfig") } private class AwsClientGenerics(private val types: Types) : FluentClientGenerics { @@ -103,7 +102,7 @@ class AwsFluentClientDecorator : RustCodegenDecorator writable { rust( "pub use #T;", - awsTypes(runtimeConfig).member("Credentials"), + awsTypes(runtimeConfig).resolve("Credentials"), ) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt index fcc4f5ed6b..315851dae1 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt @@ -106,7 +106,7 @@ private fun HttpChecksumTrait.checksumAlgorithmToStr( }; """, "BuildError" to runtimeConfig.operationBuildError(), - "ChecksumAlgorithm" to smithyChecksums(runtimeConfig).member("ChecksumAlgorithm"), + "ChecksumAlgorithm" to smithyChecksums(runtimeConfig).resolve("ChecksumAlgorithm"), ) // If a request checksum is not required and there's no way to set one, do nothing @@ -139,6 +139,7 @@ class HttpRequestChecksumCustomization( emptySection } } + is OperationSection.MutateRequest -> { // Return early if no request checksum can be set nor is it required if (!checksumTrait.isRequestChecksumRequired && checksumAlgorithm == null) { @@ -161,12 +162,13 @@ class HttpRequestChecksumCustomization( operationShape, ), "add_checksum_calculation_to_request" to runtimeConfig.awsInlineableBodyWithChecksum() - .member("add_checksum_calculation_to_request"), + .resolve("add_checksum_calculation_to_request"), "BuildError" to runtimeConfig.operationBuildError(), ) } } } + else -> { return emptySection } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpResponseChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpResponseChecksumDecorator.kt index 08e473ceb0..44a2efcd25 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpResponseChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpResponseChecksumDecorator.kt @@ -113,8 +113,8 @@ class HttpResponseChecksumCustomization( } """, "ValidationModeShape" to codegenContext.symbolProvider.toSymbol(requestValidationModeMemberInner), - "wrap_body_with_checksum_validator" to codegenContext.runtimeConfig.awsInlineableBodyWithChecksum().member("wrap_body_with_checksum_validator"), - "check_headers_for_precalculated_checksum" to codegenContext.runtimeConfig.awsInlineableBodyWithChecksum().member("check_headers_for_precalculated_checksum"), + "wrap_body_with_checksum_validator" to codegenContext.runtimeConfig.awsInlineableBodyWithChecksum().resolve("wrap_body_with_checksum_validator"), + "check_headers_for_precalculated_checksum" to codegenContext.runtimeConfig.awsInlineableBodyWithChecksum().resolve("check_headers_for_precalculated_checksum"), ) } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt index 3eb0d97761..bebd0e8993 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/RegionDecorator.kt @@ -110,7 +110,7 @@ class RegionDecorator : AwsCodegenDecorator { class RegionProviderConfig(codegenContext: CodegenContext) : ConfigCustomization() { private val runtimeConfig = codegenContext.runtimeConfig private val moduleUseName = codegenContext.moduleUseName() - private val codegenScope = arrayOf("Region" to awsTypes(runtimeConfig).member("region::Region")) + private val codegenScope = arrayOf("Region" to awsTypes(runtimeConfig).resolve("region::Region")) override fun section(section: ServiceConfig) = writable { when (section) { is ServiceConfig.ConfigStruct -> rustTemplate("pub(crate) region: Option<#{Region}>,", *codegenScope) @@ -179,7 +179,7 @@ class PubUseRegion(private val runtimeConfig: RuntimeConfig) : LibRsCustomizatio is LibRsSection.Body -> writable { rust( "pub use #T;", - awsTypes(runtimeConfig).member("region::Region"), + awsTypes(runtimeConfig).resolve("region::Region"), ) } else -> emptySection diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt index f25286d8b6..ac7d08f20e 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/ResiliencyDecorator.kt @@ -45,7 +45,7 @@ class ResiliencyDecorator : AwsCodegenDecorator { } class RetryClassifierFeature(private val runtimeConfig: RuntimeConfig) : OperationCustomization() { - override fun retryType(): RuntimeType = awsHttp(runtimeConfig).member("retry::AwsResponseRetryClassifier") + override fun retryType(): RuntimeType = awsHttp(runtimeConfig).resolve("retry::AwsResponseRetryClassifier") override fun section(section: OperationSection) = when (section) { is OperationSection.FinalizeOperation -> writable { rust( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt index 748fbca715..4efe875a04 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SdkConfigDecorator.kt @@ -45,7 +45,7 @@ class SdkConfigDecorator : RustCodegenDecorator emptySection diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt index ff8fe9626f..f8ebc72b9b 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/SigV4SigningDecorator.kt @@ -87,7 +87,7 @@ class SigV4SigningConfig( private val sigV4Trait: SigV4Trait, ) : EventStreamSigningConfig(runtimeConfig) { private val codegenScope = arrayOf( - "SigV4Signer" to awsSigAuthEventStream(runtimeConfig).member("event_stream::SigV4Signer"), + "SigV4Signer" to awsSigAuthEventStream(runtimeConfig).resolve("event_stream::SigV4Signer"), ) override fun configImplSection(): Writable { @@ -142,11 +142,11 @@ class SigV4SigningFeature( private val service: ServiceShape, ) : OperationCustomization() { private val codegenScope = arrayOf( - "OperationSigningConfig" to awsSigAuth(runtimeConfig).member("signer::OperationSigningConfig"), - "SignableBody" to awsSigAuth(runtimeConfig).member("signer::SignableBody"), - "SigningRegion" to awsTypes(runtimeConfig).member("region::SigningRegion"), - "SigningRequirements" to awsSigAuth(runtimeConfig).member("signer::SigningRequirements"), - "SigningService" to awsTypes(runtimeConfig).member("SigningService"), + "OperationSigningConfig" to awsSigAuth(runtimeConfig).resolve("signer::OperationSigningConfig"), + "SignableBody" to awsSigAuth(runtimeConfig).resolve("signer::SignableBody"), + "SigningRegion" to awsTypes(runtimeConfig).resolve("region::SigningRegion"), + "SigningRequirements" to awsSigAuth(runtimeConfig).resolve("signer::SigningRequirements"), + "SigningService" to awsTypes(runtimeConfig).resolve("SigningService"), ) private val serviceIndex = ServiceIndex.of(model) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt index 42c24a2354..1a427def1d 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt @@ -79,11 +79,11 @@ private class ApiVersionAndPubUse(private val runtimeConfig: RuntimeConfig, serv // PKG_VERSION comes from CrateVersionGenerator rustTemplate( "static API_METADATA: #{ApiMetadata} = #{ApiMetadata}::new(${serviceId.dq()}, PKG_VERSION);", - "ApiMetadata" to awsHttp(runtimeConfig).member("user_agent::ApiMetadata"), + "ApiMetadata" to awsHttp(runtimeConfig).resolve("user_agent::ApiMetadata"), ) // Re-export the app name so that it can be specified in config programmatically without an explicit dependency - rust("pub use #T;", awsTypes(runtimeConfig).member("app_name::AppName")) + rust("pub use #T;", awsTypes(runtimeConfig).resolve("app_name::AppName")) } else -> emptySection } @@ -103,8 +103,8 @@ private class UserAgentFeature(private val runtimeConfig: RuntimeConfig) : Opera } ${section.request}.properties_mut().insert(user_agent); """, - "AwsUserAgent" to awsHttp(runtimeConfig).member("user_agent::AwsUserAgent"), - "Env" to awsTypes(runtimeConfig).member("os_shim_internal::Env"), + "AwsUserAgent" to awsHttp(runtimeConfig).resolve("user_agent::AwsUserAgent"), + "Env" to awsTypes(runtimeConfig).resolve("os_shim_internal::Env"), ) } else -> emptySection @@ -112,7 +112,7 @@ private class UserAgentFeature(private val runtimeConfig: RuntimeConfig) : Opera } private class AppNameCustomization(runtimeConfig: RuntimeConfig) : ConfigCustomization() { - private val codegenScope = arrayOf("AppName" to awsTypes(runtimeConfig).member("app_name::AppName")) + private val codegenScope = arrayOf("AppName" to awsTypes(runtimeConfig).resolve("app_name::AppName")) override fun section(section: ServiceConfig): Writable = when (section) { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt index f52b643055..ad7a751587 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt @@ -12,7 +12,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDe import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -50,7 +49,7 @@ class ApiGatewayAddAcceptHeader : OperationCustomization() { .headers_mut() .insert("Accept", #{HeaderValue}::from_static("application/json")); """, - "HeaderValue" to Http.asType().member("HeaderValue"), + "HeaderValue" to Http.asType().resolve("HeaderValue"), ) } else -> emptySection diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt index 47ac503e5f..c4e0527330 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt @@ -7,7 +7,6 @@ package software.amazon.smithy.rustsdk.servicedecorators.glacier import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization @@ -30,7 +29,7 @@ class ApiVersionHeader( .headers_mut() .insert("x-amz-glacier-version", #{HeaderValue}::from_static(${apiVersion.dq()})); """, - "HeaderValue" to Http.asType().member("HeaderValue"), + "HeaderValue" to Http.asType().resolve("HeaderValue"), ) } else -> emptySection diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/route53/Route53Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/route53/Route53Decorator.kt index e0ccb2a405..9080c103f2 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/route53/Route53Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/route53/Route53Decorator.kt @@ -33,7 +33,8 @@ val Route53: ShapeId = ShapeId.from("com.amazonaws.route53#AWSDnsV20130401") class Route53Decorator : RustCodegenDecorator { override val order: Byte = 0 private val logger: Logger = Logger.getLogger(javaClass.name) - private val resourceShapes = setOf(ShapeId.from("com.amazonaws.route53#ResourceId"), ShapeId.from("com.amazonaws.route53#ChangeId")) + private val resourceShapes = + setOf(ShapeId.from("com.amazonaws.route53#ResourceId"), ShapeId.from("com.amazonaws.route53#ChangeId")) private fun applies(service: ServiceShape) = service.id == Route53 @@ -72,11 +73,9 @@ class TrimResourceIdCustomization(private val fieldName: String) : OperationCust override fun mutSelf(): Boolean = true override fun consumesSelf(): Boolean = true - private val trimResourceId = - RuntimeType.forInlineDependency( - InlineAwsDependency.forRustFile("route53_resource_id_preprocessor"), - ) - .member("trim_resource_id") + private val trimResourceId = RuntimeType.forInlineDependency( + InlineAwsDependency.forRustFile("route53_resource_id_preprocessor"), + ).resolve("trim_resource_id") override fun section(section: OperationSection): Writable { return when (section) { @@ -86,6 +85,7 @@ class TrimResourceIdCustomization(private val fieldName: String) : OperationCust "trim_resource_id" to trimResourceId, ) } + else -> emptySection } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt index b028628212..3c5c02e4da 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt @@ -21,7 +21,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Compani import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate @@ -92,11 +91,11 @@ class S3Decorator : RustCodegenDecorator() diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt index f892103bb7..3de1000edb 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt @@ -20,10 +20,10 @@ class ResiliencyConfigCustomization(codegenContext: CodegenContext) : ConfigCust private val runtimeConfig = codegenContext.runtimeConfig private val moduleUseName = codegenContext.moduleUseName() private val codegenScope = arrayOf( - "AsyncSleep" to smithyAsync(runtimeConfig).member("rt::sleep::AsyncSleep"), - "RetryConfig" to smithyTypes(runtimeConfig).member("retry::RetryConfig"), - "Sleep" to smithyAsync(runtimeConfig).member("rt::sleep::Sleep"), - "TimeoutConfig" to smithyTypes(runtimeConfig).member("timeout::TimeoutConfig"), + "AsyncSleep" to smithyAsync(runtimeConfig).resolve("rt::sleep::AsyncSleep"), + "RetryConfig" to smithyTypes(runtimeConfig).resolve("retry::RetryConfig"), + "Sleep" to smithyAsync(runtimeConfig).resolve("rt::sleep::Sleep"), + "TimeoutConfig" to smithyTypes(runtimeConfig).resolve("timeout::TimeoutConfig"), ) override fun section(section: ServiceConfig) = @@ -244,9 +244,9 @@ class ResiliencyReExportCustomization(private val runtimeConfig: RuntimeConfig) pub use #{timeout}::{TimeoutConfig, TimeoutConfigBuilder}; } """, - "retry" to smithyTypes(runtimeConfig).member("retry"), - "sleep" to smithyAsync(runtimeConfig).member("rt::sleep"), - "timeout" to smithyTypes(runtimeConfig).member("timeout"), + "retry" to smithyTypes(runtimeConfig).resolve("retry"), + "sleep" to smithyAsync(runtimeConfig).resolve("rt::sleep"), + "timeout" to smithyTypes(runtimeConfig).resolve("timeout"), ) } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt index dbbcdbd2c4..d1c68b51b3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt @@ -60,9 +60,9 @@ internal fun pubUseTypes(runtimeConfig: RuntimeConfig, model: Model): List listOf( - PubUseType(http.member("result::SdkError")) { true }, - PubUseType(http.member("byte_stream::ByteStream"), ::hasStreamingOperations), - PubUseType(http.member("byte_stream::AggregatedBytes"), ::hasStreamingOperations), + PubUseType(http.resolve("result::SdkError")) { true }, + PubUseType(http.resolve("byte_stream::ByteStream"), ::hasStreamingOperations), + PubUseType(http.resolve("byte_stream::AggregatedBytes"), ::hasStreamingOperations), ) } ).filter { pubUseType -> pubUseType.shouldExport(model) }.map { it.type } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt index e9e1d0856d..b6abf95867 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt @@ -46,7 +46,7 @@ class NoOpEventStreamSigningConfig( private val serviceHasEventStream: Boolean, runtimeConfig: RuntimeConfig, ) : EventStreamSigningConfig(runtimeConfig) { - private val codegenScope = arrayOf("NoOpSigner" to smithyEventstream(runtimeConfig).member("frame::NoOpSigner")) + private val codegenScope = arrayOf("NoOpSigner" to smithyEventstream(runtimeConfig).resolve("frame::NoOpSigner")) override fun configImplSection() = renderEventStreamSignerFn { writable { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt index aab2eebc28..bbb7eb2420 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt @@ -32,7 +32,7 @@ class EndpointTraitBindings( private val endpointTrait: EndpointTrait, ) { private val inputShape = operationShape.inputShape(model) - private val endpointPrefix = smithyHttp(runtimeConfig).member("endpoint::EndpointPrefix") + private val endpointPrefix = smithyHttp(runtimeConfig).resolve("endpoint::EndpointPrefix") /** * Render the `EndpointPrefix` struct. [input] refers to the symbol referring to the input of this operation. diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt index 63ec19d4a4..2506af89e4 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt @@ -18,7 +18,6 @@ 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.asType import software.amazon.smithy.rust.codegen.core.rustlang.render import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate @@ -113,12 +112,12 @@ class PaginatorGenerator private constructor( "Builder" to operation.inputShape(model).builderSymbol(symbolProvider), // SDK Types - "SdkError" to smithyHttp(runtimeConfig).member("result::SdkError"), + "SdkError" to smithyHttp(runtimeConfig).resolve("result::SdkError"), "client" to smithyClient(runtimeConfig), - "fn_stream" to smithyAsync(runtimeConfig).member("future::fn_stream"), + "fn_stream" to smithyAsync(runtimeConfig).resolve("future::fn_stream"), // External Types - "Stream" to TokioStream.asType().member("Stream"), + "Stream" to TokioStream.asType().resolve("Stream"), ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt index d5a23232a3..d9344b678f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt @@ -11,7 +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.asType 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 @@ -47,9 +46,9 @@ class CustomizableOperationGenerator( pub use #{ClassifyRetry}; pub use #{RetryKind}; """, - "Operation" to smithyHttp(runtimeConfig).member("operation::Operation"), - "ClassifyRetry" to smithyHttp(runtimeConfig).member("retry::ClassifyRetry"), - "RetryKind" to smithyTypes(runtimeConfig).member("retry::RetryKind"), + "Operation" to smithyHttp(runtimeConfig).resolve("operation::Operation"), + "ClassifyRetry" to smithyHttp(runtimeConfig).resolve("retry::ClassifyRetry"), + "RetryKind" to smithyTypes(runtimeConfig).resolve("retry::RetryKind"), ) renderCustomizableOperationModule(this) @@ -66,9 +65,9 @@ class CustomizableOperationGenerator( val codegenScope = arrayOf( // SDK Types - "http_result" to smithyHttp(runtimeConfig).member("result"), - "http_body" to smithyHttp(runtimeConfig).member("body"), - "HttpRequest" to Http.asType().member("Request"), + "http_result" to smithyHttp(runtimeConfig).resolve("result"), + "http_body" to smithyHttp(runtimeConfig).resolve("body"), + "HttpRequest" to Http.asType().resolve("Request"), "handle_generics_decl" to handleGenerics.declaration(), "handle_generics_bounds" to handleGenerics.bounds(), "operation_generics_decl" to operationGenerics.declaration(), @@ -150,9 +149,9 @@ class CustomizableOperationGenerator( val codegenScope = arrayOf( "combined_generics_decl" to combinedGenerics.declaration(), "handle_generics_bounds" to handleGenerics.bounds(), - "ParseHttpResponse" to smithyHttp(runtimeConfig).member("response::ParseHttpResponse"), - "NewRequestPolicy" to smithyClient(runtimeConfig).member("retry::NewRequestPolicy"), - "SmithyRetryPolicy" to smithyClient(runtimeConfig).member("bounds::SmithyRetryPolicy"), + "ParseHttpResponse" to smithyHttp(runtimeConfig).resolve("response::ParseHttpResponse"), + "NewRequestPolicy" to smithyClient(runtimeConfig).resolve("retry::NewRequestPolicy"), + "SmithyRetryPolicy" to smithyClient(runtimeConfig).resolve("bounds::SmithyRetryPolicy"), ) writer.rustTemplate( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt index 8d5a2489d2..17e255f61e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt @@ -57,11 +57,11 @@ class FluentClientGenerator( private val generics: FluentClientGenerics = FlexibleClientGenerics( connectorDefault = null, middlewareDefault = null, - retryDefault = smithyClient(codegenContext.runtimeConfig).member("retry::Standard"), + retryDefault = smithyClient(codegenContext.runtimeConfig).resolve("retry::Standard"), client = smithyClient(codegenContext.runtimeConfig), ), private val customizations: List = emptyList(), - private val retryClassifier: RuntimeType = smithyHttp(codegenContext.runtimeConfig).member("retry::DefaultResponseRetryClassifier"), + private val retryClassifier: RuntimeType = smithyHttp(codegenContext.runtimeConfig).resolve("retry::DefaultResponseRetryClassifier"), ) { companion object { fun clientOperationFnName(operationShape: OperationShape, symbolProvider: RustSymbolProvider): String = @@ -304,11 +304,11 @@ class FluentClientGenerator( self.handle.client.call(op).await } """, - "ClassifyRetry" to smithyHttp(runtimeConfig).member("retry::ClassifyRetry"), + "ClassifyRetry" to smithyHttp(runtimeConfig).resolve("retry::ClassifyRetry"), "OperationError" to errorType, "OperationOutput" to outputType, - "SdkError" to smithyHttp(runtimeConfig).member("result::SdkError"), - "SdkSuccess" to smithyHttp(runtimeConfig).member("result::SdkSuccess"), + "SdkError" to smithyHttp(runtimeConfig).resolve("result::SdkError"), + "SdkSuccess" to smithyHttp(runtimeConfig).resolve("result::SdkSuccess"), "send_bounds" to generics.sendBounds(operationSymbol, outputType, errorType, retryClassifier), "customizable_op_type_params" to rustTypeParameters( symbolProvider.toSymbol(operation), diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt index b0e4beecfb..b3229051e6 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt @@ -90,9 +90,9 @@ data class FlexibleClientGenerics( } override fun toRustGenerics(): RustGenerics = RustGenerics( - GenericTypeArg("C", client.member("bounds::SmithyConnector")), - GenericTypeArg("M", client.member("bounds::SmithyMiddleware")), - GenericTypeArg("R", client.member("retry::NewRequestPolicy")), + GenericTypeArg("C", client.resolve("bounds::SmithyConnector")), + GenericTypeArg("M", client.resolve("bounds::SmithyMiddleware")), + GenericTypeArg("R", client.resolve("retry::NewRequestPolicy")), ) private fun defaultType(default: RuntimeType?) = writable { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt index 6cb91d53d3..f7bb6df98c 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt @@ -16,8 +16,8 @@ open class EventStreamSigningConfig( runtimeConfig: RuntimeConfig, ) : ConfigCustomization() { private val codegenScope = arrayOf( - "SharedPropertyBag" to smithyHttp(runtimeConfig).member("property_bag::SharedPropertyBag"), - "SignMessage" to smithyEventstream(runtimeConfig).member("frame::SignMessage"), + "SharedPropertyBag" to smithyHttp(runtimeConfig).resolve("property_bag::SharedPropertyBag"), + "SignMessage" to smithyEventstream(runtimeConfig).resolve("frame::SignMessage"), ) override fun section(section: ServiceConfig): Writable { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt index 43d20282f9..e34d95a29d 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt @@ -29,7 +29,6 @@ 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.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.escape import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock @@ -73,7 +72,7 @@ class ProtocolTestGenerator( private val codegenScope = arrayOf( "SmithyHttp" to smithyHttp(runtimeConfig), - "AssertEq" to PrettyAssertions.asType().member("assert_eq!"), + "AssertEq" to PrettyAssertions.asType().resolve("assert_eq!"), ) sealed class TestCase { @@ -193,8 +192,8 @@ class ProtocolTestGenerator( let ep = #{Endpoint}::mutable(#{Uri}::from_static(${withScheme.dq()})); ep.set_endpoint(http_request.uri_mut(), parts.acquire().get()); """, - "Endpoint" to smithyHttp(runtimeConfig).member("endpoint::Endpoint"), - "Uri" to Http.asType().member("Uri"), + "Endpoint" to smithyHttp(runtimeConfig).resolve("endpoint::Endpoint"), + "Uri" to Http.asType().resolve("Uri"), ) } rustTemplate( @@ -258,7 +257,7 @@ class ProtocolTestGenerator( write("let expected_output =") instantiator.render(this, expectedShape, testCase.params) write(";") - rust("let http_response = #T::new()", Http.asType().member("response::Builder")) + rust("let http_response = #T::new()", Http.asType().resolve("response::Builder")) testCase.headers.forEach { (key, value) -> writeWithNoFormatting(".header(${key.dq()}, ${value.dq()})") } @@ -272,7 +271,7 @@ class ProtocolTestGenerator( ) rust( "let mut op_response = #T::new(http_response);", - RuntimeType.operationModule(runtimeConfig).member("Response"), + RuntimeType.operationModule(runtimeConfig).resolve("Response"), ) rustTemplate( """ @@ -286,8 +285,8 @@ class ProtocolTestGenerator( }); """, "op" to operationSymbol, - "bytes" to Bytes.asType().member("Bytes"), - "parse_http_response" to smithyHttp(runtimeConfig).member("response::ParseHttpResponse"), + "bytes" to Bytes.asType().resolve("Bytes"), + "parse_http_response" to smithyHttp(runtimeConfig).resolve("response::ParseHttpResponse"), ) if (expectedShape.hasTrait()) { val errorSymbol = operationShape.errorSymbol(codegenContext.model, codegenContext.symbolProvider, codegenContext.target) @@ -317,7 +316,7 @@ class ProtocolTestGenerator( when (codegenContext.model.expectShape(member.target)) { is DoubleShape, is FloatShape -> { addUseImports( - smithyProtocolTest(codegenContext.runtimeConfig).member("FloatEquals").toSymbol(), + smithyProtocolTest(codegenContext.runtimeConfig).resolve("FloatEquals").toSymbol(), ) rust( """ @@ -353,8 +352,8 @@ class ProtocolTestGenerator( val rawMediaType = (mediaType ?: "unknown").dq() rustTemplate( "#{validate_body}(&body, $escapedExpectedBody, #{MediaType}::from($rawMediaType))", - "validate_body" to smithyProtocolTest(runtimeConfig).member("validate_body"), - "MediaType" to smithyProtocolTest(runtimeConfig).member("MediaType"), + "validate_body" to smithyProtocolTest(runtimeConfig).resolve("validate_body"), + "MediaType" to smithyProtocolTest(runtimeConfig).resolve("MediaType"), ) } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt index 419b9ad68a..77c76babaa 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt @@ -16,7 +16,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Compani 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.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.assignment import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock @@ -82,7 +81,7 @@ class HttpBoundProtocolTraitImplGenerator( "ParseResponse" to RuntimeType.parseResponse(runtimeConfig), "http" to Http.asType(), "operation" to RuntimeType.operationModule(runtimeConfig), - "Bytes" to Bytes.asType().member("Bytes"), + "Bytes" to Bytes.asType().resolve("Bytes"), ) override fun generateTraitImpls( diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt index e2526b5ea0..23839535f0 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt @@ -222,10 +222,10 @@ class FakeSigningConfig( runtimeConfig: RuntimeConfig, ) : ConfigCustomization() { private val codegenScope = arrayOf( - "SharedPropertyBag" to smithyHttp(runtimeConfig).member("property_bag::SharedPropertyBag"), - "SignMessageError" to smithyEventstream(runtimeConfig).member("frame::SignMessageError"), - "SignMessage" to smithyEventstream(runtimeConfig).member("frame::SignMessage"), - "Message" to smithyEventstream(runtimeConfig).member("frame::Message"), + "SharedPropertyBag" to smithyHttp(runtimeConfig).resolve("property_bag::SharedPropertyBag"), + "SignMessageError" to smithyEventstream(runtimeConfig).resolve("frame::SignMessageError"), + "SignMessage" to smithyEventstream(runtimeConfig).resolve("frame::SignMessage"), + "Message" to smithyEventstream(runtimeConfig).resolve("frame::Message"), ) override fun section(section: ServiceConfig): Writable { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolVisitorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolVisitorTest.kt index e7e87a89a6..805e0b2d24 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolVisitorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolVisitorTest.kt @@ -159,8 +159,8 @@ class SymbolVisitorTest { val provider: SymbolProvider = testSymbolProvider(model) val setSymbol = provider.toSymbol(set) - setSymbol.rustType().render(false) shouldBe "${RustType.HashSet.Type}" - setSymbol.referenceClosure().map { it.name } shouldBe listOf(RustType.HashSet.Type, "String") + setSymbol.rustType().render(false) shouldBe "${RustType.HashSet.RuntimeType.name}" + setSymbol.referenceClosure().map { it.name } shouldBe listOf(RustType.HashSet.RuntimeType.name, "String") } @Test diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt index 220e1c8fe5..81b124b4d8 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt @@ -17,7 +17,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDe import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.escape import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate @@ -68,8 +67,8 @@ private class TestProtocolTraitImplGenerator( "parse_strict" to RuntimeType.parseStrictResponse(codegenContext.runtimeConfig), "output" to symbolProvider.toSymbol(operationShape.outputShape(codegenContext.model)), "error" to operationShape.errorSymbol(codegenContext.model, symbolProvider, codegenContext.target), - "response" to Http.asType().member("Response"), - "bytes" to Bytes.asType().member("Bytes"), + "response" to Http.asType().resolve("Response"), + "bytes" to Bytes.asType().resolve("Bytes"), ) } } @@ -87,7 +86,7 @@ private class TestProtocolMakeOperationGenerator( includeDefaultPayloadHeaders = true, ) { override fun createHttpRequest(writer: RustWriter, operationShape: OperationShape) { - writer.rust("#T::new()", Http.asType().member("request::Builder")) + writer.rust("#T::new()", Http.asType().resolve("request::Builder")) writer.writeWithNoFormatting(httpRequestBuilder) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt index d5166c841c..e748556eb9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt @@ -112,8 +112,6 @@ class InlineDependency( } } -fun CargoDependency.asType() = RuntimeType(null, dependency = this, namespace = rustName) - data class Feature(val name: String, val default: Boolean, val deps: List) /** @@ -138,8 +136,6 @@ data class CargoDependency( is Local -> "local" } - fun rustName(name: String): RuntimeType = RuntimeType(name, this, this.rustName) - fun toMap(): Map { val attribs = mutableMapOf() with(location) { @@ -184,6 +180,11 @@ data class CargoDependency( return "$name = { ${attribs.joinToString(",")} }" } + // TODO rename to `toType` to maintain naming convention of the above methods + fun asType(): RuntimeType { + return RuntimeType(rustName, this) + } + companion object { // Regular dependencies val Bytes: CargoDependency = CargoDependency("bytes", CratesIo("1.0.0")) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt index 6a7d36e2e8..7647c013f0 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt @@ -108,17 +108,17 @@ sealed class RustType { data class HashMap(val key: RustType, override val member: RustType) : RustType(), Container { // validating that `key` is a string occurs in the constructor in SymbolVisitor - override val name: kotlin.String = "HashMap" - override val namespace = "std::collections" + override val name: kotlin.String = RuntimeType.name + override val namespace = RuntimeType.namespace companion object { - val RuntimeType = RuntimeType("HashMap", dependency = null, namespace = "std::collections") + val RuntimeType = RuntimeType("std::collections::HashMap") } } data class HashSet(override val member: RustType) : RustType(), Container { - override val name = Type - override val namespace = Namespace + override val name: kotlin.String = RuntimeType.name + override val namespace = RuntimeType.namespace companion object { // This is Vec intentionally. Note the following passage from the Smithy spec: @@ -126,9 +126,7 @@ sealed class RustType { // support ordered sets, requiring them may be overly burdensome for users, or conflict with language // idioms. Such languages SHOULD store the values of sets in a list and rely on validation to ensure uniqueness. // It's possible that we could provide our own wrapper type in the future. - const val Type = "Vec" - const val Namespace = "std::vec" - val RuntimeType = RuntimeType(name = Type, namespace = Namespace, dependency = null) + val RuntimeType = RuntimeType("std::vec::Vec") } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt index a253163eb0..eec4673ea1 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt @@ -22,7 +22,6 @@ 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.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustInlineTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.util.orNull @@ -110,22 +109,33 @@ data class RuntimeConfig( /** * `RuntimeType` captures all necessary information to render a type into a Rust file: * - [name]: What type is this? - * - [dependency]: What other crates, if any, are required to use this type? * - [namespace]: Where can we find this type. + * - [dependency]: What other crates, if any, are required to use this type? * * For example: * + * `RuntimeType("header::HeaderName", CargoDependency.Http)`, when passed to a [RustWriter] would appear as such: + * * `http::header::HeaderName` * ------------ ---------- - * | | - * [namespace] [name] - * - * This type would have a [CargoDependency] pointing to the `http` crate. + * | | + * `[namespace]` `[name]` * - * By grouping all of this information, when we render a type into a [RustWriter], we can not only render a fully qualified - * name, but also ensure that we automatically add any dependencies **as they are used**. + * This type would have a [CargoDependency] pointing to the `http` crate. Writing it multiple times would still only + * add the dependency once. */ -data class RuntimeType(val name: String?, val dependency: RustDependency?, val namespace: String) { +data class RuntimeType(val path: String, val dependency: RustDependency? = null) { + val name: String + val namespace: String + + init { + val splitPath = path.split("::").toMutableList() + // get the name at the end + this.name = splitPath.removeLast() + // get all parts that aren't the name at the end + this.namespace = splitPath.joinToString("::") + } + /** * Get a writable for this `RuntimeType` */ @@ -143,32 +153,33 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n * (e.g. when bringing a trait into scope). See [CodegenWriter.addUseImports]. */ fun toSymbol(): Symbol { - val builder = Symbol.builder().name(name).namespace(namespace, "::") - .rustType(RustType.Opaque(name ?: "", namespace = namespace)) + val builder = Symbol + .builder() + .name(name) + .namespace(namespace, "::") + .rustType(RustType.Opaque(name, namespace)) dependency?.run { builder.addDependency(this) } return builder.build() } /** - * Create a new [RuntimeType] with a nested name. + * Create a new [RuntimeType] with a nested path. * * # Example * ```kotlin - * val http = CargoDependency.http.member("Request") + * val http = CargoDependency.http.resolve("Request") * ``` */ - fun member(member: String): RuntimeType { - val newName = name?.let { "$name::$member" } ?: member - return copy(name = newName) + fun resolve(subPath: String): RuntimeType { + return copy(path = "$path::$subPath") } /** * Returns the fully qualified name for this type */ fun fullyQualifiedName(): String { - val postFix = name?.let { "::$name" } ?: "" - return "$namespace$postFix" + return path } /** @@ -176,22 +187,24 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n */ companion object { // stdlib types - val std = RuntimeType(null, dependency = null, namespace = "std") - val stdFmt = std.member("fmt") - val AsRef = RuntimeType("AsRef", dependency = null, namespace = "std::convert") - val ByteSlab = RuntimeType("Vec", dependency = null, namespace = "std::vec") - val Clone = std.member("clone::Clone") - val Debug = stdFmt.member("Debug") - val Default: RuntimeType = RuntimeType("Default", dependency = null, namespace = "std::default") - val Display = stdFmt.member("Display") - val From = RuntimeType("From", dependency = null, namespace = "std::convert") - val TryFrom = RuntimeType("TryFrom", dependency = null, namespace = "std::convert") - val PartialEq = std.member("cmp::PartialEq") - val StdError = RuntimeType("Error", dependency = null, namespace = "std::error") - val String = RuntimeType("String", dependency = null, namespace = "std::string") + val std = RuntimeType("std") + val stdFmt = std.resolve("fmt") + val AsRef = RuntimeType("std::convert::AsRef") + val ByteSlab = RuntimeType("std::vec::Vec") + val Clone = std.resolve("clone::Clone") + val Debug = stdFmt.resolve("Debug") + val Default = RuntimeType("std::default::Default") + val Display = stdFmt.resolve("Display") + val From = RuntimeType("std::convert::From") + val TryFrom = RuntimeType("std::convert::TryFrom") + val PartialEq = std.resolve("cmp::PartialEq") + val StdError = RuntimeType("std::error::Error") + val String = RuntimeType("std::string::String") + val Phantom = RuntimeType("std::marker::PhantomData") + val Cow = RuntimeType("std::borrow::Cow") // codegen types - val Config = RuntimeType("config", null, "crate") + val Config = RuntimeType("crate::config") // smithy runtime types fun smithyAsync(runtimeConfig: RuntimeConfig) = CargoDependency.smithyAsync(runtimeConfig).asType() @@ -206,25 +219,25 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n fun smithyProtocolTest(runtimeConfig: RuntimeConfig) = CargoDependency.smithyProtocolTestHelpers(runtimeConfig).asType() // smithy runtime type members - fun base64Decode(runtimeConfig: RuntimeConfig): RuntimeType = smithyTypes(runtimeConfig).member("base64::decode") - fun base64Encode(runtimeConfig: RuntimeConfig): RuntimeType = smithyTypes(runtimeConfig).member("base64::encode") - fun blob(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).member("Blob") - fun byteStream(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).member("byte_stream::ByteStream") - fun dateTime(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).member("DateTime") - fun document(runtimeConfig: RuntimeConfig): RuntimeType = smithyTypes(runtimeConfig).member("Document") - fun errorKind(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).member("retry::ErrorKind") - fun eventStreamReceiver(runtimeConfig: RuntimeConfig): RuntimeType = smithyHttp(runtimeConfig).member("event_stream::Receiver") - fun genericError(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).member("Error") + fun base64Decode(runtimeConfig: RuntimeConfig): RuntimeType = smithyTypes(runtimeConfig).resolve("base64::decode") + fun base64Encode(runtimeConfig: RuntimeConfig): RuntimeType = smithyTypes(runtimeConfig).resolve("base64::encode") + fun blob(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).resolve("Blob") + fun byteStream(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("byte_stream::ByteStream") + fun dateTime(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).resolve("DateTime") + fun document(runtimeConfig: RuntimeConfig): RuntimeType = smithyTypes(runtimeConfig).resolve("Document") + fun errorKind(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).resolve("retry::ErrorKind") + fun eventStreamReceiver(runtimeConfig: RuntimeConfig): RuntimeType = smithyHttp(runtimeConfig).resolve("event_stream::Receiver") + fun genericError(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).resolve("Error") fun jsonErrors(runtimeConfig: RuntimeConfig) = forInlineDependency(InlineDependency.jsonErrors(runtimeConfig)) - fun labelFormat(runtimeConfig: RuntimeConfig, func: String) = smithyHttp(runtimeConfig).member("label::$func") - fun operation(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).member("operation::Operation") - fun operationModule(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).member("operation") - fun parseResponse(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).member("response::ParseHttpResponse") - fun parseStrictResponse(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).member("response::ParseStrictResponse") - fun protocolTest(runtimeConfig: RuntimeConfig, func: String): RuntimeType = smithyProtocolTest(runtimeConfig).member(func) - fun provideErrorKind(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).member("retry::ProvideErrorKind") - fun queryFormat(runtimeConfig: RuntimeConfig, func: String) = smithyHttp(runtimeConfig).member("query::$func") - fun sdkBody(runtimeConfig: RuntimeConfig): RuntimeType = smithyHttp(runtimeConfig).member("body::SdkBody") + fun labelFormat(runtimeConfig: RuntimeConfig, func: String) = smithyHttp(runtimeConfig).resolve("label::$func") + fun operation(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("operation::Operation") + fun operationModule(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("operation") + fun parseResponse(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("response::ParseHttpResponse") + fun parseStrictResponse(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("response::ParseStrictResponse") + fun protocolTest(runtimeConfig: RuntimeConfig, func: String): RuntimeType = smithyProtocolTest(runtimeConfig).resolve(func) + fun provideErrorKind(runtimeConfig: RuntimeConfig) = smithyTypes(runtimeConfig).resolve("retry::ProvideErrorKind") + fun queryFormat(runtimeConfig: RuntimeConfig, func: String) = smithyHttp(runtimeConfig).resolve("query::$func") + fun sdkBody(runtimeConfig: RuntimeConfig): RuntimeType = smithyHttp(runtimeConfig).resolve("body::SdkBody") fun timestampFormat(runtimeConfig: RuntimeConfig, format: TimestampFormatTrait.Format): RuntimeType { val timestampFormat = when (format) { TimestampFormatTrait.Format.EPOCH_SECONDS -> "EpochSeconds" @@ -233,16 +246,14 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n TimestampFormatTrait.Format.UNKNOWN -> TODO() } - return smithyTypes(runtimeConfig).member("date_time::Format::$timestampFormat") + return smithyTypes(runtimeConfig).resolve("date_time::Format::$timestampFormat") } - fun forInlineDependency(inlineDependency: InlineDependency) = - RuntimeType(inlineDependency.name, inlineDependency, namespace = "crate") + fun forInlineDependency(inlineDependency: InlineDependency) = RuntimeType("crate::${inlineDependency.name}", inlineDependency) fun forInlineFun(name: String, module: RustModule, func: Writable) = RuntimeType( - name = name, + "crate::${module.name}::$name", dependency = InlineDependency(name, module, listOf(), func), - namespace = "crate::${module.name}", ) // inlinable types diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt index 8c5a56b577..23d00b362f 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt @@ -119,12 +119,12 @@ class BaseSymbolMetadataProvider( override fun enumMeta(stringShape: StringShape): RustMetadata { return containerDefault.withDerives( - RuntimeType.std.member("hash::Hash"), + RuntimeType.std.resolve("hash::Hash"), ).withDerives( // enums can be eq because they can only contain strings - RuntimeType.std.member("cmp::Eq"), + RuntimeType.std.resolve("cmp::Eq"), // enums can be Ord because they can only contain strings - RuntimeType.std.member("cmp::PartialOrd"), - RuntimeType.std.member("cmp::Ord"), + RuntimeType.std.resolve("cmp::PartialOrd"), + RuntimeType.std.resolve("cmp::Ord"), ) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index 9ae2da62ad..4bbf03a36d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -48,8 +48,8 @@ fun StructureShape.builderSymbol(symbolProvider: RustSymbolProvider): Symbol { .build() } -fun RuntimeConfig.operationBuildError() = RuntimeType.operationModule(this).member("BuildError") -fun RuntimeConfig.serializationError() = RuntimeType.operationModule(this).member("SerializationError") +fun RuntimeConfig.operationBuildError() = RuntimeType.operationModule(this).resolve("BuildError") +fun RuntimeConfig.serializationError() = RuntimeType.operationModule(this).resolve("SerializationError") class OperationBuildError(private val runtimeConfig: RuntimeConfig) { fun missingField(w: RustWriter, field: String, details: String) = "${w.format(runtimeConfig.operationBuildError())}::MissingField { field: ${field.dq()}, details: ${details.dq()} }" diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt index 1319851194..ecdb9d9e55 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt @@ -124,7 +124,7 @@ open class Instantiator( <#{Number} as #{Parse}>::parse_smithy_primitive(${data.value.dq()}).expect("invalid string for number") """, "Number" to numberSymbol, - "Parse" to smithyTypes(runtimeConfig).member("primitive::Parse"), + "Parse" to smithyTypes(runtimeConfig).resolve("primitive::Parse"), ) } @@ -139,8 +139,8 @@ open class Instantiator( let mut tokens = #{json_token_iter}(json_bytes).peekable(); #{expect_document}(&mut tokens).expect("well formed json") """, - "expect_document" to smithyJson(runtimeConfig).member("deserialize::token::expect_document"), - "json_token_iter" to smithyJson(runtimeConfig).member("deserialize::json_token_iter"), + "expect_document" to smithyJson(runtimeConfig).resolve("deserialize::token::expect_document"), + "json_token_iter" to smithyJson(runtimeConfig).resolve("deserialize::json_token_iter"), ) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt index d15edc7e88..fb56d771f9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt @@ -92,7 +92,7 @@ fun OperationShape.errorSymbol( fun UnionShape.eventStreamErrorSymbol(model: Model, symbolProvider: RustSymbolProvider, target: CodegenTarget): RuntimeType { val symbol = symbolProvider.toSymbol(this) - val errorSymbol = RuntimeType("${symbol.name}Error", null, "crate::error") + val errorSymbol = RuntimeType("crate::error::${symbol.name}Error") return RuntimeType.forInlineFun("${symbol.name}Error", RustModule.Error) { val errors = this@eventStreamErrorSymbol.eventStreamErrors().map { model.expectShape(it.asMemberShape().get().target, StructureShape::class.java) } when (target) { @@ -126,7 +126,7 @@ class CombinedErrorGenerator( private val genericError = RuntimeType.genericError(symbolProvider.config().runtimeConfig) fun render(writer: RustWriter) { - val errorSymbol = RuntimeType("${operationSymbol.name}Error", null, "crate::error") + val errorSymbol = RuntimeType("crate::error::${operationSymbol.name}Error") renderErrors(writer, errorSymbol, operationSymbol) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ServerCombinedErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ServerCombinedErrorGenerator.kt index de6c09a5ac..6ce5bc8c93 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ServerCombinedErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ServerCombinedErrorGenerator.kt @@ -32,7 +32,7 @@ open class ServerCombinedErrorGenerator( private val errors: List, ) { open fun render(writer: RustWriter) { - val symbol = RuntimeType("${operationSymbol.name}Error", null, "crate::error") + val symbol = RuntimeType("crate::error::${operationSymbol.name}Error") if (errors.isNotEmpty()) { renderErrors(writer, symbol, operationSymbol) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt index f5e5df5e31..b6e71d16e9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt @@ -14,7 +14,6 @@ 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.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.deprecatedShape import software.amazon.smithy.rust.codegen.core.rustlang.documentShape import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -50,7 +49,7 @@ class TopLevelErrorGenerator(private val codegenContext: CodegenContext, private .map { codegenContext.model.expectShape(it, StructureShape::class.java) } .sortedBy { it.id.getName(codegenContext.serviceShape) } - private val sdkError = CargoDependency.smithyHttp(codegenContext.runtimeConfig).asType().member("result::SdkError") + private val sdkError = CargoDependency.smithyHttp(codegenContext.runtimeConfig).asType().resolve("result::SdkError") fun render(crate: RustCrate) { crate.withModule(RustModule.private("error_meta")) { renderDefinition() diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt index 5594230bae..9fcc61d9fc 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt @@ -27,7 +27,6 @@ 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.Writable import software.amazon.smithy.rust.codegen.core.rustlang.asOptional -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref import software.amazon.smithy.rust.codegen.core.rustlang.render import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -101,7 +100,7 @@ class HttpBindingGenerator( private val model = codegenContext.model private val service = codegenContext.serviceShape private val index = HttpBindingIndex.of(model) - private val headerUtil = smithyHttp(runtimeConfig).member("header") + private val headerUtil = smithyHttp(runtimeConfig).resolve("header") private val defaultTimestampFormat = TimestampFormatTrait.Format.EPOCH_SECONDS private val dateTime = RuntimeType.dateTime(runtimeConfig).toSymbol().rustType() private val httpSerdeModule = RustModule.private("http_serde") @@ -129,10 +128,10 @@ class HttpBindingGenerator( let headers = header_map.get_all(${binding.locationName.dq()}).iter(); #{deserializeFromHeader:W} } - """, - "HeaderMap" to Http.asType().member("HeaderMap"), + """, + "HeaderMap" to Http.asType().resolve("HeaderMap"), "Output" to outputT, - "ParseError" to smithyHttp(runtimeConfig).member("header::ParseError"), + "ParseError" to smithyHttp(runtimeConfig).resolve("header::ParseError"), "deserializeFromHeader" to deserializeFromHeader( model.expectShape(binding.member.target), binding.member, @@ -154,11 +153,11 @@ class HttpBindingGenerator( pub fn ${fnName}_inner(headers: #{ValueIter}) -> std::result::Result, #{ParseError}> { #{deserializeFromHeader:W} } - """, - "ValueIter" to Http.asType().member("header::ValueIter"), - "HeaderValue" to Http.asType().member("HeaderValue"), + """, + "ValueIter" to Http.asType().resolve("header::ValueIter"), + "HeaderValue" to Http.asType().resolve("HeaderValue"), "Output" to symbolProvider.toSymbol(model.expectShape(target.value.target)), - "ParseError" to smithyHttp(runtimeConfig).member("header::ParseError"), + "ParseError" to smithyHttp(runtimeConfig).resolve("header::ParseError"), "deserializeFromHeader" to deserializeFromHeader( model.expectShape(target.value.target), binding.member, @@ -179,11 +178,11 @@ class HttpBindingGenerator( }).collect(); out.map(Some) } - """, - "HeaderMap" to Http.asType().member("HeaderMap"), + """, + "HeaderMap" to Http.asType().resolve("HeaderMap"), "Output" to outputSymbol.mapRustType { it.asOptional() }, - "ParseError" to smithyHttp(runtimeConfig).member("header::ParseError"), - "headers_for_prefix" to smithyHttp(runtimeConfig).member("header::headers_for_prefix"), + "ParseError" to smithyHttp(runtimeConfig).resolve("header::ParseError"), + "headers_for_prefix" to smithyHttp(runtimeConfig).resolve("header::headers_for_prefix"), "inner" to inner, ) } @@ -206,7 +205,7 @@ class HttpBindingGenerator( val outputT = symbolProvider.toSymbol(binding.member) rustBlock( "pub fn $fnName(body: &mut #T) -> std::result::Result<#T, #T>", - smithyHttp(runtimeConfig).member("body::SdkBody"), + smithyHttp(runtimeConfig).resolve("body::SdkBody"), outputT, errorT, ) { @@ -250,7 +249,7 @@ class HttpBindingGenerator( let body = std::mem::replace(body, #{SdkBody}::taken()); Ok(#{Receiver}::new(unmarshaller, body)) """, - "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), + "SdkBody" to smithyHttp(runtimeConfig).resolve("body::SdkBody"), "unmarshallerConstructorFn" to unmarshallerConstructorFn, "Receiver" to RuntimeType.eventStreamReceiver(runtimeConfig), ) @@ -266,7 +265,7 @@ class HttpBindingGenerator( let body = std::mem::replace(body, #{SdkBody}::taken()); Ok(#{ByteStream}::new(body)) """, - "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), + "SdkBody" to smithyHttp(runtimeConfig).resolve("body::SdkBody"), "ByteStream" to symbolProvider.toSymbol(member), ) } @@ -373,12 +372,12 @@ class HttpBindingGenerator( if (coreShape.hasTrait()) { rustTemplate( """ - let $parsedValue: std::result::Result, _> = $parsedValue - .iter().map(|s| - #{base_64_decode}(s).map_err(|_|#{header}::ParseError::new_with_message("failed to decode base64")) - .and_then(|bytes|String::from_utf8(bytes).map_err(|_|#{header}::ParseError::new_with_message("base64 encoded data was not valid utf-8"))) - ).collect(); - """, + let $parsedValue: std::result::Result, _> = $parsedValue + .iter().map(|s| + #{base_64_decode}(s).map_err(|_|#{header}::ParseError::new_with_message("failed to decode base64")) + .and_then(|bytes|String::from_utf8(bytes).map_err(|_|#{header}::ParseError::new_with_message("base64 encoded data was not valid utf-8"))) + ).collect(); + """, "base_64_decode" to RuntimeType.base64Decode(runtimeConfig), "header" to headerUtil, ) @@ -389,34 +388,34 @@ class HttpBindingGenerator( is RustType.Vec -> rust( """ - Ok(if !$parsedValue.is_empty() { - Some($parsedValue) - } else { - None - }) - """, + Ok(if !$parsedValue.is_empty() { + Some($parsedValue) + } else { + None + }) + """, ) is RustType.HashSet -> rust( """ - Ok(if !$parsedValue.is_empty() { - Some($parsedValue.into_iter().collect()) - } else { - None - }) - """, + Ok(if !$parsedValue.is_empty() { + Some($parsedValue.into_iter().collect()) + } else { + None + }) + """, ) else -> rustTemplate( """ - if $parsedValue.len() > 1 { - Err(#{header_util}::ParseError::new_with_message(format!("expected one item but found {}", $parsedValue.len()))) - } else { - let mut $parsedValue = $parsedValue; - Ok($parsedValue.pop()) - } - """, + if $parsedValue.len() > 1 { + Err(#{header_util}::ParseError::new_with_message(format!("expected one item but found {}", $parsedValue.len()))) + } else { + let mut $parsedValue = $parsedValue; + Ok($parsedValue.pop()) + } + """, "header_util" to headerUtil, ) } @@ -473,8 +472,8 @@ class HttpBindingGenerator( ) val codegenScope = arrayOf( "BuildError" to runtimeConfig.operationBuildError(), - HttpMessageType.REQUEST.name to Http.asType().member("request::Builder"), - HttpMessageType.RESPONSE.name to Http.asType().member("response::Builder"), + HttpMessageType.REQUEST.name to Http.asType().resolve("request::Builder"), + HttpMessageType.RESPONSE.name to Http.asType().resolve("response::Builder"), "Shape" to shapeSymbol, ) rustBlockTemplate( @@ -509,7 +508,7 @@ class HttpBindingGenerator( if (innerMemberType.isPrimitive()) { rust( "let mut encoder = #T::from(${autoDeref(innerField)});", - smithyTypes(runtimeConfig).member("primitive::Encoder"), + smithyTypes(runtimeConfig).resolve("primitive::Encoder"), ) } val formatted = headerFmtFun(this, innerMemberType, memberShape, innerField, isListHeader) @@ -586,7 +585,7 @@ class HttpBindingGenerator( fun quoteValue(value: String): String { // Timestamp shapes are not quoted in header lists return if (isListHeader && !target.isTimestampShape) { - val quoteFn = writer.format(headerUtil.member("quote_header_value")) + val quoteFn = writer.format(headerUtil.resolve("quote_header_value")) "$quoteFn($value)" } else { value diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt index 7243f306cd..f790d7f703 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt @@ -16,7 +16,6 @@ import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock @@ -65,11 +64,11 @@ class RequestBindingGenerator( private val httpTrait = protocol.httpBindingResolver.httpTrait(operationShape) private val httpBindingGenerator = HttpBindingGenerator(protocol, codegenContext, operationShape) private val index = HttpBindingIndex.of(model) - private val Encoder = smithyTypes(runtimeConfig).member("primitive::Encoder") + private val Encoder = smithyTypes(runtimeConfig).resolve("primitive::Encoder") private val codegenScope = arrayOf( "BuildError" to runtimeConfig.operationBuildError(), - "HttpRequestBuilder" to Http.asType().member("request::Builder"), + "HttpRequestBuilder" to Http.asType().resolve("request::Builder"), "Input" to symbolProvider.toSymbol(inputShape), ) @@ -117,7 +116,7 @@ class RequestBindingGenerator( "${label.content} = ${local(member)}" } val combinedArgs = listOf(formatString, *args.toTypedArray()) - writer.addImport(RuntimeType.stdFmt.member("Write").toSymbol(), null) + writer.addImport(RuntimeType.stdFmt.resolve("Write").toSymbol(), null) writer.rustBlockTemplate( "fn uri_base(_input: &#{Input}, output: &mut String) -> Result<(), #{BuildError}>", *codegenScope, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt index b6d5800a00..cb25df1991 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt @@ -6,9 +6,8 @@ package software.amazon.smithy.rust.codegen.core.smithy.generators.http import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.writable @@ -37,7 +36,7 @@ class RestRequestSpecGenerator( "PathSegment", "QuerySegment", ).map { - it to requestSpecModule.member(it) + it to requestSpecModule.resolve(it) }.toTypedArray() // TODO(https://github.com/awslabs/smithy-rs/issues/950): Support the `endpoint` trait. @@ -86,7 +85,7 @@ class RestRequestSpecGenerator( *codegenScope, "PathSegmentsVec" to pathSegmentsVec, "QuerySegmentsVec" to querySegmentsVec, - "Method" to CargoDependency.Http.asType().member("Method"), + "Method" to Http.asType().resolve("Method"), ) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt index 00ef5c3668..82386f593c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt @@ -11,7 +11,6 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -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 import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate @@ -48,7 +47,7 @@ open class MakeOperationGenerator( protected val runtimeConfig = codegenContext.runtimeConfig protected val symbolProvider = codegenContext.symbolProvider protected val httpBindingResolver = protocol.httpBindingResolver - private val defaultClassifier = smithyHttp(runtimeConfig).member("retry::DefaultResponseRetryClassifier") + private val defaultClassifier = smithyHttp(runtimeConfig).resolve("retry::DefaultResponseRetryClassifier") private val sdkId = codegenContext.serviceShape.getTrait()?.sdkId?.lowercase()?.replace(" ", "") @@ -56,12 +55,12 @@ open class MakeOperationGenerator( private val codegenScope = arrayOf( "config" to RuntimeType.Config, - "header_util" to smithyHttp(runtimeConfig).member("header"), + "header_util" to smithyHttp(runtimeConfig).resolve("header"), "http" to Http.asType(), - "HttpRequestBuilder" to Http.asType().member("request::Builder"), + "HttpRequestBuilder" to Http.asType().resolve("request::Builder"), "OpBuildError" to runtimeConfig.operationBuildError(), "operation" to RuntimeType.operationModule(runtimeConfig), - "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), + "SdkBody" to smithyHttp(runtimeConfig).resolve("body::SdkBody"), ) fun generateMakeOperation( @@ -96,7 +95,7 @@ open class MakeOperationGenerator( withBlock("let mut request = {", "};") { createHttpRequest(this, shape) } - rust("let mut properties = #T::new();", smithyHttp(runtimeConfig).member("property_bag::SharedPropertyBag")) + rust("let mut properties = #T::new();", smithyHttp(runtimeConfig).resolve("property_bag::SharedPropertyBag")) // When the payload is a `ByteStream`, `into_inner()` already returns an `SdkBody`, so we mute this // Clippy warning to make the codegen a little simpler in that case. @@ -172,7 +171,7 @@ open class MakeOperationGenerator( val contentType = httpBindingResolver.requestContentType(operationShape) httpBindingGenerator.renderUpdateHttpBuilder(writer) - writer.rust("let mut builder = update_http_builder(&self, #T::new())?;", Http.asType().member("request::Builder")) + writer.rust("let mut builder = update_http_builder(&self, #T::new())?;", Http.asType().resolve("request::Builder")) if (includeDefaultPayloadHeaders && contentType != null) { writer.rustTemplate( "builder = #{header_util}::set_request_header_if_absent(builder, #{http}::header::CONTENT_TYPE, ${contentType.dq()});", diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt index 564f293952..35239b1f5b 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt @@ -15,7 +15,6 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -86,7 +85,7 @@ class AwsJsonSerializerGenerator( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "Error" to runtimeConfig.serializationError(), - "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), + "SdkBody" to smithyHttp(runtimeConfig).resolve("body::SdkBody"), ) override fun operationInputSerializer(operationShape: OperationShape): RuntimeType { @@ -113,11 +112,11 @@ open class AwsJson( ) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( - "Bytes" to Bytes.asType().member("Bytes"), + "Bytes" to Bytes.asType().resolve("Bytes"), "Error" to RuntimeType.genericError(runtimeConfig), - "HeaderMap" to Http.asType().member("HeaderMap"), - "JsonError" to smithyJson(runtimeConfig).member("deserialize::Error"), - "Response" to Http.asType().member("Response"), + "HeaderMap" to Http.asType().resolve("HeaderMap"), + "JsonError" to smithyJson(runtimeConfig).resolve("deserialize::Error"), + "Response" to Http.asType().resolve("Response"), "json_errors" to RuntimeType.jsonErrors(runtimeConfig), ) private val jsonDeserModule = RustModule.private("json_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt index d46424a198..da28d20f8d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt @@ -15,7 +15,6 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -45,11 +44,11 @@ class AwsQueryProtocol(private val codegenContext: CodegenContext) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val awsQueryErrors: RuntimeType = RuntimeType.wrappedXmlErrors(runtimeConfig) private val errorScope = arrayOf( - "Bytes" to Bytes.asType().member("Bytes"), + "Bytes" to Bytes.asType().resolve("Bytes"), "Error" to RuntimeType.genericError(runtimeConfig), - "HeaderMap" to Http.asType().member("HeaderMap"), - "Response" to Http.asType().member("Response"), - "XmlError" to smithyXml(runtimeConfig).member("decode::XmlError"), + "HeaderMap" to Http.asType().resolve("HeaderMap"), + "Response" to Http.asType().resolve("Response"), + "XmlError" to smithyXml(runtimeConfig).resolve("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt index 84f1c029b2..f781de77c9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt @@ -12,7 +12,6 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -27,11 +26,11 @@ class Ec2QueryProtocol(private val codegenContext: CodegenContext) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val ec2QueryErrors: RuntimeType = RuntimeType.ec2QueryErrors(runtimeConfig) private val errorScope = arrayOf( - "Bytes" to Bytes.asType().member("Bytes"), + "Bytes" to Bytes.asType().resolve("Bytes"), "Error" to RuntimeType.genericError(runtimeConfig), - "HeaderMap" to Http.asType().member("HeaderMap"), - "Response" to Http.asType().member("Response"), - "XmlError" to smithyXml(runtimeConfig).member("decode::XmlError"), + "HeaderMap" to Http.asType().resolve("HeaderMap"), + "Response" to Http.asType().resolve("Response"), + "XmlError" to smithyXml(runtimeConfig).resolve("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt index c25243b1a0..587daad700 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt @@ -17,7 +17,6 @@ import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate @@ -60,10 +59,10 @@ class HttpBoundProtocolPayloadGenerator( private val operationSerModule = RustModule.private("operation_ser") private val codegenScope = arrayOf( "hyper" to CargoDependency.HyperWithStream.asType(), - "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), + "SdkBody" to smithyHttp(runtimeConfig).resolve("body::SdkBody"), "BuildError" to runtimeConfig.operationBuildError(), "SmithyHttp" to smithyHttp(runtimeConfig), - "NoOpSigner" to smithyEventstream(runtimeConfig).member("frame::NoOpSigner"), + "NoOpSigner" to smithyEventstream(runtimeConfig).resolve("frame::NoOpSigner"), ) override fun payloadMetadata(operationShape: OperationShape): ProtocolPayloadGenerator.PayloadMetadata { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt index d153d4cf77..a6797235c8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt @@ -17,7 +17,6 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType @@ -66,11 +65,11 @@ class RestJsonHttpBindingResolver( open class RestJson(val codegenContext: CodegenContext) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( - "Bytes" to Bytes.asType().member("Bytes"), + "Bytes" to Bytes.asType().resolve("Bytes"), "Error" to RuntimeType.genericError(runtimeConfig), - "HeaderMap" to Http.asType().member("HeaderMap"), - "JsonError" to smithyJson(runtimeConfig).member("deserialize::Error"), - "Response" to Http.asType().member("Response"), + "HeaderMap" to Http.asType().resolve("HeaderMap"), + "JsonError" to smithyJson(runtimeConfig).resolve("deserialize::Error"), + "Response" to Http.asType().resolve("Response"), "json_errors" to RuntimeType.jsonErrors(runtimeConfig), ) private val jsonDeserModule = RustModule.private("json_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt index 48bf4877fe..e8a5b01855 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt @@ -11,7 +11,6 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Bytes import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext @@ -27,11 +26,11 @@ open class RestXml(val codegenContext: CodegenContext) : Protocol { private val restXml = codegenContext.serviceShape.expectTrait() private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( - "Bytes" to Bytes.asType().member("Bytes"), + "Bytes" to Bytes.asType().resolve("Bytes"), "Error" to RuntimeType.genericError(runtimeConfig), - "HeaderMap" to Http.asType().member("HeaderMap"), - "Response" to Http.asType().member("Response"), - "XmlError" to smithyXml(runtimeConfig).member("decode::XmlError"), + "HeaderMap" to Http.asType().resolve("HeaderMap"), + "Response" to Http.asType().resolve("Response"), + "XmlError" to smithyXml(runtimeConfig).resolve("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt index 9578a604b5..76f8b58b27 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt @@ -25,7 +25,6 @@ import software.amazon.smithy.model.traits.EventPayloadTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.asType 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.rustlang.rustBlockTemplate @@ -59,23 +58,23 @@ class EventStreamUnmarshallerGenerator( ) { private val unionSymbol = symbolProvider.toSymbol(unionShape) private val errorSymbol = if (target == CodegenTarget.SERVER && unionShape.eventStreamErrors().isEmpty()) { - smithyEventstream(runtimeConfig).member("event_stream::MessageStreamError").toSymbol() + smithyEventstream(runtimeConfig).resolve("event_stream::MessageStreamError").toSymbol() } else { unionShape.eventStreamErrorSymbol(model, symbolProvider, target).toSymbol() } private val eventStreamSerdeModule = RustModule.private("event_stream_serde") private val codegenScope = arrayOf( - "Blob" to smithyTypes(runtimeConfig).member("Blob"), - "Error" to smithyEventstream(runtimeConfig).member("error::Error"), - "expect_fns" to smithyEventstream(runtimeConfig).member("smithy"), - "Header" to smithyEventstream(runtimeConfig).member("frame::Header"), - "HeaderValue" to smithyEventstream(runtimeConfig).member("frame::HeaderValue"), - "Message" to smithyEventstream(runtimeConfig).member("frame::Message"), + "Blob" to smithyTypes(runtimeConfig).resolve("Blob"), + "Error" to smithyEventstream(runtimeConfig).resolve("error::Error"), + "expect_fns" to smithyEventstream(runtimeConfig).resolve("smithy"), + "Header" to smithyEventstream(runtimeConfig).resolve("frame::Header"), + "HeaderValue" to smithyEventstream(runtimeConfig).resolve("frame::HeaderValue"), + "Message" to smithyEventstream(runtimeConfig).resolve("frame::Message"), "OpError" to errorSymbol, - "SmithyError" to smithyTypes(runtimeConfig).member("Error"), + "SmithyError" to smithyTypes(runtimeConfig).resolve("Error"), "tracing" to CargoDependency.Tracing.asType(), - "UnmarshalledMessage" to smithyEventstream(runtimeConfig).member("frame::UnmarshalledMessage"), - "UnmarshallMessage" to smithyEventstream(runtimeConfig).member("frame::UnmarshallMessage"), + "UnmarshalledMessage" to smithyEventstream(runtimeConfig).resolve("frame::UnmarshalledMessage"), + "UnmarshallMessage" to smithyEventstream(runtimeConfig).resolve("frame::UnmarshallMessage"), ) fun render(): RuntimeType { @@ -407,6 +406,6 @@ class EventStreamUnmarshallerGenerator( private fun UnionShape.eventStreamUnmarshallerType(): RuntimeType { val symbol = symbolProvider.toSymbol(this) - return RuntimeType("${symbol.name.toPascalCase()}Unmarshaller", null, "crate::event_stream_serde") + return RuntimeType("crate::event_stream_serde::${symbol.name.toPascalCase()}Unmarshaller") } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt index 4176fd8e37..3f8710fd35 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt @@ -63,25 +63,25 @@ class JsonParserGenerator( private val symbolProvider = codegenContext.symbolProvider private val runtimeConfig = codegenContext.runtimeConfig private val target = codegenContext.target - private val smithyJsonDeser = smithyJson(runtimeConfig).member("deserialize") + private val smithyJsonDeser = smithyJson(runtimeConfig).resolve("deserialize") private val jsonDeserModule = RustModule.private("json_deser") private val typeConversionGenerator = TypeConversionGenerator(model, symbolProvider, runtimeConfig) private val codegenScope = arrayOf( - "Error" to smithyJsonDeser.member("Error"), - "ErrorReason" to smithyJsonDeser.member("ErrorReason"), - "expect_blob_or_null" to smithyJsonDeser.member("token::expect_blob_or_null"), - "expect_bool_or_null" to smithyJsonDeser.member("token::expect_bool_or_null"), - "expect_document" to smithyJsonDeser.member("token::expect_document"), - "expect_number_or_null" to smithyJsonDeser.member("token::expect_number_or_null"), - "expect_start_array" to smithyJsonDeser.member("token::expect_start_array"), - "expect_start_object" to smithyJsonDeser.member("token::expect_start_object"), - "expect_string_or_null" to smithyJsonDeser.member("token::expect_string_or_null"), - "expect_timestamp_or_null" to smithyJsonDeser.member("token::expect_timestamp_or_null"), - "json_token_iter" to smithyJsonDeser.member("json_token_iter"), - "Peekable" to RuntimeType.std.member("iter::Peekable"), - "skip_value" to smithyJsonDeser.member("token::skip_value"), - "skip_to_end" to smithyJsonDeser.member("token::skip_to_end"), - "Token" to smithyJsonDeser.member("Token"), + "Error" to smithyJsonDeser.resolve("Error"), + "ErrorReason" to smithyJsonDeser.resolve("ErrorReason"), + "expect_blob_or_null" to smithyJsonDeser.resolve("token::expect_blob_or_null"), + "expect_bool_or_null" to smithyJsonDeser.resolve("token::expect_bool_or_null"), + "expect_document" to smithyJsonDeser.resolve("token::expect_document"), + "expect_number_or_null" to smithyJsonDeser.resolve("token::expect_number_or_null"), + "expect_start_array" to smithyJsonDeser.resolve("token::expect_start_array"), + "expect_start_object" to smithyJsonDeser.resolve("token::expect_start_object"), + "expect_string_or_null" to smithyJsonDeser.resolve("token::expect_string_or_null"), + "expect_timestamp_or_null" to smithyJsonDeser.resolve("token::expect_timestamp_or_null"), + "json_token_iter" to smithyJsonDeser.resolve("json_token_iter"), + "Peekable" to RuntimeType.std.resolve("iter::Peekable"), + "skip_value" to smithyJsonDeser.resolve("token::skip_value"), + "skip_to_end" to smithyJsonDeser.resolve("token::skip_to_end"), + "Token" to smithyJsonDeser.resolve("Token"), "or_empty" to orEmptyJson(), ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt index 215276901a..5c6172e941 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt @@ -97,14 +97,14 @@ class XmlBindingTraitParserGenerator( private val symbolProvider = codegenContext.symbolProvider private val runtimeConfig = codegenContext.runtimeConfig - private val xmlError = smithyXml(runtimeConfig).member("decode::XmlError") + private val xmlError = smithyXml(runtimeConfig).resolve("decode::XmlError") private val codegenScope = arrayOf( "Blob" to RuntimeType.blob(runtimeConfig), - "Document" to smithyXml(runtimeConfig).member("decode::Document"), + "Document" to smithyXml(runtimeConfig).resolve("decode::Document"), "XmlError" to xmlError, - "next_start_element" to smithyXml(runtimeConfig).member("decode::next_start_element"), - "try_data" to smithyXml(runtimeConfig).member("decode::try_data"), - "ScopedDecoder" to smithyXml(runtimeConfig).member("decode::ScopedDecoder"), + "next_start_element" to smithyXml(runtimeConfig).resolve("decode::next_start_element"), + "try_data" to smithyXml(runtimeConfig).resolve("decode::try_data"), + "ScopedDecoder" to smithyXml(runtimeConfig).resolve("decode::ScopedDecoder"), "aws_smithy_types" to smithyTypes(runtimeConfig), ) private val model = codegenContext.model diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt index 604e5eee9d..0d57acff6c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt @@ -8,15 +8,12 @@ package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.MemberShape -import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EventHeaderTrait import software.amazon.smithy.model.traits.EventPayloadTrait -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.render 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.rustlang.rustBlockTemplate @@ -25,6 +22,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyEventstream +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.generators.error.eventStreamErrorSymbol import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant @@ -46,20 +44,19 @@ class EventStreamErrorMarshallerGenerator( private val serializerGenerator: StructuredDataSerializerGenerator, payloadContentType: String, ) : EventStreamMarshallerGenerator(model, target, runtimeConfig, symbolProvider, unionShape, serializerGenerator, payloadContentType) { - private val smithyEventStream = CargoDependency.smithyEventstream(runtimeConfig) private val operationErrorSymbol = if (target == CodegenTarget.SERVER && unionShape.eventStreamErrors().isEmpty()) { - RuntimeType("MessageStreamError", smithyEventStream, "aws_smithy_http::event_stream").toSymbol() + smithyHttp(runtimeConfig).resolve("event_stream::MessageStreamError") } else { - unionShape.eventStreamErrorSymbol(model, symbolProvider, target).toSymbol() + unionShape.eventStreamErrorSymbol(model, symbolProvider, target) } private val eventStreamSerdeModule = RustModule.private("event_stream_serde") private val errorsShape = unionShape.expectTrait() private val codegenScope = arrayOf( - "MarshallMessage" to smithyEventstream(runtimeConfig).member("frame::MarshallMessage"), - "Message" to smithyEventstream(runtimeConfig).member("frame::Message"), - "Header" to smithyEventstream(runtimeConfig).member("frame::Header"), - "HeaderValue" to smithyEventstream(runtimeConfig).member("frame::HeaderValue"), - "Error" to smithyEventstream(runtimeConfig).member("error::Error"), + "MarshallMessage" to smithyEventstream(runtimeConfig).resolve("frame::MarshallMessage"), + "Message" to smithyEventstream(runtimeConfig).resolve("frame::Message"), + "Header" to smithyEventstream(runtimeConfig).resolve("frame::Header"), + "HeaderValue" to smithyEventstream(runtimeConfig).resolve("frame::HeaderValue"), + "Error" to smithyEventstream(runtimeConfig).resolve("error::Error"), ) override fun render(): RuntimeType { @@ -90,7 +87,7 @@ class EventStreamErrorMarshallerGenerator( "impl #{MarshallMessage} for ${marshallerType.name}", *codegenScope, ) { - rust("type Input = ${operationErrorSymbol.rustType().render(fullyQualified = true)};") + rust("type Input = #T;", operationErrorSymbol) rustBlockTemplate( "fn marshall(&self, _input: Self::Input) -> std::result::Result<#{Message}, #{Error}>", @@ -106,7 +103,7 @@ class EventStreamErrorMarshallerGenerator( rust("let payload = Vec::new();") } else { rustBlock("let payload = match _input$kind") { - val symbol = operationErrorSymbol + val symbol = operationErrorSymbol.fullyQualifiedName() val errorName = when (target) { CodegenTarget.CLIENT -> "${symbol}Kind" CodegenTarget.SERVER -> "$symbol" @@ -138,7 +135,7 @@ class EventStreamErrorMarshallerGenerator( } } - fun RustWriter.renderMarshallEvent(unionMember: MemberShape, eventStruct: StructureShape) { + private fun RustWriter.renderMarshallEvent(unionMember: MemberShape, eventStruct: StructureShape) { val headerMembers = eventStruct.members().filter { it.hasTrait() } val payloadMember = eventStruct.members().firstOrNull { it.hasTrait() } for (member in headerMembers) { @@ -161,11 +158,6 @@ class EventStreamErrorMarshallerGenerator( private fun UnionShape.eventStreamMarshallerType(): RuntimeType { val symbol = symbolProvider.toSymbol(this) - return RuntimeType("${symbol.name.toPascalCase()}ErrorMarshaller", null, "crate::event_stream_serde") - } - - private fun OperationShape.eventStreamMarshallerType(): RuntimeType { - val symbol = symbolProvider.toSymbol(this) - return RuntimeType("${symbol.name.toPascalCase()}ErrorMarshaller", null, "crate::event_stream_serde") + return RuntimeType("crate::event_stream_serde::${symbol.name.toPascalCase()}ErrorMarshaller") } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt index 714c70d0be..f4177db496 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt @@ -55,11 +55,11 @@ open class EventStreamMarshallerGenerator( ) { private val eventStreamSerdeModule = RustModule.private("event_stream_serde") private val codegenScope = arrayOf( - "MarshallMessage" to smithyEventstream(runtimeConfig).member("frame::MarshallMessage"), - "Message" to smithyEventstream(runtimeConfig).member("frame::Message"), - "Header" to smithyEventstream(runtimeConfig).member("frame::Header"), - "HeaderValue" to smithyEventstream(runtimeConfig).member("frame::HeaderValue"), - "Error" to smithyEventstream(runtimeConfig).member("error::Error"), + "MarshallMessage" to smithyEventstream(runtimeConfig).resolve("frame::MarshallMessage"), + "Message" to smithyEventstream(runtimeConfig).resolve("frame::Message"), + "Header" to smithyEventstream(runtimeConfig).resolve("frame::Header"), + "HeaderValue" to smithyEventstream(runtimeConfig).resolve("frame::HeaderValue"), + "Error" to smithyEventstream(runtimeConfig).resolve("error::Error"), ) open fun render(): RuntimeType { @@ -249,6 +249,6 @@ open class EventStreamMarshallerGenerator( private fun UnionShape.eventStreamMarshallerType(): RuntimeType { val symbol = symbolProvider.toSymbol(this) - return RuntimeType("${symbol.name.toPascalCase()}Marshaller", null, "crate::event_stream_serde") + return RuntimeType("crate::event_stream_serde::${symbol.name.toPascalCase()}Marshaller") } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt index 1c143b3160..6f32eaab7d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt @@ -160,10 +160,10 @@ class JsonSerializerGenerator( private val codegenScope = arrayOf( "ByteSlab" to RuntimeType.ByteSlab, "Error" to runtimeConfig.serializationError(), - "JsonObjectWriter" to smithyJson(runtimeConfig).member("serialize::JsonObjectWriter"), - "JsonValueWriter" to smithyJson(runtimeConfig).member("serialize::JsonValueWriter"), - "Number" to smithyTypes(runtimeConfig).member("Number"), - "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), + "JsonObjectWriter" to smithyJson(runtimeConfig).resolve("serialize::JsonObjectWriter"), + "JsonValueWriter" to smithyJson(runtimeConfig).resolve("serialize::JsonValueWriter"), + "Number" to smithyTypes(runtimeConfig).resolve("Number"), + "SdkBody" to smithyHttp(runtimeConfig).resolve("body::SdkBody"), "String" to RuntimeType.String, ) private val serializerUtil = SerializerUtil(model) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt index 6d66a48727..30b91aa8af 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt @@ -98,9 +98,9 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct private val codegenScope = arrayOf( "String" to RuntimeType.String, "Error" to serializerError, - "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), - "QueryWriter" to smithyQuery(runtimeConfig).member("QueryWriter"), - "QueryValueWriter" to smithyQuery(runtimeConfig).member("QueryValueWriter"), + "SdkBody" to smithyHttp(runtimeConfig).resolve("body::SdkBody"), + "QueryWriter" to smithyQuery(runtimeConfig).resolve("QueryWriter"), + "QueryValueWriter" to smithyQuery(runtimeConfig).resolve("QueryValueWriter"), ) private val operationSerModule = RustModule.private("operation_ser") private val querySerModule = RustModule.private("query_ser") @@ -218,7 +218,7 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct } rust( "$writer.number(##[allow(clippy::useless_conversion)]#T::$numberType((${value.asValue()}).into()));", - smithyTypes(runtimeConfig).member("Number"), + smithyTypes(runtimeConfig).resolve("Number"), ) } is BlobShape -> rust( diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt index d5fc2fdc7b..cac0dfed4a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt @@ -66,9 +66,9 @@ class XmlBindingTraitSerializerGenerator( private val target = codegenContext.target private val codegenScope = arrayOf( - "XmlWriter" to smithyXml(runtimeConfig).member("encode::XmlWriter"), - "ElementWriter" to smithyXml(runtimeConfig).member("encode::ElWriter"), - "SdkBody" to smithyHttp(runtimeConfig).member("body::SdkBody"), + "XmlWriter" to smithyXml(runtimeConfig).resolve("encode::XmlWriter"), + "ElementWriter" to smithyXml(runtimeConfig).resolve("encode::ElWriter"), + "SdkBody" to smithyHttp(runtimeConfig).resolve("body::SdkBody"), "Error" to runtimeConfig.serializationError(), ) private val operationSerModule = RustModule.private("operation_ser") @@ -296,7 +296,7 @@ class XmlBindingTraitSerializerGenerator( is BooleanShape, is NumberShape -> { rust( "#T::from(${autoDeref(input)}).encode()", - smithyTypes(runtimeConfig).member("primitive::Encoder"), + smithyTypes(runtimeConfig).resolve("primitive::Encoder"), ) } is BlobShape -> rust("#T($input.as_ref()).as_ref()", RuntimeType.base64Encode(runtimeConfig)) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt index f5f08e9076..c98925c423 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt @@ -16,7 +16,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenericsTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenericsTest.kt index 87004473c4..a8eb41353f 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenericsTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenericsTest.kt @@ -125,5 +125,5 @@ class RustGenericsTest { } } - private fun testRT(name: String): RuntimeType = RuntimeType(name, null, "test") + private fun testRT(name: String): RuntimeType = RuntimeType("test::$name") } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt index f77fc8d029..038c54c4cf 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt @@ -26,7 +26,7 @@ class RustWriterTest { @Test fun `inner modules correctly handle dependencies`() { val sut = RustWriter.forModule("parent") - val requestBuilder = Http.asType().member("request::Builder") + val requestBuilder = Http.asType().resolve("request::Builder") sut.withModule(RustModule.public("inner")) { rustBlock("fn build(builder: #T)", requestBuilder) { } @@ -58,11 +58,11 @@ class RustWriterTest { } val output = sut.toString() output.shouldCompile() - output shouldContain RustType.HashSet.Type + output shouldContain RustType.HashSet.RuntimeType.name output shouldContain "struct Test" output.compileAndRun( """ - let test = Test { member: ${RustType.HashSet.Namespace}::${RustType.HashSet.Type}::default(), otherMember: "hello".to_string() }; + let test = Test { member: ${RustType.HashSet.RuntimeType.namespace}::${RustType.HashSet.RuntimeType.name}::default(), otherMember: "hello".to_string() }; assert_eq!(test.otherMember, "hello"); assert_eq!(test.member.is_empty(), true); """, @@ -155,7 +155,7 @@ class RustWriterTest { sut.rustTemplate( "inner: #{Inner:W}, regular: #{http}", "Inner" to inner, - "http" to Http.asType().member("foo"), + "http" to Http.asType().resolve("foo"), ) sut.toString().shouldContain("inner: hello, regular: http::foo") } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/WritableTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/WritableTest.kt index 67419a5728..1939606ffe 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/WritableTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/WritableTest.kt @@ -26,14 +26,13 @@ internal class RustTypeParametersTest { @Test fun `rustTypeParameters accepts Symbol`() { - val symbol = RuntimeType("Operation", namespace = "crate::operation", dependency = null).toSymbol() + val symbol = RuntimeType("crate::operation::Operation").toSymbol() forInputExpectOutput(symbol, "''") } @Test fun `rustTypeParameters accepts RuntimeType`() { - val runtimeType = RuntimeType("String", namespace = "std::string", dependency = null) - forInputExpectOutput(runtimeType, "''") + forInputExpectOutput(RuntimeType.String, "''") } @Test @@ -50,9 +49,9 @@ internal class RustTypeParametersTest { fun `rustTypeParameters accepts heterogeneous inputs`() { val writer = RustWriter.forModule("model") val tps = rustTypeParameters( - RuntimeType("Operation", namespace = "crate::operation", dependency = null).toSymbol(), + RuntimeType("crate::operation::Operation").toSymbol(), RustType.Unit, - RuntimeType("String", namespace = "std::string", dependency = null), + RuntimeType.String, "T", RustGenerics(GenericTypeArg("A"), GenericTypeArg("B")), ) diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt index 57b869094e..a719430c8e 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt @@ -14,7 +14,6 @@ import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http 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.asType 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.operationBuildError @@ -145,11 +144,11 @@ class RequestBindingGeneratorTest { rustBlock( "pub fn test_request_builder_base(&self) -> Result<#T, #T>", - Http.asType().member("request::Builder"), + Http.asType().resolve("request::Builder"), TestRuntimeConfig.operationBuildError(), ) { bindingGen.renderUpdateHttpBuilder(this) - rust("let builder = #T::new();", Http.asType().member("request::Builder")) + rust("let builder = #T::new();", Http.asType().resolve("request::Builder")) rust("update_http_builder(self, builder)") } } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt index f81cfed731..12ce3c4e63 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt @@ -10,7 +10,6 @@ import software.amazon.smithy.model.traits.DocumentationTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http 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.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate @@ -182,8 +181,8 @@ class PythonApplicationGenerator( """ fn build_service(&mut self, event_loop: &#{pyo3}::PyAny) -> #{pyo3}::PyResult< #{tower}::util::BoxCloneService< - #{http}::Request<#{SmithyServer}::body::Body>, - #{http}::Response<#{SmithyServer}::body::BoxBody>, + #{http}::Request<#{SmithyServer}::body::Body>, + #{http}::Response<#{SmithyServer}::body::BoxBody>, std::convert::Infallible > > diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt index 53d4713aa0..138d66ae17 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt @@ -10,7 +10,6 @@ import software.amazon.smithy.model.knowledge.OperationIndex import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType 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.rustlang.writable diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt index b804d12bbb..9f8907fd18 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt @@ -11,7 +11,6 @@ import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType 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.rustlang.rustTemplate diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt index b8b361d04a..5f3816eeca 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt @@ -12,7 +12,6 @@ import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.Shape 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.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.smithy.RustCrate diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt index 27b3d87d30..33ed2e232d 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt @@ -8,7 +8,6 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.generators import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt index faea82110b..9a4a0b82ea 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt @@ -13,7 +13,6 @@ import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.render import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt index 3a03931c2a..de1c00924b 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt @@ -8,6 +8,7 @@ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency.smithyHttpServer /** * Object used *exclusively* in the runtime of the server, for separation concerns. @@ -15,32 +16,20 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType * For a runtime type that is used in the client, or in both the client and the server, use [RuntimeType] directly. */ object ServerRuntimeType { - fun forInlineDependency(inlineDependency: InlineDependency) = - RuntimeType(inlineDependency.name, inlineDependency, namespace = "crate") + private fun forInlineDependency(inlineDependency: InlineDependency) = RuntimeType.forInlineDependency(inlineDependency) - val Phantom = RuntimeType("PhantomData", dependency = null, namespace = "std::marker") - val Cow = RuntimeType("Cow", dependency = null, namespace = "std::borrow") + fun Router(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("routing::Router") - fun Router(runtimeConfig: RuntimeConfig) = - RuntimeType("Router", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::routing") - - fun RequestSpecModule(runtimeConfig: RuntimeConfig) = - RuntimeType("request_spec", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::routing") + fun RequestSpecModule(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("routing::request_spec") fun OperationHandler(runtimeConfig: RuntimeConfig) = forInlineDependency(ServerInlineDependency.serverOperationHandler(runtimeConfig)) - fun RuntimeError(runtimeConfig: RuntimeConfig) = - RuntimeType("RuntimeError", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::runtime_error") - - fun RequestRejection(runtimeConfig: RuntimeConfig) = - RuntimeType("RequestRejection", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::rejection") + fun RuntimeError(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("runtime_error::RuntimeError") - fun ResponseRejection(runtimeConfig: RuntimeConfig) = - RuntimeType("ResponseRejection", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::rejection") + fun RequestRejection(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("rejection::RequestRejection") - fun Protocol(name: String, path: String, runtimeConfig: RuntimeConfig) = - RuntimeType(name, ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::proto::" + path) + fun ResponseRejection(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("rejection::ResponseRejection") - fun Protocol(runtimeConfig: RuntimeConfig) = Protocol("Protocol", "", runtimeConfig) + fun Protocol(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("proto") } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt index bdf9432859..fa3f5c295a 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt @@ -19,7 +19,6 @@ import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.SensitiveTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.plus import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt index ee049222e6..262ff39e57 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt @@ -8,7 +8,6 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.documentShape import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt index e06437fb53..e32ea29f9b 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt @@ -8,11 +8,11 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Http import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.smithyHttp import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol import software.amazon.smithy.rust.codegen.core.smithy.transformers.operationErrors @@ -43,7 +43,7 @@ open class ServerOperationHandlerGenerator( "FuturesUtil" to ServerCargoDependency.FuturesUtil.asType(), "SmithyHttp" to smithyHttp(runtimeConfig), "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), - "Phantom" to ServerRuntimeType.Phantom, + "Phantom" to RuntimeType.Phantom, "ServerOperationHandler" to ServerRuntimeType.OperationHandler(runtimeConfig), "http" to Http.asType(), ) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt index 928dc6d396..120bc09afd 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt @@ -13,7 +13,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType 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.rustlang.rustBlockTemplate @@ -64,7 +63,7 @@ class ServerOperationRegistryGenerator( "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), "ServerOperationHandler" to ServerRuntimeType.OperationHandler(runtimeConfig), "Tower" to Tower.asType(), - "Phantom" to ServerRuntimeType.Phantom, + "Phantom" to RuntimeType.Phantom, "StdError" to RuntimeType.StdError, "Display" to RuntimeType.Display, "From" to RuntimeType.From, @@ -401,6 +400,6 @@ ${operationImplementationStubs(operations)} this, symbolProvider.toSymbol(this).name, serviceName, - ServerCargoDependency.smithyHttpServer(runtimeConfig).asType().member("routing::request_spec"), + ServerRuntimeType.RequestSpecModule(runtimeConfig), ) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt index 899902a2f7..f44bb99818 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt @@ -12,7 +12,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Compani import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.documentShape import software.amazon.smithy.rust.codegen.core.rustlang.join import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -32,7 +31,7 @@ class ServerServiceGeneratorV2( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( - "Bytes" to Bytes.asType().member("Bytes"), + "Bytes" to Bytes.asType().resolve("Bytes"), "Http" to Http.asType(), "HttpBody" to HttpBody.asType(), "SmithyHttpServer" to @@ -340,7 +339,7 @@ class ServerServiceGeneratorV2( impl #{Tower}::Service<#{Http}::Request> for $serviceName where S: #{Tower}::Service<#{Http}::Request, Response = #{Http}::Response> + Clone, - RespB: #{HttpBody}::Body + Send + 'static, + RespB: #{HttpBody}::Body + Send + 'static, RespB::Error: Into> { type Response = #{Http}::Response<#{SmithyHttpServer}::body::BoxBody>; diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt index ebfc0a0cc3..4f6550d6dc 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt @@ -8,7 +8,6 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators.protocol import software.amazon.smithy.model.knowledge.TopDownIndex import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType 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.rustlang.writable @@ -93,21 +92,24 @@ class ServerAwsJsonProtocol( ServerAwsJsonSerializerGenerator(codegenContext, httpBindingResolver, awsJsonVersion) companion object { - fun fromCoreProtocol(awsJson: AwsJson): ServerAwsJsonProtocol = ServerAwsJsonProtocol(awsJson.codegenContext, awsJson.version) + fun fromCoreProtocol(awsJson: AwsJson): ServerAwsJsonProtocol = + ServerAwsJsonProtocol(awsJson.codegenContext, awsJson.version) } override fun markerStruct(): RuntimeType { return when (version) { is AwsJsonVersion.Json10 -> { - ServerRuntimeType.Protocol("AwsJson1_0", "aws_json_10", runtimeConfig) + ServerRuntimeType.Protocol(runtimeConfig).resolve("aws_json_10::AwsJson1_0") } + is AwsJsonVersion.Json11 -> { - ServerRuntimeType.Protocol("AwsJson1_1", "aws_json_11", runtimeConfig) + ServerRuntimeType.Protocol(runtimeConfig).resolve("aws_json_11::AwsJson1_1") } } } - override fun routerType() = RuntimeType("AwsJsonRouter", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::proto::aws_json::router") + override fun routerType() = + ServerRuntimeType.Protocol(runtimeConfig).resolve("aws_json::router::AwsJsonRouter") override fun routerConstruction(operationValues: Iterable): Writable = writable { val allOperationShapes = allOperations(codegenContext) @@ -158,13 +160,15 @@ class ServerAwsJsonProtocol( } } -private fun restRouterType(runtimeConfig: RuntimeConfig) = RuntimeType("RestRouter", ServerCargoDependency.smithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server::proto::rest::router") +private fun restRouterType(runtimeConfig: RuntimeConfig) = + ServerRuntimeType.Protocol(runtimeConfig).resolve("rest::router::RestRouter") private fun restRouterConstruction( protocol: ServerProtocol, operationValues: Iterable, codegenContext: CodegenContext, ): Writable = writable { + val runtimeConfig = codegenContext.runtimeConfig val operations = allOperations(codegenContext) // TODO(https://github.com/awslabs/smithy-rs/issues/1724#issue-1367509999): This causes a panic: "symbol visitor @@ -178,7 +182,7 @@ private fun restRouterConstruction( operationShape, operationName, serviceName, - ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).asType().member("routing::request_spec"), + ServerRuntimeType.RequestSpecModule(runtimeConfig), ) rustTemplate( """ @@ -189,7 +193,7 @@ private fun restRouterConstruction( """, "Key" to key, "OperationValue" to operationValue, - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), ) } } @@ -208,14 +212,16 @@ class ServerRestJsonProtocol( val runtimeConfig = codegenContext.runtimeConfig companion object { - fun fromCoreProtocol(restJson: RestJson): ServerRestJsonProtocol = ServerRestJsonProtocol(restJson.codegenContext) + fun fromCoreProtocol(restJson: RestJson): ServerRestJsonProtocol = + ServerRestJsonProtocol(restJson.codegenContext) } - override fun markerStruct() = ServerRuntimeType.Protocol("RestJson1", "rest_json_1", runtimeConfig) + override fun markerStruct() = ServerRuntimeType.Protocol(runtimeConfig).resolve("rest_json_1::RestJson1") override fun routerType() = restRouterType(runtimeConfig) - override fun routerConstruction(operationValues: Iterable): Writable = restRouterConstruction(this, operationValues, codegenContext) + override fun routerConstruction(operationValues: Iterable): Writable = + restRouterConstruction(this, operationValues, codegenContext) override fun serverRouterRequestSpec( operationShape: OperationShape, @@ -240,11 +246,12 @@ class ServerRestXmlProtocol( } } - override fun markerStruct() = ServerRuntimeType.Protocol("RestXml", "rest_xml", runtimeConfig) + override fun markerStruct() = ServerRuntimeType.Protocol(runtimeConfig).resolve("rest_xml::RestXml") override fun routerType() = restRouterType(runtimeConfig) - override fun routerConstruction(operationValues: Iterable): Writable = restRouterConstruction(this, operationValues, codegenContext) + override fun routerConstruction(operationValues: Iterable): Writable = + restRouterConstruction(this, operationValues, codegenContext) override fun serverRouterRequestSpec( operationShape: OperationShape, diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt index 32d8c0e421..37fa5b5180 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt @@ -34,7 +34,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords 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.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.escape import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock @@ -96,7 +95,7 @@ class ServerProtocolTestGenerator( val outputT = if (it.errors.isEmpty()) { t } else { - val errorType = RuntimeType("${operationSymbol.name}Error", null, "crate::error") + val errorType = RuntimeType("crate::error::${operationSymbol.name}Error") val e = errorType.fullyQualifiedName() "Result<$t, $e>" } @@ -107,14 +106,14 @@ class ServerProtocolTestGenerator( private val instantiator = serverInstantiator(codegenContext) private val codegenScope = arrayOf( - "Bytes" to Bytes.asType().member("Bytes"), + "Bytes" to Bytes.asType().resolve("Bytes"), "SmithyHttp" to smithyHttp(codegenContext.runtimeConfig), "Http" to Http.asType(), "Hyper" to Hyper.asType(), "Tokio" to ServerCargoDependency.TokioDev.asType(), "Tower" to Tower.asType(), "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).asType(), - "AssertEq" to PrettyAssertions.asType().member("assert_eq!"), + "AssertEq" to PrettyAssertions.asType().resolve("assert_eq!"), "Router" to ServerRuntimeType.Router(codegenContext.runtimeConfig), ) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt index e365d8f482..a83c2b4b51 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt @@ -31,7 +31,6 @@ 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.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.conditionalBlock import software.amazon.smithy.rust.codegen.core.rustlang.render import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -132,11 +131,11 @@ private class ServerHttpBoundProtocolTraitImplGenerator( private val codegenScope = arrayOf( "AsyncTrait" to ServerCargoDependency.AsyncTrait.asType(), - "Cow" to ServerRuntimeType.Cow, + "Cow" to RuntimeType.Cow, "DateTime" to RuntimeType.dateTime(runtimeConfig), "FormUrlEncoded" to ServerCargoDependency.FormUrlEncoded.asType(), "HttpBody" to CargoDependency.HttpBody.asType(), - "header_util" to smithyHttp(runtimeConfig).member("header"), + "header_util" to smithyHttp(runtimeConfig).resolve("header"), "Hyper" to CargoDependency.Hyper.asType(), "LazyStatic" to CargoDependency.LazyStatic.asType(), "Mime" to ServerCargoDependency.Mime.asType(), @@ -1036,7 +1035,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( else -> { // Number or boolean. rust( "let v = <_ as #T>::parse_smithy_primitive(&v)?;", - smithyTypes(runtimeConfig).member("primitive::Parse"), + smithyTypes(runtimeConfig).resolve("primitive::Parse"), ) } } @@ -1216,12 +1215,12 @@ private class ServerHttpBoundProtocolTraitImplGenerator( if (model.expectShape(binding.member.target) is StringShape) { return ServerRuntimeType.RequestRejection(runtimeConfig) } - when (codegenContext.protocol) { + return when (codegenContext.protocol) { RestJson1Trait.ID, AwsJson1_0Trait.ID, AwsJson1_1Trait.ID -> { - return smithyJson(runtimeConfig).member("deserialize").member("Error") + smithyJson(runtimeConfig).resolve("deserialize::Error") } RestXmlTrait.ID -> { - return smithyXml(runtimeConfig).member("decode").member("XmlError") + smithyXml(runtimeConfig).resolve("decode::XmlError") } else -> { TODO("Protocol ${codegenContext.protocol} not supported yet") diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt index 1353d119fe..afc080aed9 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt @@ -9,7 +9,6 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt index 6b8638df69..ec2d8d8cae 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt @@ -47,8 +47,10 @@ class EventStreamMarshallerGeneratorTest { ) test.project.lib { - val protocolTestHelpers = CargoDependency.smithyProtocolTestHelpers(TestRuntimeConfig) + val protocolTestHelpers = CargoDependency + .smithyProtocolTestHelpers(TestRuntimeConfig) .copy(scope = DependencyScope.Compile) + .asType() rustTemplate( """ use aws_smithy_eventstream::frame::{Message, Header, HeaderValue, MarshallMessage}; @@ -72,8 +74,8 @@ class EventStreamMarshallerGeneratorTest { HeaderValue::String(value.into()) } """, - "validate_body" to protocolTestHelpers.rustName("validate_body"), - "MediaType" to protocolTestHelpers.rustName("MediaType"), + "validate_body" to protocolTestHelpers.resolve("validate_body"), + "MediaType" to protocolTestHelpers.resolve("MediaType"), ) unitTest( From 1c95fb7552d0a8a781f8ed4903a355b2689968cf Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Wed, 9 Nov 2022 17:00:35 -0600 Subject: [PATCH 17/19] fix: outdated RuntimeType usage format: run `pre-commit run --all-files` --- aws/SDK_CHANGELOG.next.json | 2 +- aws/sdk/build.gradle.kts | 2 +- .../smithy/customizations/ClientDocsGenerator.kt | 14 +++++++------- .../smithy/generators/NestedAccessorGenerator.kt | 10 +++++----- .../smithy/generators/ClientInstantiatorTest.kt | 6 +++--- .../core/smithy/generators/InstantiatorTest.kt | 6 +++--- .../python/smithy/PythonServerRuntimeType.kt | 16 ++++++---------- .../smithy/generators/ServerInstantiatorTest.kt | 10 +++++----- .../examples/pokemon_service.py | 6 +++--- 9 files changed, 34 insertions(+), 38 deletions(-) diff --git a/aws/SDK_CHANGELOG.next.json b/aws/SDK_CHANGELOG.next.json index 9fb8b3ef9d..08ffbf6682 100644 --- a/aws/SDK_CHANGELOG.next.json +++ b/aws/SDK_CHANGELOG.next.json @@ -341,4 +341,4 @@ } ], "aws-sdk-model": [] -} \ No newline at end of file +} diff --git a/aws/sdk/build.gradle.kts b/aws/sdk/build.gradle.kts index fe8766babe..a8c248cdc6 100644 --- a/aws/sdk/build.gradle.kts +++ b/aws/sdk/build.gradle.kts @@ -399,7 +399,7 @@ project.registerGenerateCargoConfigTomlTask(outputDir) tasks["test"].finalizedBy( Cargo.CHECK.toString, Cargo.TEST.toString, - Cargo.DOCS.toString + Cargo.DOCS.toString, ) tasks.register("deleteSdk") { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt index adfb3b8721..8b8d419ad0 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt @@ -25,16 +25,16 @@ class ClientDocsGenerator : LibRsCustomization() { writable { containerDocs( """ - The entry point for most customers will be [`Client`]. [`Client`] exposes one method for each API offered - by the service. + The entry point for most customers will be [`Client`]. [`Client`] exposes one method for each API offered + by the service. - Some APIs require complex or nested arguments. These exist in [`model`](crate::model). + Some APIs require complex or nested arguments. These exist in [`model`](crate::model). - Lastly, errors that can be returned by the service are contained within [`error`]. [`Error`] defines a meta - error encompassing all possible errors that can be returned by the service. + Lastly, errors that can be returned by the service are contained within [`error`]. [`Error`] defines a meta + error encompassing all possible errors that can be returned by the service. - The other modules within this crate are not required for normal usage. - """.trimEnd(), + The other modules within this crate are not required for normal usage. + """.trimEnd(), ) } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt index 8b7672fe8f..7348293c73 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt @@ -79,11 +79,11 @@ class NestedAccessorGenerator(private val symbolProvider: RustSymbolProvider) { if (symbolProvider.toSymbol(head).isOptional()) { rust( """ - let input = match ${ref}input.${symbolProvider.toMemberName(head)} { - None => return None, - Some(t) => t - }; - """, + let input = match ${ref}input.${symbolProvider.toMemberName(head)} { + None => return None, + Some(t) => t + }; + """, ) } else { rust("let input = input.${symbolProvider.toMemberName(head)};") diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiatorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiatorTest.kt index e55f98c0d3..f507ba2d4c 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiatorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiatorTest.kt @@ -24,13 +24,13 @@ import software.amazon.smithy.rust.codegen.core.util.lookup internal class ClientInstantiatorTest { private val model = """ namespace com.test - + @enum([ { value: "t2.nano" }, { value: "t2.micro" }, ]) string UnnamedEnum - + @enum([ { value: "t2.nano", @@ -42,7 +42,7 @@ internal class ClientInstantiatorTest { }, ]) string NamedEnum - """.asSmithyModel() + """.asSmithyModel() private val codegenContext = testCodegenContext(model) private val symbolProvider = codegenContext.symbolProvider diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt index 73dbe86d5b..9dc1e0592d 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt @@ -31,7 +31,7 @@ import software.amazon.smithy.rust.codegen.core.util.lookup class InstantiatorTest { private val model = """ namespace com.test - + @documentation("this documents the shape") structure MyStruct { foo: String, @@ -122,8 +122,8 @@ class InstantiatorTest { } rust( """ - assert_eq!(result.bar, 10); - assert_eq!(result.foo.unwrap(), "hello"); + assert_eq!(result.bar, 10); + assert_eq!(result.foo.unwrap(), "hello"); """, ) } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt index 660e87a057..4ef27c3723 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt @@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.server.python.smithy import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency.smithyHttpServerPython /** * Object used *exclusively* in the runtime of the Python server, for separation concerns. @@ -15,18 +16,13 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType */ object PythonServerRuntimeType { - fun PySocket(runtimeConfig: RuntimeConfig) = - RuntimeType("PySocket", PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python") + fun PySocket(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).asType().resolve("PySocket") - fun Blob(runtimeConfig: RuntimeConfig) = - RuntimeType("Blob", PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") + fun Blob(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).asType().resolve("types::Blob") - fun ByteStream(runtimeConfig: RuntimeConfig) = - RuntimeType("ByteStream", PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") + fun ByteStream(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).asType().resolve("types::ByteStream") - fun DateTime(runtimeConfig: RuntimeConfig) = - RuntimeType("DateTime", PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python::types") + fun DateTime(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).asType().resolve("types::DateTime") - fun PyError(runtimeConfig: RuntimeConfig) = - RuntimeType("Error", PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_smithy_http_server_python") + fun PyError(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).asType().resolve("Error") } diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiatorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiatorTest.kt index ae50d8a0a5..945dac55dc 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiatorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiatorTest.kt @@ -31,9 +31,9 @@ class ServerInstantiatorTest { // This model started off from the one in `InstantiatorTest.kt` from `codegen-core`. private val model = """ namespace com.test - + use smithy.framework#ValidationException - + @documentation("this documents the shape") structure MyStruct { foo: String, @@ -83,7 +83,7 @@ class ServerInstantiatorTest { @required num: Integer } - + structure MyStructRequired { @required str: String, @@ -106,13 +106,13 @@ class ServerInstantiatorTest { @required doc: Document } - + @enum([ { value: "t2.nano" }, { value: "t2.micro" }, ]) string UnnamedEnum - + @enum([ { value: "t2.nano", diff --git a/rust-runtime/aws-smithy-http-server-python/examples/pokemon_service.py b/rust-runtime/aws-smithy-http-server-python/examples/pokemon_service.py index 9264b31dcb..23489b7cca 100644 --- a/rust-runtime/aws-smithy-http-server-python/examples/pokemon_service.py +++ b/rust-runtime/aws-smithy-http-server-python/examples/pokemon_service.py @@ -63,9 +63,9 @@ def value(self): # # Synchronization: # Instance of `Context` class will be cloned for every worker and all state kept in `Context` -# will be specific to that process. There is no protection provided by default, -# it is up to you to have synchronization between processes. -# If you really want to share state between different processes you need to use `multiprocessing` primitives: +# will be specific to that process. There is no protection provided by default, +# it is up to you to have synchronization between processes. +# If you really want to share state between different processes you need to use `multiprocessing` primitives: # https://docs.python.org/3/library/multiprocessing.html#sharing-state-between-processes @dataclass class Context: From 7aae03d12b9aae5c7cfe7338abe0413062b3d4fc Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Thu, 10 Nov 2022 09:38:34 -0600 Subject: [PATCH 18/19] rename: `RuntimeType.asType()` to `RuntimeType.toType()` in convention with other conversion methods --- .../smithy/rustsdk/AwsRuntimeDependency.kt | 12 +++++----- .../decorators/AwsFluentClientDecorator.kt | 2 +- .../decorators/AwsPresigningDecorator.kt | 2 +- .../apigateway/ApiGatewayDecorator.kt | 2 +- .../glacier/ApiVersionHeader.kt | 2 +- .../servicedecorators/s3/S3Decorator.kt | 6 ++--- .../smithy/StreamingTraitSymbolProvider.kt | 2 +- .../HttpChecksumRequiredGenerator.kt | 4 ++-- .../smithy/generators/PaginatorGenerator.kt | 2 +- .../client/CustomizableOperationGenerator.kt | 2 +- .../protocol/ProtocolTestGenerator.kt | 8 +++---- .../protocols/HttpBoundProtocolGenerator.kt | 4 ++-- .../protocol/ProtocolTestGeneratorTest.kt | 6 ++--- .../codegen/core/rustlang/CargoDependency.kt | 3 +-- .../rust/codegen/core/smithy/RuntimeType.kt | 20 ++++++++-------- .../error/TopLevelErrorGenerator.kt | 2 +- .../generators/http/HttpBindingGenerator.kt | 12 +++++----- .../http/RequestBindingGenerator.kt | 2 +- .../http/RestRequestSpecGenerator.kt | 2 +- .../protocol/MakeOperationGenerator.kt | 6 ++--- .../codegen/core/smithy/protocols/AwsJson.kt | 6 ++--- .../codegen/core/smithy/protocols/AwsQuery.kt | 6 ++--- .../codegen/core/smithy/protocols/Ec2Query.kt | 6 ++--- .../HttpBoundProtocolPayloadGenerator.kt | 2 +- .../codegen/core/smithy/protocols/RestJson.kt | 6 ++--- .../codegen/core/smithy/protocols/RestXml.kt | 6 ++--- .../parse/EventStreamUnmarshallerGenerator.kt | 2 +- .../rust/codegen/core/testutil/TestHelpers.kt | 2 +- .../codegen/core/rustlang/RustWriterTest.kt | 4 ++-- .../http/RequestBindingGeneratorTest.kt | 4 ++-- .../python/smithy/PythonServerRuntimeType.kt | 10 ++++---- .../generators/PythonApplicationGenerator.kt | 24 +++++++++---------- .../PythonServerCombinedErrorGenerator.kt | 2 +- .../generators/PythonServerEnumGenerator.kt | 2 +- .../generators/PythonServerModuleGenerator.kt | 4 ++-- .../PythonServerOperationHandlerGenerator.kt | 12 +++++----- .../PythonServerStructureGenerator.kt | 2 +- .../server/smithy/ServerRuntimeType.kt | 12 +++++----- .../ServerHttpSensitivityGenerator.kt | 14 +++++------ .../generators/ServerOperationGenerator.kt | 2 +- .../ServerOperationHandlerGenerator.kt | 10 ++++---- .../ServerOperationRegistryGenerator.kt | 8 +++---- .../generators/ServerServiceGeneratorV2.kt | 10 ++++---- .../generators/protocol/ServerProtocol.kt | 4 ++-- .../protocol/ServerProtocolTestGenerator.kt | 14 +++++------ .../ServerHttpBoundProtocolGenerator.kt | 24 +++++++++---------- .../ServerHttpSensitivityGeneratorTest.kt | 4 ++-- .../EventStreamMarshallerGeneratorTest.kt | 2 +- 48 files changed, 152 insertions(+), 153 deletions(-) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt index edb2623666..2fea451419 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt @@ -68,9 +68,9 @@ object AwsRuntimeType { fun RuntimeConfig.awsRuntimeCrate(name: String, features: Set = setOf()): CargoDependency = CargoDependency(name, awsRoot().crateLocation(null), features = features) -fun awsEndpoint(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-endpoint").asType() -fun awsHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-http").asType() -fun awsSigAuth(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sig-auth").asType() -fun awsSigAuthEventStream(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sig-auth", setOf("sign-eventstream")).asType() -fun awsSigv4(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sigv4").asType() -fun awsTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-types").asType() +fun awsEndpoint(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-endpoint").toType() +fun awsHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-http").toType() +fun awsSigAuth(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sig-auth").toType() +fun awsSigAuthEventStream(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sig-auth", setOf("sign-eventstream")).toType() +fun awsSigv4(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sigv4").toType() +fun awsTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-types").toType() diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt index 7ef36167b7..fce62cef93 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsFluentClientDecorator.kt @@ -258,7 +258,7 @@ private class AwsFluentClientDocs(private val codegenContext: CodegenContext) : /// let client = $crateName::Client::from_conf(config); /// ## } """, - "aws_config" to runtimeConfig.awsRuntimeCrate("aws-config").copy(scope = DependencyScope.Dev).asType(), + "aws_config" to runtimeConfig.awsRuntimeCrate("aws-config").copy(scope = DependencyScope.Dev).toType(), ) } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsPresigningDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsPresigningDecorator.kt index 3ca992bf97..7b37e96ede 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsPresigningDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsPresigningDecorator.kt @@ -149,7 +149,7 @@ class AwsInputPresignedMethod( "SdkError" to smithyHttp(runtimeConfig).resolve("result::SdkError"), "aws_sigv4" to awsSigv4(runtimeConfig), "sig_auth" to awsSigAuth(runtimeConfig), - "tower" to Tower.asType(), + "tower" to Tower.toType(), "Middleware" to runtimeConfig.defaultMiddleware(), ) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt index ad7a751587..fe8665596c 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/apigateway/ApiGatewayDecorator.kt @@ -49,7 +49,7 @@ class ApiGatewayAddAcceptHeader : OperationCustomization() { .headers_mut() .insert("Accept", #{HeaderValue}::from_static("application/json")); """, - "HeaderValue" to Http.asType().resolve("HeaderValue"), + "HeaderValue" to Http.toType().resolve("HeaderValue"), ) } else -> emptySection diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt index c4e0527330..a920c969bc 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/glacier/ApiVersionHeader.kt @@ -29,7 +29,7 @@ class ApiVersionHeader( .headers_mut() .insert("x-amz-glacier-version", #{HeaderValue}::from_static(${apiVersion.dq()})); """, - "HeaderValue" to Http.asType().resolve("HeaderValue"), + "HeaderValue" to Http.toType().resolve("HeaderValue"), ) } else -> emptySection diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt index 3c5c02e4da..86293972cf 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/servicedecorators/s3/S3Decorator.kt @@ -91,10 +91,10 @@ class S3Decorator : RustCodegenDecorator::Ok(req) })?; """, - "md5" to Md5.asType(), - "HeaderName" to Http.asType().resolve("header::HeaderName"), + "md5" to Md5.toType(), + "HeaderName" to Http.toType().resolve("header::HeaderName"), "base64_encode" to RuntimeType.base64Encode(codegenContext.runtimeConfig), "BuildError" to codegenContext.runtimeConfig.operationBuildError(), ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt index 2506af89e4..540f1a15e3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt @@ -117,7 +117,7 @@ class PaginatorGenerator private constructor( "fn_stream" to smithyAsync(runtimeConfig).resolve("future::fn_stream"), // External Types - "Stream" to TokioStream.asType().resolve("Stream"), + "Stream" to TokioStream.toType().resolve("Stream"), ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt index d9344b678f..61231b18be 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt @@ -67,7 +67,7 @@ class CustomizableOperationGenerator( // SDK Types "http_result" to smithyHttp(runtimeConfig).resolve("result"), "http_body" to smithyHttp(runtimeConfig).resolve("body"), - "HttpRequest" to Http.asType().resolve("Request"), + "HttpRequest" to Http.toType().resolve("Request"), "handle_generics_decl" to handleGenerics.declaration(), "handle_generics_bounds" to handleGenerics.bounds(), "operation_generics_decl" to operationGenerics.declaration(), diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt index e34d95a29d..203d07bba2 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt @@ -72,7 +72,7 @@ class ProtocolTestGenerator( private val codegenScope = arrayOf( "SmithyHttp" to smithyHttp(runtimeConfig), - "AssertEq" to PrettyAssertions.asType().resolve("assert_eq!"), + "AssertEq" to PrettyAssertions.toType().resolve("assert_eq!"), ) sealed class TestCase { @@ -193,7 +193,7 @@ class ProtocolTestGenerator( ep.set_endpoint(http_request.uri_mut(), parts.acquire().get()); """, "Endpoint" to smithyHttp(runtimeConfig).resolve("endpoint::Endpoint"), - "Uri" to Http.asType().resolve("Uri"), + "Uri" to Http.toType().resolve("Uri"), ) } rustTemplate( @@ -257,7 +257,7 @@ class ProtocolTestGenerator( write("let expected_output =") instantiator.render(this, expectedShape, testCase.params) write(";") - rust("let http_response = #T::new()", Http.asType().resolve("response::Builder")) + rust("let http_response = #T::new()", Http.toType().resolve("response::Builder")) testCase.headers.forEach { (key, value) -> writeWithNoFormatting(".header(${key.dq()}, ${value.dq()})") } @@ -285,7 +285,7 @@ class ProtocolTestGenerator( }); """, "op" to operationSymbol, - "bytes" to Bytes.asType().resolve("Bytes"), + "bytes" to Bytes.toType().resolve("Bytes"), "parse_http_response" to smithyHttp(runtimeConfig).resolve("response::ParseHttpResponse"), ) if (expectedShape.hasTrait()) { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt index 77c76babaa..ed509309d6 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt @@ -79,9 +79,9 @@ class HttpBoundProtocolTraitImplGenerator( private val codegenScope = arrayOf( "ParseStrict" to RuntimeType.parseStrictResponse(runtimeConfig), "ParseResponse" to RuntimeType.parseResponse(runtimeConfig), - "http" to Http.asType(), + "http" to Http.toType(), "operation" to RuntimeType.operationModule(runtimeConfig), - "Bytes" to Bytes.asType().resolve("Bytes"), + "Bytes" to Bytes.toType().resolve("Bytes"), ) override fun generateTraitImpls( diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt index 81b124b4d8..0362feea32 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt @@ -67,8 +67,8 @@ private class TestProtocolTraitImplGenerator( "parse_strict" to RuntimeType.parseStrictResponse(codegenContext.runtimeConfig), "output" to symbolProvider.toSymbol(operationShape.outputShape(codegenContext.model)), "error" to operationShape.errorSymbol(codegenContext.model, symbolProvider, codegenContext.target), - "response" to Http.asType().resolve("Response"), - "bytes" to Bytes.asType().resolve("Bytes"), + "response" to Http.toType().resolve("Response"), + "bytes" to Bytes.toType().resolve("Bytes"), ) } } @@ -86,7 +86,7 @@ private class TestProtocolMakeOperationGenerator( includeDefaultPayloadHeaders = true, ) { override fun createHttpRequest(writer: RustWriter, operationShape: OperationShape) { - writer.rust("#T::new()", Http.asType().resolve("request::Builder")) + writer.rust("#T::new()", Http.toType().resolve("request::Builder")) writer.writeWithNoFormatting(httpRequestBuilder) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt index e748556eb9..2de6b5b3a4 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt @@ -180,8 +180,7 @@ data class CargoDependency( return "$name = { ${attribs.joinToString(",")} }" } - // TODO rename to `toType` to maintain naming convention of the above methods - fun asType(): RuntimeType { + fun toType(): RuntimeType { return RuntimeType(rustName, this) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt index eec4673ea1..8654ce5c41 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt @@ -207,16 +207,16 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null) val Config = RuntimeType("crate::config") // smithy runtime types - fun smithyAsync(runtimeConfig: RuntimeConfig) = CargoDependency.smithyAsync(runtimeConfig).asType() - fun smithyChecksums(runtimeConfig: RuntimeConfig) = CargoDependency.smithyChecksums(runtimeConfig).asType() - fun smithyClient(runtimeConfig: RuntimeConfig) = CargoDependency.smithyClient(runtimeConfig).asType() - fun smithyEventstream(runtimeConfig: RuntimeConfig) = CargoDependency.smithyEventstream(runtimeConfig).asType() - fun smithyHttp(runtimeConfig: RuntimeConfig) = CargoDependency.smithyHttp(runtimeConfig).asType() - fun smithyJson(runtimeConfig: RuntimeConfig) = CargoDependency.smithyJson(runtimeConfig).asType() - fun smithyQuery(runtimeConfig: RuntimeConfig) = CargoDependency.smithyQuery(runtimeConfig).asType() - fun smithyTypes(runtimeConfig: RuntimeConfig) = CargoDependency.smithyTypes(runtimeConfig).asType() - fun smithyXml(runtimeConfig: RuntimeConfig) = CargoDependency.smithyXml(runtimeConfig).asType() - fun smithyProtocolTest(runtimeConfig: RuntimeConfig) = CargoDependency.smithyProtocolTestHelpers(runtimeConfig).asType() + fun smithyAsync(runtimeConfig: RuntimeConfig) = CargoDependency.smithyAsync(runtimeConfig).toType() + fun smithyChecksums(runtimeConfig: RuntimeConfig) = CargoDependency.smithyChecksums(runtimeConfig).toType() + fun smithyClient(runtimeConfig: RuntimeConfig) = CargoDependency.smithyClient(runtimeConfig).toType() + fun smithyEventstream(runtimeConfig: RuntimeConfig) = CargoDependency.smithyEventstream(runtimeConfig).toType() + fun smithyHttp(runtimeConfig: RuntimeConfig) = CargoDependency.smithyHttp(runtimeConfig).toType() + fun smithyJson(runtimeConfig: RuntimeConfig) = CargoDependency.smithyJson(runtimeConfig).toType() + fun smithyQuery(runtimeConfig: RuntimeConfig) = CargoDependency.smithyQuery(runtimeConfig).toType() + fun smithyTypes(runtimeConfig: RuntimeConfig) = CargoDependency.smithyTypes(runtimeConfig).toType() + fun smithyXml(runtimeConfig: RuntimeConfig) = CargoDependency.smithyXml(runtimeConfig).toType() + fun smithyProtocolTest(runtimeConfig: RuntimeConfig) = CargoDependency.smithyProtocolTestHelpers(runtimeConfig).toType() // smithy runtime type members fun base64Decode(runtimeConfig: RuntimeConfig): RuntimeType = smithyTypes(runtimeConfig).resolve("base64::decode") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt index b6e71d16e9..527b0291e1 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt @@ -49,7 +49,7 @@ class TopLevelErrorGenerator(private val codegenContext: CodegenContext, private .map { codegenContext.model.expectShape(it, StructureShape::class.java) } .sortedBy { it.id.getName(codegenContext.serviceShape) } - private val sdkError = CargoDependency.smithyHttp(codegenContext.runtimeConfig).asType().resolve("result::SdkError") + private val sdkError = CargoDependency.smithyHttp(codegenContext.runtimeConfig).toType().resolve("result::SdkError") fun render(crate: RustCrate) { crate.withModule(RustModule.private("error_meta")) { renderDefinition() diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt index 9fcc61d9fc..4961667fc1 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt @@ -129,7 +129,7 @@ class HttpBindingGenerator( #{deserializeFromHeader:W} } """, - "HeaderMap" to Http.asType().resolve("HeaderMap"), + "HeaderMap" to Http.toType().resolve("HeaderMap"), "Output" to outputT, "ParseError" to smithyHttp(runtimeConfig).resolve("header::ParseError"), "deserializeFromHeader" to deserializeFromHeader( @@ -154,8 +154,8 @@ class HttpBindingGenerator( #{deserializeFromHeader:W} } """, - "ValueIter" to Http.asType().resolve("header::ValueIter"), - "HeaderValue" to Http.asType().resolve("HeaderValue"), + "ValueIter" to Http.toType().resolve("header::ValueIter"), + "HeaderValue" to Http.toType().resolve("HeaderValue"), "Output" to symbolProvider.toSymbol(model.expectShape(target.value.target)), "ParseError" to smithyHttp(runtimeConfig).resolve("header::ParseError"), "deserializeFromHeader" to deserializeFromHeader( @@ -179,7 +179,7 @@ class HttpBindingGenerator( out.map(Some) } """, - "HeaderMap" to Http.asType().resolve("HeaderMap"), + "HeaderMap" to Http.toType().resolve("HeaderMap"), "Output" to outputSymbol.mapRustType { it.asOptional() }, "ParseError" to smithyHttp(runtimeConfig).resolve("header::ParseError"), "headers_for_prefix" to smithyHttp(runtimeConfig).resolve("header::headers_for_prefix"), @@ -472,8 +472,8 @@ class HttpBindingGenerator( ) val codegenScope = arrayOf( "BuildError" to runtimeConfig.operationBuildError(), - HttpMessageType.REQUEST.name to Http.asType().resolve("request::Builder"), - HttpMessageType.RESPONSE.name to Http.asType().resolve("response::Builder"), + HttpMessageType.REQUEST.name to Http.toType().resolve("request::Builder"), + HttpMessageType.RESPONSE.name to Http.toType().resolve("response::Builder"), "Shape" to shapeSymbol, ) rustBlockTemplate( diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt index f790d7f703..7c18dc595b 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt @@ -68,7 +68,7 @@ class RequestBindingGenerator( private val codegenScope = arrayOf( "BuildError" to runtimeConfig.operationBuildError(), - "HttpRequestBuilder" to Http.asType().resolve("request::Builder"), + "HttpRequestBuilder" to Http.toType().resolve("request::Builder"), "Input" to symbolProvider.toSymbol(inputShape), ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt index cb25df1991..2125948394 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt @@ -85,7 +85,7 @@ class RestRequestSpecGenerator( *codegenScope, "PathSegmentsVec" to pathSegmentsVec, "QuerySegmentsVec" to querySegmentsVec, - "Method" to Http.asType().resolve("Method"), + "Method" to Http.toType().resolve("Method"), ) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt index 82386f593c..b309208ecb 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt @@ -56,8 +56,8 @@ open class MakeOperationGenerator( private val codegenScope = arrayOf( "config" to RuntimeType.Config, "header_util" to smithyHttp(runtimeConfig).resolve("header"), - "http" to Http.asType(), - "HttpRequestBuilder" to Http.asType().resolve("request::Builder"), + "http" to Http.toType(), + "HttpRequestBuilder" to Http.toType().resolve("request::Builder"), "OpBuildError" to runtimeConfig.operationBuildError(), "operation" to RuntimeType.operationModule(runtimeConfig), "SdkBody" to smithyHttp(runtimeConfig).resolve("body::SdkBody"), @@ -171,7 +171,7 @@ open class MakeOperationGenerator( val contentType = httpBindingResolver.requestContentType(operationShape) httpBindingGenerator.renderUpdateHttpBuilder(writer) - writer.rust("let mut builder = update_http_builder(&self, #T::new())?;", Http.asType().resolve("request::Builder")) + writer.rust("let mut builder = update_http_builder(&self, #T::new())?;", Http.toType().resolve("request::Builder")) if (includeDefaultPayloadHeaders && contentType != null) { writer.rustTemplate( "builder = #{header_util}::set_request_header_if_absent(builder, #{http}::header::CONTENT_TYPE, ${contentType.dq()});", diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt index 35239b1f5b..510754d089 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt @@ -112,11 +112,11 @@ open class AwsJson( ) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( - "Bytes" to Bytes.asType().resolve("Bytes"), + "Bytes" to Bytes.toType().resolve("Bytes"), "Error" to RuntimeType.genericError(runtimeConfig), - "HeaderMap" to Http.asType().resolve("HeaderMap"), + "HeaderMap" to Http.toType().resolve("HeaderMap"), "JsonError" to smithyJson(runtimeConfig).resolve("deserialize::Error"), - "Response" to Http.asType().resolve("Response"), + "Response" to Http.toType().resolve("Response"), "json_errors" to RuntimeType.jsonErrors(runtimeConfig), ) private val jsonDeserModule = RustModule.private("json_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt index da28d20f8d..99dce5067f 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt @@ -44,10 +44,10 @@ class AwsQueryProtocol(private val codegenContext: CodegenContext) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val awsQueryErrors: RuntimeType = RuntimeType.wrappedXmlErrors(runtimeConfig) private val errorScope = arrayOf( - "Bytes" to Bytes.asType().resolve("Bytes"), + "Bytes" to Bytes.toType().resolve("Bytes"), "Error" to RuntimeType.genericError(runtimeConfig), - "HeaderMap" to Http.asType().resolve("HeaderMap"), - "Response" to Http.asType().resolve("Response"), + "HeaderMap" to Http.toType().resolve("HeaderMap"), + "Response" to Http.toType().resolve("Response"), "XmlError" to smithyXml(runtimeConfig).resolve("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt index f781de77c9..592d667d76 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt @@ -26,10 +26,10 @@ class Ec2QueryProtocol(private val codegenContext: CodegenContext) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val ec2QueryErrors: RuntimeType = RuntimeType.ec2QueryErrors(runtimeConfig) private val errorScope = arrayOf( - "Bytes" to Bytes.asType().resolve("Bytes"), + "Bytes" to Bytes.toType().resolve("Bytes"), "Error" to RuntimeType.genericError(runtimeConfig), - "HeaderMap" to Http.asType().resolve("HeaderMap"), - "Response" to Http.asType().resolve("Response"), + "HeaderMap" to Http.toType().resolve("HeaderMap"), + "Response" to Http.toType().resolve("Response"), "XmlError" to smithyXml(runtimeConfig).resolve("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt index 587daad700..4f4bd8e4c0 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt @@ -58,7 +58,7 @@ class HttpBoundProtocolPayloadGenerator( private val httpBindingResolver = protocol.httpBindingResolver private val operationSerModule = RustModule.private("operation_ser") private val codegenScope = arrayOf( - "hyper" to CargoDependency.HyperWithStream.asType(), + "hyper" to CargoDependency.HyperWithStream.toType(), "SdkBody" to smithyHttp(runtimeConfig).resolve("body::SdkBody"), "BuildError" to runtimeConfig.operationBuildError(), "SmithyHttp" to smithyHttp(runtimeConfig), diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt index a6797235c8..a2998963b0 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt @@ -65,11 +65,11 @@ class RestJsonHttpBindingResolver( open class RestJson(val codegenContext: CodegenContext) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( - "Bytes" to Bytes.asType().resolve("Bytes"), + "Bytes" to Bytes.toType().resolve("Bytes"), "Error" to RuntimeType.genericError(runtimeConfig), - "HeaderMap" to Http.asType().resolve("HeaderMap"), + "HeaderMap" to Http.toType().resolve("HeaderMap"), "JsonError" to smithyJson(runtimeConfig).resolve("deserialize::Error"), - "Response" to Http.asType().resolve("Response"), + "Response" to Http.toType().resolve("Response"), "json_errors" to RuntimeType.jsonErrors(runtimeConfig), ) private val jsonDeserModule = RustModule.private("json_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt index e8a5b01855..a3c3576091 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt @@ -26,10 +26,10 @@ open class RestXml(val codegenContext: CodegenContext) : Protocol { private val restXml = codegenContext.serviceShape.expectTrait() private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( - "Bytes" to Bytes.asType().resolve("Bytes"), + "Bytes" to Bytes.toType().resolve("Bytes"), "Error" to RuntimeType.genericError(runtimeConfig), - "HeaderMap" to Http.asType().resolve("HeaderMap"), - "Response" to Http.asType().resolve("Response"), + "HeaderMap" to Http.toType().resolve("HeaderMap"), + "Response" to Http.toType().resolve("Response"), "XmlError" to smithyXml(runtimeConfig).resolve("decode::XmlError"), ) private val xmlDeserModule = RustModule.private("xml_deser") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt index 76f8b58b27..ac01b440d9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt @@ -72,7 +72,7 @@ class EventStreamUnmarshallerGenerator( "Message" to smithyEventstream(runtimeConfig).resolve("frame::Message"), "OpError" to errorSymbol, "SmithyError" to smithyTypes(runtimeConfig).resolve("Error"), - "tracing" to CargoDependency.Tracing.asType(), + "tracing" to CargoDependency.Tracing.toType(), "UnmarshalledMessage" to smithyEventstream(runtimeConfig).resolve("frame::UnmarshalledMessage"), "UnmarshallMessage" to smithyEventstream(runtimeConfig).resolve("frame::UnmarshallMessage"), ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt index c98925c423..2e5fb3a0d0 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt @@ -121,4 +121,4 @@ val TokioWithTestMacros = CargoDependency( scope = DependencyScope.Dev, ) -val TokioTest = Attribute.Custom("tokio::test", listOf(TokioWithTestMacros.asType())) +val TokioTest = Attribute.Custom("tokio::test", listOf(TokioWithTestMacros.toType())) diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt index 038c54c4cf..ea75110221 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt @@ -26,7 +26,7 @@ class RustWriterTest { @Test fun `inner modules correctly handle dependencies`() { val sut = RustWriter.forModule("parent") - val requestBuilder = Http.asType().resolve("request::Builder") + val requestBuilder = Http.toType().resolve("request::Builder") sut.withModule(RustModule.public("inner")) { rustBlock("fn build(builder: #T)", requestBuilder) { } @@ -155,7 +155,7 @@ class RustWriterTest { sut.rustTemplate( "inner: #{Inner:W}, regular: #{http}", "Inner" to inner, - "http" to Http.asType().resolve("foo"), + "http" to Http.toType().resolve("foo"), ) sut.toString().shouldContain("inner: hello, regular: http::foo") } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt index a719430c8e..829e9722d9 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt @@ -144,11 +144,11 @@ class RequestBindingGeneratorTest { rustBlock( "pub fn test_request_builder_base(&self) -> Result<#T, #T>", - Http.asType().resolve("request::Builder"), + Http.toType().resolve("request::Builder"), TestRuntimeConfig.operationBuildError(), ) { bindingGen.renderUpdateHttpBuilder(this) - rust("let builder = #T::new();", Http.asType().resolve("request::Builder")) + rust("let builder = #T::new();", Http.toType().resolve("request::Builder")) rust("update_http_builder(self, builder)") } } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt index 4ef27c3723..09053ae112 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt @@ -16,13 +16,13 @@ import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCarg */ object PythonServerRuntimeType { - fun PySocket(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).asType().resolve("PySocket") + fun PySocket(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).toType().resolve("PySocket") - fun Blob(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).asType().resolve("types::Blob") + fun Blob(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).toType().resolve("types::Blob") - fun ByteStream(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).asType().resolve("types::ByteStream") + fun ByteStream(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).toType().resolve("types::ByteStream") - fun DateTime(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).asType().resolve("types::DateTime") + fun DateTime(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).toType().resolve("types::DateTime") - fun PyError(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).asType().resolve("Error") + fun PyError(runtimeConfig: RuntimeConfig) = smithyHttpServerPython(runtimeConfig).toType().resolve("Error") } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt index 12ce3c4e63..609a4e8b86 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt @@ -75,19 +75,19 @@ class PythonApplicationGenerator( private val model = codegenContext.model private val codegenScope = arrayOf( - "SmithyPython" to PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig).asType(), - "SmithyServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), - "pyo3" to PythonServerCargoDependency.PyO3.asType(), - "pyo3_asyncio" to PythonServerCargoDependency.PyO3Asyncio.asType(), - "tokio" to PythonServerCargoDependency.Tokio.asType(), - "tracing" to PythonServerCargoDependency.Tracing.asType(), - "tower" to PythonServerCargoDependency.Tower.asType(), - "tower_http" to PythonServerCargoDependency.TowerHttp.asType(), - "num_cpus" to PythonServerCargoDependency.NumCpus.asType(), - "hyper" to PythonServerCargoDependency.Hyper.asType(), + "SmithyPython" to PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig).toType(), + "SmithyServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), + "pyo3" to PythonServerCargoDependency.PyO3.toType(), + "pyo3_asyncio" to PythonServerCargoDependency.PyO3Asyncio.toType(), + "tokio" to PythonServerCargoDependency.Tokio.toType(), + "tracing" to PythonServerCargoDependency.Tracing.toType(), + "tower" to PythonServerCargoDependency.Tower.toType(), + "tower_http" to PythonServerCargoDependency.TowerHttp.toType(), + "num_cpus" to PythonServerCargoDependency.NumCpus.toType(), + "hyper" to PythonServerCargoDependency.Hyper.toType(), "HashMap" to RustType.HashMap.RuntimeType, - "parking_lot" to PythonServerCargoDependency.ParkingLot.asType(), - "http" to Http.asType(), + "parking_lot" to PythonServerCargoDependency.ParkingLot.toType(), + "http" to Http.toType(), ) fun render(writer: RustWriter) { diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt index 138d66ae17..42d6f07fcf 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt @@ -52,7 +52,7 @@ class PythonServerCombinedErrorGenerator( } """, - "pyo3" to PythonServerCargoDependency.PyO3.asType(), + "pyo3" to PythonServerCargoDependency.PyO3.toType(), "Error" to operation.errorSymbol(model, symbolProvider, CodegenTarget.SERVER), "From" to RuntimeType.From, "CastPyErrToRustError" to castPyErrToRustError(), diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt index 9f8907fd18..b27235b0ab 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt @@ -35,7 +35,7 @@ class PythonServerEnumGenerator( runtimeConfig: RuntimeConfig, ) : ServerEnumGenerator(model, symbolProvider, writer, shape, enumTrait, runtimeConfig) { - private val pyo3Symbols = listOf(PythonServerCargoDependency.PyO3.asType()) + private val pyo3Symbols = listOf(PythonServerCargoDependency.PyO3.toType()) override fun render() { renderPyClass() diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt index 5f3816eeca..7ca520485b 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt @@ -25,8 +25,8 @@ class PythonServerModuleGenerator( private val serviceShapes: Set, ) { private val codegenScope = arrayOf( - "SmithyPython" to PythonServerCargoDependency.smithyHttpServerPython(codegenContext.runtimeConfig).asType(), - "pyo3" to PythonServerCargoDependency.PyO3.asType(), + "SmithyPython" to PythonServerCargoDependency.smithyHttpServerPython(codegenContext.runtimeConfig).toType(), + "pyo3" to PythonServerCargoDependency.PyO3.toType(), ) private val symbolProvider = codegenContext.symbolProvider private val libName = "lib${codegenContext.settings.moduleName.toSnakeCase()}" diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt index 33ed2e232d..0ab189d9cd 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt @@ -40,12 +40,12 @@ class PythonServerOperationHandlerGenerator( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( - "SmithyPython" to PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig).asType(), - "SmithyServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), - "pyo3" to PythonServerCargoDependency.PyO3.asType(), - "pyo3_asyncio" to PythonServerCargoDependency.PyO3Asyncio.asType(), - "tokio" to PythonServerCargoDependency.Tokio.asType(), - "tracing" to PythonServerCargoDependency.Tracing.asType(), + "SmithyPython" to PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig).toType(), + "SmithyServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), + "pyo3" to PythonServerCargoDependency.PyO3.toType(), + "pyo3_asyncio" to PythonServerCargoDependency.PyO3Asyncio.toType(), + "tokio" to PythonServerCargoDependency.Tokio.toType(), + "tracing" to PythonServerCargoDependency.Tracing.toType(), ) override fun render(writer: RustWriter) { diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt index 9a4a0b82ea..468c1c5313 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt @@ -35,7 +35,7 @@ class PythonServerStructureGenerator( private val shape: StructureShape, ) : StructureGenerator(model, symbolProvider, writer, shape) { - private val pyo3Symbols = listOf(PythonServerCargoDependency.PyO3.asType()) + private val pyo3Symbols = listOf(PythonServerCargoDependency.PyO3.toType()) override fun renderStructure() { if (shape.hasTrait()) { diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt index de1c00924b..57f01999dd 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt @@ -18,18 +18,18 @@ import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency.s object ServerRuntimeType { private fun forInlineDependency(inlineDependency: InlineDependency) = RuntimeType.forInlineDependency(inlineDependency) - fun Router(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("routing::Router") + fun Router(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).toType().resolve("routing::Router") - fun RequestSpecModule(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("routing::request_spec") + fun RequestSpecModule(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).toType().resolve("routing::request_spec") fun OperationHandler(runtimeConfig: RuntimeConfig) = forInlineDependency(ServerInlineDependency.serverOperationHandler(runtimeConfig)) - fun RuntimeError(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("runtime_error::RuntimeError") + fun RuntimeError(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).toType().resolve("runtime_error::RuntimeError") - fun RequestRejection(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("rejection::RequestRejection") + fun RequestRejection(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).toType().resolve("rejection::RequestRejection") - fun ResponseRejection(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("rejection::ResponseRejection") + fun ResponseRejection(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).toType().resolve("rejection::ResponseRejection") - fun Protocol(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).asType().resolve("proto") + fun Protocol(runtimeConfig: RuntimeConfig) = smithyHttpServer(runtimeConfig).toType().resolve("proto") } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt index fa3f5c295a..35aa6f09f8 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt @@ -34,7 +34,7 @@ import java.util.Optional /** Models the ways status codes can be bound and sensitive. */ class StatusCodeSensitivity(private val sensitive: Boolean, runtimeConfig: RuntimeConfig) { private val codegenScope = arrayOf( - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), ) /** Returns the type of the `MakeFmt`. */ @@ -64,7 +64,7 @@ data class GreedyLabel( /** Models the ways labels can be bound and sensitive. */ class LabelSensitivity(internal val labelIndexes: List, internal val greedyLabel: GreedyLabel?, runtimeConfig: RuntimeConfig) { - private val codegenScope = arrayOf("SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType()) + private val codegenScope = arrayOf("SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType()) /** Returns the closure used during construction. */ fun closure(): Writable = writable { @@ -116,8 +116,8 @@ sealed class HeaderSensitivity( runtimeConfig: RuntimeConfig, ) { private val codegenScope = arrayOf( - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), - "Http" to Http.asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), + "Http" to Http.toType(), ) /** The case where `prefixHeaders` value is not sensitive. */ @@ -218,7 +218,7 @@ sealed class QuerySensitivity( val allKeysSensitive: Boolean, runtimeConfig: RuntimeConfig, ) { - private val codegenScope = arrayOf("SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType()) + private val codegenScope = arrayOf("SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType()) /** The case where the `httpQueryParams` value is not sensitive. */ class NotSensitiveMapValue( @@ -306,8 +306,8 @@ class ServerHttpSensitivityGenerator( private val runtimeConfig: RuntimeConfig, ) { private val codegenScope = arrayOf( - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), - "Http" to Http.asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), + "Http" to Http.toType(), ) /** Constructs `StatusCodeSensitivity` of a `Shape` */ diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt index 262ff39e57..7bd18e49d1 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt @@ -24,7 +24,7 @@ class ServerOperationGenerator( private val codegenScope = arrayOf( "SmithyHttpServer" to - ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), + ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), ) private val symbolProvider = codegenContext.symbolProvider private val model = codegenContext.model diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt index e32ea29f9b..a3e898aba2 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt @@ -38,14 +38,14 @@ open class ServerOperationHandlerGenerator( private val symbolProvider = codegenContext.symbolProvider private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( - "AsyncTrait" to ServerCargoDependency.AsyncTrait.asType(), - "Tower" to Tower.asType(), - "FuturesUtil" to ServerCargoDependency.FuturesUtil.asType(), + "AsyncTrait" to ServerCargoDependency.AsyncTrait.toType(), + "Tower" to Tower.toType(), + "FuturesUtil" to ServerCargoDependency.FuturesUtil.toType(), "SmithyHttp" to smithyHttp(runtimeConfig), - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), "Phantom" to RuntimeType.Phantom, "ServerOperationHandler" to ServerRuntimeType.OperationHandler(runtimeConfig), - "http" to Http.asType(), + "http" to Http.toType(), ) open fun render(writer: RustWriter) { diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt index 120bc09afd..b91348418a 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt @@ -60,9 +60,9 @@ class ServerOperationRegistryGenerator( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "Router" to ServerRuntimeType.Router(runtimeConfig), - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), "ServerOperationHandler" to ServerRuntimeType.OperationHandler(runtimeConfig), - "Tower" to Tower.asType(), + "Tower" to Tower.toType(), "Phantom" to RuntimeType.Phantom, "StdError" to RuntimeType.StdError, "Display" to RuntimeType.Display, @@ -159,8 +159,8 @@ ${operationImplementationStubs(operations)} "Router" to ServerRuntimeType.Router(runtimeConfig), // These should be dev-dependencies. Not all sSDKs depend on `Hyper` (only those that convert the body // `to_bytes`), and none depend on `tokio`. - "Tokio" to ServerCargoDependency.TokioDev.asType(), - "Hyper" to CargoDependency.Hyper.copy(scope = DependencyScope.Dev).asType(), + "Tokio" to ServerCargoDependency.TokioDev.toType(), + "Hyper" to CargoDependency.Hyper.copy(scope = DependencyScope.Dev).toType(), ) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt index f44bb99818..13b8c47a68 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt @@ -31,12 +31,12 @@ class ServerServiceGeneratorV2( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( - "Bytes" to Bytes.asType().resolve("Bytes"), - "Http" to Http.asType(), - "HttpBody" to HttpBody.asType(), + "Bytes" to Bytes.toType().resolve("Bytes"), + "Http" to Http.toType(), + "HttpBody" to HttpBody.toType(), "SmithyHttpServer" to - ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), - "Tower" to Tower.asType(), + ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), + "Tower" to Tower.toType(), ) private val model = codegenContext.model private val symbolProvider = codegenContext.symbolProvider diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt index 4f6550d6dc..19ca80175b 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt @@ -83,7 +83,7 @@ class ServerAwsJsonProtocol( ) : AwsJson(codegenContext, awsJsonVersion), ServerProtocol { private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), ) private val symbolProvider = codegenContext.symbolProvider private val service = codegenContext.serviceShape @@ -193,7 +193,7 @@ private fun restRouterConstruction( """, "Key" to key, "OperationValue" to operationValue, - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), ) } } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt index bc319b7e6a..4866ba2f11 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt @@ -106,14 +106,14 @@ class ServerProtocolTestGenerator( private val instantiator = serverInstantiator(codegenContext) private val codegenScope = arrayOf( - "Bytes" to Bytes.asType().resolve("Bytes"), + "Bytes" to Bytes.toType().resolve("Bytes"), "SmithyHttp" to smithyHttp(codegenContext.runtimeConfig), - "Http" to Http.asType(), - "Hyper" to Hyper.asType(), - "Tokio" to ServerCargoDependency.TokioDev.asType(), - "Tower" to Tower.asType(), - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).asType(), - "AssertEq" to PrettyAssertions.asType().resolve("assert_eq!"), + "Http" to Http.toType(), + "Hyper" to Hyper.toType(), + "Tokio" to ServerCargoDependency.TokioDev.toType(), + "Tower" to Tower.toType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).toType(), + "AssertEq" to PrettyAssertions.toType().resolve("assert_eq!"), "Router" to ServerRuntimeType.Router(codegenContext.runtimeConfig), ) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt index a83c2b4b51..d716036547 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt @@ -130,25 +130,25 @@ private class ServerHttpBoundProtocolTraitImplGenerator( private val serverProtocol = ServerProtocol.fromCoreProtocol(protocol) private val codegenScope = arrayOf( - "AsyncTrait" to ServerCargoDependency.AsyncTrait.asType(), + "AsyncTrait" to ServerCargoDependency.AsyncTrait.toType(), "Cow" to RuntimeType.Cow, "DateTime" to RuntimeType.dateTime(runtimeConfig), - "FormUrlEncoded" to ServerCargoDependency.FormUrlEncoded.asType(), - "HttpBody" to CargoDependency.HttpBody.asType(), + "FormUrlEncoded" to ServerCargoDependency.FormUrlEncoded.toType(), + "HttpBody" to CargoDependency.HttpBody.toType(), "header_util" to smithyHttp(runtimeConfig).resolve("header"), - "Hyper" to CargoDependency.Hyper.asType(), - "LazyStatic" to CargoDependency.LazyStatic.asType(), - "Mime" to ServerCargoDependency.Mime.asType(), - "Nom" to ServerCargoDependency.Nom.asType(), - "OnceCell" to ServerCargoDependency.OnceCell.asType(), - "PercentEncoding" to CargoDependency.PercentEncoding.asType(), - "Regex" to CargoDependency.Regex.asType(), + "Hyper" to CargoDependency.Hyper.toType(), + "LazyStatic" to CargoDependency.LazyStatic.toType(), + "Mime" to ServerCargoDependency.Mime.toType(), + "Nom" to ServerCargoDependency.Nom.toType(), + "OnceCell" to ServerCargoDependency.OnceCell.toType(), + "PercentEncoding" to CargoDependency.PercentEncoding.toType(), + "Regex" to CargoDependency.Regex.toType(), "SmithyHttp" to smithyHttp(runtimeConfig), - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), "RuntimeError" to ServerRuntimeType.RuntimeError(runtimeConfig), "RequestRejection" to ServerRuntimeType.RequestRejection(runtimeConfig), "ResponseRejection" to ServerRuntimeType.ResponseRejection(runtimeConfig), - "http" to Http.asType(), + "http" to Http.toType(), ) override fun generateTraitImpls(operationWriter: RustWriter, operationShape: OperationShape, customizations: List) { diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt index afc080aed9..9a8ae01cab 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt @@ -22,8 +22,8 @@ import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverTestSymb class ServerHttpSensitivityGeneratorTest { private val codegenScope = arrayOf( - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(TestRuntimeConfig).asType(), - "Http" to CargoDependency.Http.asType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(TestRuntimeConfig).toType(), + "Http" to CargoDependency.Http.toType(), ) @Test diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt index ec2d8d8cae..8d12d5132f 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt @@ -50,7 +50,7 @@ class EventStreamMarshallerGeneratorTest { val protocolTestHelpers = CargoDependency .smithyProtocolTestHelpers(TestRuntimeConfig) .copy(scope = DependencyScope.Compile) - .asType() + .toType() rustTemplate( """ use aws_smithy_eventstream::frame::{Message, Header, HeaderValue, MarshallMessage}; From 2c0ed8b927d88946af1eaf46786c7a04e6b0029d Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Thu, 10 Nov 2022 13:43:17 -0600 Subject: [PATCH 19/19] update: derive attribute type sorting --- .../amazon/smithy/rust/codegen/core/rustlang/RustType.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt index 7647c013f0..efe6cb18e7 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt @@ -393,7 +393,7 @@ sealed class Attribute { return } writer.raw("#[derive(") - derives.sortedBy { it.name }.forEach { derive -> + derives.sortedBy { it.path }.forEach { derive -> writer.writeInline("#T, ", derive) } writer.write(")]")