diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCargoDependency.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCargoDependency.kt new file mode 100644 index 0000000000000000000000000000000000000000..871e845281373bf28fa02ebb3327e2ce27f3c917 --- /dev/null +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCargoDependency.kt @@ -0,0 +1,23 @@ +/* + * 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.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.crateLocation + +fun RuntimeConfig.awsRuntimeCrate(name: String, features: Set = setOf()): CargoDependency = + CargoDependency(name, awsRoot().crateLocation(null), features = features) + +object AwsCargoDependency { + fun awsConfig(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-config") + fun awsEndpoint(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-endpoint") + fun awsHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-http") + fun awsSigAuth(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sig-auth") + fun awsSigAuthEventStream(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sig-auth", setOf("sign-eventstream")) + fun awsSigv4(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sigv4") + fun awsTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-types") +} 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/AwsEndpointDecorator.kt index ec748798765bc6c51f550508e346560daafb8b4b..94da0fb8d58c534de5f2772ca31d269a1aeb8a60 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/AwsEndpointDecorator.kt @@ -94,18 +94,13 @@ class EndpointConfigCustomization( ) : ConfigCustomization() { private val runtimeConfig = codegenContext.runtimeConfig - private val resolveAwsEndpoint = runtimeConfig.awsEndpoint().toType().copy(name = "ResolveAwsEndpoint") - private val smithyEndpointResolver = - CargoDependency.smithyHttp(runtimeConfig).toType().member("endpoint::ResolveEndpoint") - private val placeholderEndpointParams = runtimeConfig.awsEndpoint().toType().member("Params") - private val endpointShim = runtimeConfig.awsEndpoint().toType().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).toType(), + "SmithyResolver" to RuntimeType.smithyHttp(runtimeConfig).resolve("endpoint::ResolveEndpoint"), + "PlaceholderParams" to AwsRuntimeType.awsEndpoint(runtimeConfig).resolve("Params"), + "ResolveAwsEndpoint" to AwsRuntimeType.awsEndpoint(runtimeConfig).resolve("ResolveAwsEndpoint"), + "EndpointShim" to AwsRuntimeType.awsEndpoint(runtimeConfig).resolve("EndpointShim"), + "aws_types" to AwsRuntimeType.awsTypes(runtimeConfig), ) override fun section(section: ServiceConfig): Writable = writable { @@ -181,7 +176,7 @@ class EndpointConfigCustomization( class EndpointResolverFeature(runtimeConfig: RuntimeConfig) : OperationCustomization() { - private val placeholderEndpointParams = runtimeConfig.awsEndpoint().toType().member("Params") + private val placeholderEndpointParams = AwsRuntimeType.awsEndpoint(runtimeConfig).resolve("Params") private val codegenScope = arrayOf( "PlaceholderParams" to placeholderEndpointParams, "BuildError" to runtimeConfig.operationBuildError(), @@ -223,20 +218,20 @@ 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().toType() - private val awsTypes = runtimeConfig.awsTypes().toType() + private val awsEndpoint = AwsRuntimeType.awsEndpoint(runtimeConfig) + private val awsTypes = AwsRuntimeType.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/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt index 0aeddc3ab5e8c03015e85882b0f04c022d0833e2..61a13c7650f2d2ff7a8da16b2f15fd418951eaeb 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/AwsFluentClientDecorator.kt @@ -17,7 +17,6 @@ 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 @@ -38,23 +37,21 @@ import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware private class Types(runtimeConfig: RuntimeConfig) { - private val smithyTypesDep = CargoDependency.smithyTypes(runtimeConfig) - private val smithyClientDep = CargoDependency.smithyClient(runtimeConfig) - private val smithyHttpDep = CargoDependency.smithyHttp(runtimeConfig) + private val smithyClient = RuntimeType.smithyClient(runtimeConfig) + private val smithyHttp = RuntimeType.smithyHttp(runtimeConfig) + private val smithyTypes = RuntimeType.smithyTypes(runtimeConfig) - val awsTypes = awsTypes(runtimeConfig).toType() - val smithyClientRetry = RuntimeType("retry", smithyClientDep, "aws_smithy_client") - val awsSmithyClient = smithyClientDep.toType() - - val connectorSettings = RuntimeType("ConnectorSettings", smithyClientDep, "aws_smithy_client::http_connector") + val awsTypes = AwsRuntimeType.awsTypes(runtimeConfig) + val connectorError = smithyHttp.resolve("result::ConnectorError") + val connectorSettings = smithyClient.resolve("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 = smithyClient.resolve("erase::DynConnector") + val dynMiddleware = smithyClient.resolve("erase::DynMiddleware") + val retryConfig = smithyTypes.resolve("retry::RetryConfig") + val smithyClientBuilder = smithyClient.resolve("Builder") + val smithyClientRetry = smithyClient.resolve("retry") + val smithyConnector = smithyClient.resolve("bounds::SmithyConnector") + val timeoutConfig = smithyTypes.resolve("timeout::TimeoutConfig") } private class AwsClientGenerics(private val types: Types) : FluentClientGenerics { @@ -105,7 +102,7 @@ class AwsFluentClientDecorator : RustCodegenDecorator = setOf()): CargoDependency = - CargoDependency(name, awsRoot().crateLocation(null), features = features) + ).resolve("DefaultMiddleware") -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 awsEndpoint(runtimeConfig: RuntimeConfig) = AwsCargoDependency.awsEndpoint(runtimeConfig).toType() + fun awsHttp(runtimeConfig: RuntimeConfig) = AwsCargoDependency.awsHttp(runtimeConfig).toType() + fun awsSigAuth(runtimeConfig: RuntimeConfig) = AwsCargoDependency.awsSigAuth(runtimeConfig).toType() + fun awsSigAuthEventStream(runtimeConfig: RuntimeConfig) = AwsCargoDependency.awsSigAuthEventStream(runtimeConfig).toType() + fun awsSigv4(runtimeConfig: RuntimeConfig) = AwsCargoDependency.awsSigv4(runtimeConfig).toType() + fun awsTypes(runtimeConfig: RuntimeConfig) = AwsCargoDependency.awsTypes(runtimeConfig).toType() +} 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/CredentialProviders.kt index fb7b00f61e5f205fb004f985b3a8bc870da54519..8b489923f1862d5468217e515258cf3766021b61 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/CredentialProviders.kt @@ -59,17 +59,17 @@ class CredentialsProviderDecorator : RustCodegenDecorator rustTemplate( + ServiceConfig.ConfigStruct -> rustTemplate( """pub(crate) credentials_provider: #{credentials}::SharedCredentialsProvider,""", *codegenScope, ) - is ServiceConfig.ConfigImpl -> rustTemplate( + ServiceConfig.ConfigImpl -> rustTemplate( """ /// Returns the credentials provider. pub fn credentials_provider(&self) -> #{credentials}::SharedCredentialsProvider { @@ -78,7 +78,7 @@ class CredentialProviderConfig(runtimeConfig: RuntimeConfig) : ConfigCustomizati """, *codegenScope, ) - is ServiceConfig.BuilderStruct -> + ServiceConfig.BuilderStruct -> rustTemplate("credentials_provider: Option<#{credentials}::SharedCredentialsProvider>,", *codegenScope) ServiceConfig.BuilderImpl -> { rustTemplate( @@ -103,6 +103,8 @@ class CredentialProviderConfig(runtimeConfig: RuntimeConfig) : ConfigCustomizati "credentials_provider: self.credentials_provider.unwrap_or_else(|| #{credentials}::SharedCredentialsProvider::new(#{DefaultProvider})),", *codegenScope, ) + + else -> emptySection } } } @@ -130,7 +132,7 @@ class PubUseCredentials(private val runtimeConfig: RuntimeConfig) : LibRsCustomi is LibRsSection.Body -> writable { rust( "pub use #T::Credentials;", - awsTypes(runtimeConfig).toType(), + AwsRuntimeType.awsTypes(runtimeConfig), ) } @@ -139,10 +141,7 @@ 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") + RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("no_credentials")).resolve("NoCredentials") -fun setProvider(runtimeConfig: RuntimeConfig) = - RuntimeType("set_provider", awsHttp(runtimeConfig), "aws_http::auth") +fun setProvider(runtimeConfig: RuntimeConfig) = AwsRuntimeType.awsHttp(runtimeConfig).resolve("auth::set_provider") diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpConnectorConfigCustomization.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpConnectorConfigCustomization.kt index 6184c5331d70b9e96680bdb67d1b0fb562c54186..215662aeca7b1d6d65fe0e673eafdcbab68cf95d 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpConnectorConfigCustomization.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpConnectorConfigCustomization.kt @@ -10,12 +10,12 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDe 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.Companion.smithyClient 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.RuntimeType class HttpConnectorDecorator : RustCodegenDecorator { override val name: String = "HttpConnectorDecorator" @@ -38,7 +38,7 @@ class HttpConnectorConfigCustomization( private val runtimeConfig = codegenContext.runtimeConfig private val moduleUseName = codegenContext.moduleUseName() private val codegenScope = arrayOf( - "HttpConnector" to smithyClient(runtimeConfig).toType().member("http_connector::HttpConnector"), + "HttpConnector" to RuntimeType.smithyClient(runtimeConfig).resolve("http_connector::HttpConnector"), ) override fun section(section: ServiceConfig): Writable { 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/HttpRequestChecksumDecorator.kt index 86421702056efe270e4d0c8413ada546be40ba22..a94531f43c7b2d42e1ab12e4aba557ac3322123d 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/HttpRequestChecksumDecorator.kt @@ -36,8 +36,6 @@ fun RuntimeConfig.awsInlineableBodyWithChecksum() = RuntimeType.forInlineDepende CargoDependency.smithyTypes(this), CargoDependency.Bytes, CargoDependency.Tracing, - this.sigAuth(), - this.awsHttp(), ), ) @@ -104,7 +102,7 @@ private fun HttpChecksumTrait.checksumAlgorithmToStr( }; """, "BuildError" to runtimeConfig.operationBuildError(), - "ChecksumAlgorithm" to CargoDependency.smithyChecksums(runtimeConfig).toType().member("ChecksumAlgorithm"), + "ChecksumAlgorithm" to RuntimeType.smithyChecksums(runtimeConfig).resolve("ChecksumAlgorithm"), ) // If a request checksum is not required and there's no way to set one, do nothing @@ -159,7 +157,7 @@ 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(), ) } 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/HttpResponseChecksumDecorator.kt index c695c5c4072fff531d96cd640e2efcb33d716571..fbbb878fbc584e57ed713d44adbeacb950890699 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/HttpResponseChecksumDecorator.kt @@ -114,8 +114,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/RegionDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt index 47b1dea56db5f6837589eddda6094f15ba09c16a..24cf36aa0b067fbb80bb31070f6e583ab13be71f 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/RegionDecorator.kt @@ -24,7 +24,6 @@ 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 @@ -127,7 +126,7 @@ class RegionDecorator : RustCodegenDecorator rustTemplate("pub(crate) region: Option<#{Region}>,", *codegenScope) - is ServiceConfig.ConfigImpl -> rustTemplate( + ServiceConfig.ConfigStruct -> rustTemplate("pub(crate) region: Option<#{Region}>,", *codegenScope) + ServiceConfig.ConfigImpl -> rustTemplate( """ /// Returns the AWS region, if it was provided. pub fn region(&self) -> Option<&#{Region}> { @@ -159,7 +158,7 @@ class RegionProviderConfig(codegenContext: CodegenContext) : ConfigCustomization *codegenScope, ) - is ServiceConfig.BuilderStruct -> + ServiceConfig.BuilderStruct -> rustTemplate("region: Option<#{Region}>,", *codegenScope) ServiceConfig.BuilderImpl -> @@ -188,6 +187,7 @@ class RegionProviderConfig(codegenContext: CodegenContext) : ConfigCustomization """region: self.region,""", *codegenScope, ) + else -> emptySection } } @@ -227,7 +227,4 @@ 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") +fun region(runtimeConfig: RuntimeConfig) = AwsRuntimeType.awsTypes(runtimeConfig).resolve("region") 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/RetryClassifierDecorator.kt index e1e784ce70b0b64d5d2d8c8f5cf1d33b97ef8c7e..cbf4ca57e98987e2e30d047402f568e80014b024 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/RetryClassifierDecorator.kt @@ -34,7 +34,7 @@ class RetryClassifierDecorator : RustCodegenDecorator writable { rust( 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/SdkConfigDecorator.kt index 5d63aa4ee2a3223032b7d6899b95751bb2f5e5cd..2ae5e8d6148c3211bec0db1965a5922405718680 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/SdkConfigDecorator.kt @@ -37,8 +37,7 @@ class SdkConfigDecorator : RustCodegenDecorator emptySection } } -private fun RuntimeConfig.userAgentModule() = awsHttp().toType().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 { @@ -100,8 +95,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(), + "ua_module" to AwsRuntimeType.awsHttp(runtimeConfig).resolve("user_agent"), + "Env" to AwsRuntimeType.awsTypes(runtimeConfig).resolve("os_shim_internal::Env"), ) } else -> emptySection @@ -109,7 +104,9 @@ 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 AwsRuntimeType.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/customize/apigateway/ApiGatewayDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/apigateway/ApiGatewayDecorator.kt index 23d489a5ce467f371e8a6dda20749abf8c41a16a..70af3fe19540489feb06e35722182562b7cf241e 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/customize/apigateway/ApiGatewayDecorator.kt @@ -50,7 +50,7 @@ class ApiGatewayAddAcceptHeader : OperationCustomization() { .http_mut() .headers_mut() .insert("Accept", #T::HeaderValue::from_static("application/json"));""", - RuntimeType.http, + RuntimeType.Http, ) } else -> emptySection 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/customize/glacier/ApiVersionHeader.kt index 8bc2d3b0610458b3902e189445ac40c142f9dabf..8772de0ce9112d41de6df658504181dcb38251d3 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/customize/glacier/ApiVersionHeader.kt @@ -29,7 +29,7 @@ class ApiVersionHeader( .http_mut() .headers_mut() .insert("x-amz-glacier-version", #T::HeaderValue::from_static(${apiVersion.dq()}));""", - RuntimeType.http, + RuntimeType.Http, ) } else -> emptySection 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/customize/glacier/TreeHashHeader.kt index 18611d4fd9bc1e910e8a275ede8ef1db9e86987c..023a663c429df3411fd843d2e958d504366a95c2 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/customize/glacier/TreeHashHeader.kt @@ -16,7 +16,6 @@ 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.operationBuildError -import software.amazon.smithy.rust.codegen.core.testutil.TokioWithTestMacros import software.amazon.smithy.rustsdk.InlineAwsDependency val TreeHashDependencies = listOf( @@ -24,7 +23,7 @@ val TreeHashDependencies = listOf( CargoDependency.TokioStream, CargoDependency.BytesUtils, CargoDependency.Bytes, - TokioWithTestMacros, + CargoDependency.Tokio, CargoDependency.Hex, CargoDependency.TempFile, ) 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/customize/route53/Route53Decorator.kt index adff13cf80b0f24659957c1eca981101c15d8df1..d58f73456105b1a157115adb2983385badddfbd3 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/customize/route53/Route53Decorator.kt @@ -77,7 +77,7 @@ class TrimResourceIdCustomization(private val fieldName: String) : OperationCust RuntimeType.forInlineDependency( InlineAwsDependency.forRustFile("route53_resource_id_preprocessor"), ) - .member("trim_resource_id") + .resolve("trim_resource_id") override fun section(section: OperationSection): Writable { return when (section) { 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/customize/s3/S3Decorator.kt index abb599849ebf85516d3af56702784abb265ca3a1..c484ee88b820af090f34f0848c2069b7668d4f53 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/customize/s3/S3Decorator.kt @@ -17,7 +17,6 @@ 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.rust @@ -92,10 +91,10 @@ class S3(codegenContext: CodegenContext) : RestXml(codegenContext) { 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"), - "XmlDecodeError" to CargoDependency.smithyXml(runtimeConfig).toType().member("decode::XmlDecodeError"), + "Error" to RuntimeType.genericError(runtimeConfig), + "HeaderMap" to RuntimeType.HttpHeaderMap, + "Response" to RuntimeType.HttpResponse, + "XmlDecodeError" to RuntimeType.smithyXml(runtimeConfig).resolve("decode::XmlDecodeError"), "base_errors" to restXmlErrors, "s3_errors" to AwsRuntimeType.S3Errors, ) 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 d14d65b05890666328977dae4ab7dc1a522e5b9c..39127ccf2a9897d2c37529e028fbae159cf0452b 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 @@ -9,19 +9,19 @@ import org.junit.jupiter.api.Test import software.amazon.smithy.model.node.Node import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest -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.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.testutil.unitTest import java.io.File internal class EndpointConfigCustomizationTest { - private val placeholderEndpointParams = AwsTestRuntimeConfig.awsEndpoint().toType().member("Params") + private val placeholderEndpointParams = AwsRuntimeType.awsEndpoint(AwsTestRuntimeConfig).resolve("Params") private val codegenScope = arrayOf( - "http" to CargoDependency.Http.toType(), + "http" to RuntimeType.Http, "PlaceholderParams" to placeholderEndpointParams, - "aws_types" to awsTypes(AwsTestRuntimeConfig).toType(), + "aws_types" to AwsRuntimeType.awsTypes(AwsTestRuntimeConfig), ) private val model = """ 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 85053dca6c673f72d7284592deca44eabc5a4ab6..7a885d91aec47839c61e573769cbcf4addf45331 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 @@ -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() + RuntimeType.smithyHttp(runtimeConfig).resolve("event_stream::MessageStreamError").toSymbol() } else { unionShape.eventStreamErrorSymbol(model, this, target).toSymbol() } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingTraitSymbolProvider.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingTraitSymbolProvider.kt index cd362acccf5dbffc4245663c29dc50fbc96fbd33..3203e96a22fc1265af9b45b254a0c07589de4178 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingTraitSymbolProvider.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingTraitSymbolProvider.kt @@ -48,7 +48,7 @@ class StreamingShapeSymbolProvider(private val base: RustSymbolProvider, private // We are only targeting streaming blobs return if (target is BlobShape && shape.isStreaming(model)) { - RuntimeType.ByteStream(config().runtimeConfig).toSymbol().toBuilder().setDefault(Default.RustDefault).build() + RuntimeType.byteStream(config().runtimeConfig).toSymbol().toBuilder().setDefault(Default.RustDefault).build() } else { base.toSymbol(shape) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpChecksumRequiredGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpChecksumRequiredGenerator.kt index 14cd2caf46abafd308380b086e0e63375ef0bf90..bf275034c6955a743b3b59b3aba646e9b70b756b 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpChecksumRequiredGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpChecksumRequiredGenerator.kt @@ -8,7 +8,6 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.HttpChecksumRequiredTrait -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 @@ -49,9 +48,9 @@ class HttpChecksumRequiredGenerator( Result::<_, #{BuildError}>::Ok(req) })?; """, - "md5" to CargoDependency.Md5.toType(), - "http" to CargoDependency.Http.toType(), - "base64_encode" to RuntimeType.Base64Encode(codegenContext.runtimeConfig), + "md5" to RuntimeType.Md5, + "http" to RuntimeType.Http, + "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 8550adcefadd4073a19bff9cef01c0da88e01e41..da4ba53222cd899b56f00312148e3b1f7792e5ee 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 @@ -8,38 +8,31 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations 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.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.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() - override fun section(section: OperationSection): Writable { + val runtimeConfig = codegenContext.runtimeConfig val awsProtocolTrait = codegenContext.serviceShape.getTrait() val supportedHttpProtocolVersions = if (awsProtocolTrait == null) { // No protocol trait was defined, use default http versions - "$defaultHttpVersions.clone()" + "#{defaultHttpVersions}.clone()" } else { // Figure out whether we're dealing with an EventStream operation and fetch the corresponding list of desired HTTP versions val versionList = if (operationShape.isEventStream(codegenContext.model)) awsProtocolTrait.eventStreamHttp else awsProtocolTrait.http if (versionList.isEmpty()) { // If no desired versions are specified, go with the default - "$defaultHttpVersions.clone()" + "#{defaultHttpVersions}.clone()" } else { // otherwise, use the specified versions "vec![${versionList.joinToString(",") { version -> mapHttpVersion(version) }}]" @@ -48,10 +41,11 @@ class HttpVersionListCustomization( return when (section) { is OperationSection.MutateRequest -> writable { - rust( + rustTemplate( """ ${section.request}.properties_mut().insert($supportedHttpProtocolVersions); """, + "defaultHttpVersions" to RuntimeType.smithyHttp(runtimeConfig).resolve("http_versions::DEFAULT_HTTP_VERSION_LIST"), ) } else -> emptySection 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 df0c0869768c837583c98d43a16a75a6f5441cfd..119d43ebfda482793f119c0ff17fd214b4f80ada 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 @@ -16,15 +16,16 @@ 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 retryConfig = RuntimeType.smithyTypes(runtimeConfig).resolve("retry") + private val sleepModule = RuntimeType.smithyAsync(runtimeConfig).resolve("rt::sleep") + private val timeoutModule = RuntimeType.smithyTypes(runtimeConfig).resolve("timeout") 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 sleepModule.resolve("AsyncSleep"), + "RetryConfig" to retryConfig.resolve("RetryConfig"), + "Sleep" to sleepModule.resolve("Sleep"), + "TimeoutConfig" to timeoutModule.resolve("TimeoutConfig"), ) override fun section(section: ServiceConfig) = @@ -245,22 +246,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), + "types_retry" to RuntimeType.smithyTypes(runtimeConfig).resolve("retry"), + "sleep" to RuntimeType.smithyAsync(runtimeConfig).resolve("rt::sleep"), + "timeout" to RuntimeType.smithyTypes(runtimeConfig).resolve("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 4546a74154eac45f99b6f4c6d127230fea0492ae..2f2c72ab15ae9659abd013d2c5874b0177b560b5 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,7 +7,6 @@ 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.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig @@ -53,15 +52,15 @@ 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), - ) + CargoDependency.smithyTypes(runtimeConfig).toType().let { types -> - listOf(PubUseType(types.member("error::display::DisplayErrorContext")) { true }) - } + CargoDependency.smithyHttp(runtimeConfig).toType().let { http -> + PubUseType(RuntimeType.blob(runtimeConfig), ::hasBlobs), + PubUseType(RuntimeType.dateTime(runtimeConfig), ::hasDateTimes), + ) + RuntimeType.smithyTypes(runtimeConfig).let { types -> + listOf(PubUseType(types.resolve("error::display::DisplayErrorContext")) { true }) + } + RuntimeType.smithyHttp(runtimeConfig).let { http -> 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 8c63b06d72eb5b774e5914d8a0513e4eabb0714f..cddfc1cc102bff330d955ac07adc7ab9bdb82718 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,7 +7,6 @@ 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 @@ -48,9 +47,9 @@ 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"), + "NoOpSigner" to RuntimeType.smithyEventStream(runtimeConfig).resolve("frame::NoOpSigner"), ) override fun configImplSection() = renderEventStreamSignerFn { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt index 9419df2df99660ee57dd1f60795e04c60eebfbf0..0a496611a4e8f4c102e80b29dce33b1e61a1d7eb 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt @@ -12,13 +12,13 @@ import software.amazon.smithy.rulesengine.language.syntax.parameters.ParameterTy import software.amazon.smithy.rulesengine.traits.ContextParamTrait import software.amazon.smithy.rust.codegen.client.smithy.endpoint.generators.EndpointsStdLib import software.amazon.smithy.rust.codegen.client.smithy.endpoint.generators.FunctionRegistry -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords import software.amazon.smithy.rust.codegen.core.rustlang.RustType 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.makeOptional import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.letIf @@ -46,11 +46,11 @@ internal fun endpointsLib(name: String, vararg additionalDependency: RustDepende ) class Types(runtimeConfig: RuntimeConfig) { - private val smithyTypesEndpointModule = CargoDependency.smithyTypes(runtimeConfig).toType().member("endpoint") - val smithyHttpEndpointModule = CargoDependency.smithyHttp(runtimeConfig).toType().member("endpoint") - val resolveEndpoint = smithyHttpEndpointModule.member("ResolveEndpoint") - val smithyEndpoint = smithyTypesEndpointModule.member("Endpoint") - val resolveEndpointError = smithyHttpEndpointModule.member("ResolveEndpointError") + private val smithyTypesEndpointModule = RuntimeType.smithyTypes(runtimeConfig).resolve("endpoint") + val smithyHttpEndpointModule = RuntimeType.smithyHttp(runtimeConfig).resolve("endpoint") + val resolveEndpoint = smithyHttpEndpointModule.resolve("ResolveEndpoint") + val smithyEndpoint = smithyTypesEndpointModule.resolve("Endpoint") + val resolveEndpointError = smithyHttpEndpointModule.resolve("ResolveEndpointError") } private fun String.stringToRustName(): String = RustReservedWords.escapeIfNeeded(this.toSnakeCase()) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointResolverGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointResolverGenerator.kt index 0a87d9e81f02d08625661df70ff5eed6b2b0e80c..bd02d2da4c7f877048ff7b7486169d55dee3c2a9 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointResolverGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointResolverGenerator.kt @@ -126,7 +126,7 @@ internal class EndpointResolverGenerator(stdlib: List, ru "endpoint" to types.smithyHttpEndpointModule, "SmithyEndpoint" to types.smithyEndpoint, "EndpointError" to types.resolveEndpointError, - "DiagnosticCollector" to endpointsLib("diagnostic").toType().member("DiagnosticCollector"), + "DiagnosticCollector" to endpointsLib("diagnostic").toType().resolve("DiagnosticCollector"), ) private val context = Context(registry, runtimeConfig) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointTestGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointTestGenerator.kt index 9fd89efdbdce82b7aef7dea65e3726686e2b1c9c..4196865ba4f51eada9db10a93e8cf5099827fd24 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointTestGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointTestGenerator.kt @@ -12,8 +12,6 @@ import software.amazon.smithy.rulesengine.traits.EndpointTestCase import software.amazon.smithy.rulesengine.traits.ExpectedEndpoint import software.amazon.smithy.rust.codegen.client.smithy.endpoint.Types import software.amazon.smithy.rust.codegen.client.smithy.endpoint.rustName -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.Writable import software.amazon.smithy.rust.codegen.core.rustlang.docs import software.amazon.smithy.rust.codegen.core.rustlang.escape @@ -39,8 +37,8 @@ internal class EndpointTestGenerator( "Endpoint" to types.smithyEndpoint, "ResolveEndpoint" to types.resolveEndpoint, "Error" to types.resolveEndpointError, - "Document" to CargoDependency.smithyTypes(runtimeConfig).toType().member("Document"), - "HashMap" to RustType.HashMap.RuntimeType, + "Document" to RuntimeType.document(runtimeConfig), + "HashMap" to RuntimeType.HashMap, ) fun generate(): Writable = writable { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/LiteralGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/LiteralGenerator.kt index c54980115485b5c2679b6453703497e62425fb7d..23530c107a663961532fa856162181ffa36f2fb1 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/LiteralGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/LiteralGenerator.kt @@ -9,13 +9,12 @@ import software.amazon.smithy.rulesengine.language.syntax.Identifier import software.amazon.smithy.rulesengine.language.syntax.expr.Literal import software.amazon.smithy.rulesengine.language.syntax.expr.Template import software.amazon.smithy.rust.codegen.client.smithy.endpoint.Context -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.Writable 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.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.dq import java.util.stream.Stream @@ -27,8 +26,10 @@ import java.util.stream.Stream class LiteralGenerator(private val ownership: Ownership, private val context: Context) : Literal.Vistor { private val runtimeConfig = context.runtimeConfig - private val document = CargoDependency.smithyTypes(runtimeConfig).toType().member("Document") - private val codegenScope = arrayOf("Document" to document, "HashMap" to RustType.HashMap.RuntimeType) + private val codegenScope = arrayOf( + "Document" to RuntimeType.document(runtimeConfig), + "HashMap" to RuntimeType.HashMap, + ) override fun visitBool(b: Boolean) = writable { rust(b.toString()) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/StdLib.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/StdLib.kt index 08401904dbaae7e88f8e58738bed1ee64e915285..d2d43f2858050c516e303f43bdcd063e4ee5c915 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/StdLib.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/StdLib.kt @@ -22,15 +22,15 @@ import software.amazon.smithy.rust.codegen.core.util.dq * Standard library functions available to all generated crates (e.g. not `aws.` specific / prefixed) */ internal val SmithyEndpointsStdLib: List = listOf( - SimpleRuntimeFunction("substring", endpointsLib("substring").toType().member("substring")), - SimpleRuntimeFunction("isValidHostLabel", endpointsLib("host").toType().member("is_valid_host_label")), + SimpleRuntimeFunction("substring", endpointsLib("substring").toType().resolve("substring")), + SimpleRuntimeFunction("isValidHostLabel", endpointsLib("host").toType().resolve("is_valid_host_label")), SimpleRuntimeFunction( "parseURL", - endpointsLib("parse_url", CargoDependency.Http, CargoDependency.Url).toType().member("parse_url"), + endpointsLib("parse_url", CargoDependency.Http, CargoDependency.Url).toType().resolve("parse_url"), ), SimpleRuntimeFunction( "uriEncode", - endpointsLib("uri_encode", CargoDependency.PercentEncoding).toType().member("uri_encode"), + endpointsLib("uri_encode", CargoDependency.PercentEncoding).toType().resolve("uri_encode"), ), ) @@ -40,7 +40,7 @@ internal val SmithyEndpointsStdLib: List = listOf( * This is defined in client-codegen to support running tests—it is not used when generating smithy-native services. */ fun awsStandardLib(runtimeConfig: RuntimeConfig, partitionsDotJson: Node) = listOf( - SimpleRuntimeFunction("aws.parseArn", endpointsLib("arn").toType().member("parse_arn")), + SimpleRuntimeFunction("aws.parseArn", endpointsLib("arn").toType().resolve("parse_arn")), SimpleRuntimeFunction( "aws.isVirtualHostableS3Bucket", endpointsLib( @@ -48,7 +48,7 @@ fun awsStandardLib(runtimeConfig: RuntimeConfig, partitionsDotJson: Node) = list endpointsLib("host"), CargoDependency.OnceCell, CargoDependency.Regex, - ).toType().member("is_virtual_hostable_s3_bucket"), + ).toType().resolve("is_virtual_hostable_s3_bucket"), ), AwsPartitionResolver( runtimeConfig, @@ -70,7 +70,7 @@ class AwsPartitionResolver(runtimeConfig: RuntimeConfig, private val partitionsD CargoDependency.smithyJson(runtimeConfig), CargoDependency.Regex, ).toType() - .member("PartitionResolver"), + .resolve("PartitionResolver"), ) override fun structFieldInit() = 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 ccd8e3c020f9847efffcc28d45e40d178b1c85ef..b016fcff68b42965aee9b97b972ad30f8388b8d2 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,12 @@ 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.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.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.generators.OperationBuildError import software.amazon.smithy.rust.codegen.core.smithy.generators.http.rustFormatString @@ -24,8 +24,6 @@ fun EndpointTrait.prefixFormatString(): String { return this.hostPrefix.rustFormatString("", "") } -fun RuntimeConfig.smithyHttp() = CargoDependency.smithyHttp(this).toType() - class EndpointTraitBindings( model: Model, private val symbolProvider: RustSymbolProvider, @@ -34,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 = RuntimeType.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 fa4e7ae29ac757dc44f3557ba0e10ec606584ed7..0663eecefa2f39fd2bfc1a2a2f53cb2fbd3398a5 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,6 @@ 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.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.rustlang.Writable @@ -108,13 +107,12 @@ class PaginatorGenerator private constructor( "Builder" to operation.inputShape(model).builderSymbol(symbolProvider), // SDK Types - "SdkError" to CargoDependency.smithyHttp(runtimeConfig).toType() - .copy(name = "result::SdkError"), - "client" to CargoDependency.smithyClient(runtimeConfig).toType(), - "fn_stream" to CargoDependency.smithyAsync(runtimeConfig).toType().member("future::fn_stream"), + "SdkError" to RuntimeType.sdkError(runtimeConfig), + "client" to RuntimeType.smithyClient(runtimeConfig), + "fn_stream" to RuntimeType.smithyAsync(runtimeConfig).resolve("future::fn_stream"), // External Types - "Stream" to CargoDependency.TokioStream.toType().member("Stream"), + "Stream" to RuntimeType.TokioStream.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 a50e963ecbd117b0c7dd83d99f0156a6d6981b27..31a86d07ac074e43aeb7bc0c88f9a91af1198a20 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 @@ -13,6 +13,7 @@ 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.rustTemplate 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 /** @@ -40,9 +41,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 smithyHttp.resolve("operation::Operation"), + "ClassifyRetry" to smithyHttp.resolve("retry::ClassifyRetry"), + "RetryKind" to smithyTypes.resolve("retry::RetryKind"), ) renderCustomizableOperationModule(this) @@ -59,9 +60,9 @@ class CustomizableOperationGenerator( val codegenScope = arrayOf( // SDK Types - "http_result" to smithyHttp.member("result"), - "http_body" to smithyHttp.member("body"), - "HttpRequest" to CargoDependency.Http.toType().member("Request"), + "http_result" to smithyHttp.resolve("result"), + "http_body" to smithyHttp.resolve("body"), + "HttpRequest" to RuntimeType.HttpRequest, "handle_generics_decl" to handleGenerics.declaration(), "handle_generics_bounds" to handleGenerics.bounds(), "operation_generics_decl" to operationGenerics.declaration(), @@ -146,9 +147,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 smithyHttp.resolve("response::ParseHttpResponse"), + "NewRequestPolicy" to smithyClient.resolve("retry::NewRequestPolicy"), + "SmithyRetryPolicy" to smithyClient.resolve("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 1495c68ce968acf2d5ab03f2dd96b76010b14e7d..e16c2b1e6450c27fdec8f2a3c797d5eea4851fe3 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,7 +10,6 @@ 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.rust @@ -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 03ce4859ea3273daf58631b934081ce5e0329d35..903b0d25f303352678e4e09994af6a821fefcde6 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,8 +15,6 @@ 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.client.smithy.generators.smithyHttp -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 @@ -58,13 +56,11 @@ class FluentClientGenerator( private val generics: FluentClientGenerics = FlexibleClientGenerics( connectorDefault = null, middlewareDefault = null, - retryDefault = CargoDependency.smithyClient(codegenContext.runtimeConfig).toType() - .member("retry::Standard"), - client = CargoDependency.smithyClient(codegenContext.runtimeConfig).toType(), + retryDefault = RuntimeType.smithyClient(codegenContext.runtimeConfig).resolve("retry::Standard"), + client = RuntimeType.smithyClient(codegenContext.runtimeConfig), ), private val customizations: List = emptyList(), - private val retryClassifier: RuntimeType = CargoDependency.smithyHttp(codegenContext.runtimeConfig).toType() - .member("retry::DefaultResponseRetryClassifier"), + private val retryClassifier: RuntimeType = RuntimeType.smithyHttp(codegenContext.runtimeConfig).resolve("retry::DefaultResponseRetryClassifier"), ) { companion object { fun clientOperationFnName(operationShape: OperationShape, symbolProvider: RustSymbolProvider): String = @@ -81,7 +77,6 @@ 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 core = FluentClientCore(model) @@ -146,7 +141,7 @@ class FluentClientGenerator( """, "generics_decl" to generics.decl, "smithy_inst" to generics.smithyInst, - "client" to clientDep.toType(), + "client" to RuntimeType.smithyClient(runtimeConfig), "client_docs" to writable { customizations.forEach { @@ -160,7 +155,7 @@ class FluentClientGenerator( ) writer.rustBlockTemplate( "impl${generics.inst} Client${generics.inst} #{bounds:W}", - "client" to clientDep.toType(), + "client" to RuntimeType.smithyClient(runtimeConfig), "bounds" to generics.bounds, ) { operations.forEach { operation -> @@ -255,14 +250,14 @@ class FluentClientGenerator( } """, "Inner" to input.builderSymbol(symbolProvider), - "client" to clientDep.toType(), + "client" to RuntimeType.smithyClient(runtimeConfig), "generics" to generics.decl, "operation" to operationSymbol, ) rustBlockTemplate( "impl${generics.inst} ${operationSymbol.name}${generics.inst} #{bounds:W}", - "client" to clientDep.toType(), + "client" to RuntimeType.smithyClient(runtimeConfig), "bounds" to generics.bounds, ) { val outputType = symbolProvider.toSymbol(operation.outputShape(model)) @@ -307,11 +302,11 @@ class FluentClientGenerator( self.handle.client.call(op).await } """, - "ClassifyRetry" to runtimeConfig.smithyHttp().member("retry::ClassifyRetry"), + "ClassifyRetry" to RuntimeType.classifyRetry(runtimeConfig), "OperationError" to errorType, "OperationOutput" to outputType, - "SdkError" to runtimeConfig.smithyHttp().member("result::SdkError"), - "SdkSuccess" to runtimeConfig.smithyHttp().member("result::SdkSuccess"), + "SdkError" to RuntimeType.sdkError(runtimeConfig), + "SdkSuccess" to RuntimeType.sdkSuccess(runtimeConfig), "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 b0e4beecfbc0f88d209f73616b3734fd47f6f744..b3229051e6940530cfb80239c17b4e6bba28d579 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 6e6e167a5a84cb7290f83c93926aa2d47c4c16df..35da7d63b0eb0577d2500a5c7dbc7109af253bd6 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,7 +5,6 @@ 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 @@ -16,16 +15,8 @@ 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 RuntimeType.smithyHttp(runtimeConfig).resolve("property_bag::SharedPropertyBag"), + "SignMessage" to RuntimeType.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 c1860b64a9b594b1127cc2708e14abeacd4c7761..903f779859ffa7d6a235d0057a30d84739d16d1f 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 @@ -22,7 +22,6 @@ import software.amazon.smithy.protocoltests.traits.HttpResponseTestsTrait import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext 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.RustMetadata import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter @@ -68,8 +67,8 @@ class ProtocolTestGenerator( private val instantiator = clientInstantiator(codegenContext) private val codegenScope = arrayOf( - "SmithyHttp" to CargoDependency.smithyHttp(codegenContext.runtimeConfig).toType(), - "AssertEq" to CargoDependency.PrettyAssertions.toType().member("assert_eq!"), + "SmithyHttp" to RuntimeType.smithyHttp(codegenContext.runtimeConfig), + "AssertEq" to RuntimeType.PrettyAssertions.resolve("assert_eq!"), ) sealed class TestCase { @@ -284,7 +283,7 @@ class ProtocolTestGenerator( ) write( "let mut op_response = #T::new(http_response);", - RuntimeType.operationModule(codegenContext.runtimeConfig).member("Response"), + RuntimeType.operationModule(codegenContext.runtimeConfig).resolve("Response"), ) rustTemplate( """ @@ -293,14 +292,13 @@ class ProtocolTestGenerator( let parsed = parser.parse_unloaded(&mut op_response); let parsed = parsed.unwrap_or_else(|| { let (http_response, _) = op_response.into_parts(); - let http_response = http_response.map(|body|#{bytes}::copy_from_slice(body.bytes().unwrap())); + let http_response = http_response.map(|body|#{copy_from_slice}(body.bytes().unwrap())); <#{op} as #{parse_http_response}>::parse_loaded(&parser, &http_response) }); """, "op" to operationSymbol, - "bytes" to RuntimeType.Bytes, - "parse_http_response" to CargoDependency.smithyHttp(codegenContext.runtimeConfig).toType() - .member("response::ParseHttpResponse"), + "copy_from_slice" to RuntimeType.Bytes.resolve("copy_from_slice"), + "parse_http_response" to RuntimeType.parseHttpResponse(codegenContext.runtimeConfig), ) if (expectedShape.hasTrait()) { val errorSymbol = @@ -331,7 +329,7 @@ class ProtocolTestGenerator( when (codegenContext.model.expectShape(member.target)) { is DoubleShape, is FloatShape -> { addUseImports( - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "FloatEquals").toSymbol(), + RuntimeType.protocolTest(codegenContext.runtimeConfig, "FloatEquals").toSymbol(), ) rust( """ @@ -369,8 +367,8 @@ class ProtocolTestGenerator( "#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"), ) } } @@ -411,7 +409,7 @@ class ProtocolTestGenerator( assertOk(rustWriter) { write( "#T($actualExpression, $variableName)", - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "validate_headers"), + RuntimeType.protocolTest(codegenContext.runtimeConfig, "validate_headers"), ) } } @@ -465,7 +463,7 @@ class ProtocolTestGenerator( assertOk(rustWriter) { write( "#T($actualExpression, $expectedVariableName)", - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, checkFunction), + RuntimeType.protocolTest(codegenContext.runtimeConfig, checkFunction), ) } } @@ -475,7 +473,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(codegenContext.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 0f1eac1d676152dadf8ae89291845851482d9f4c..a312bf9bb549c19a9c317c3871f8c6c83d2bb31e 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 @@ -76,8 +76,8 @@ class HttpBoundProtocolTraitImplGenerator( private val codegenScope = arrayOf( "ParseStrict" to RuntimeType.parseStrictResponse(runtimeConfig), - "ParseResponse" to RuntimeType.parseResponse(runtimeConfig), - "http" to RuntimeType.http, + "ParseResponse" to RuntimeType.parseHttpResponse(runtimeConfig), + "http" to RuntimeType.Http, "operation" to RuntimeType.operationModule(runtimeConfig), "Bytes" to RuntimeType.Bytes, ) 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 5953da8a4f0b2a756d55104e0f8fc83979bd343d..5113094a8d509c092636e49c19c882cc1bea2547 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 @@ -13,7 +13,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.config.Event 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.clientIntegrationTest -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 @@ -215,26 +214,10 @@ class FakeSigningConfig( runtimeConfig: RuntimeConfig, ) : EventStreamSigningConfig(runtimeConfig) { 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 RuntimeType.smithyHttp(runtimeConfig).resolve("property_bag::SharedPropertyBag"), + "SignMessageError" to RuntimeType.smithyEventStream(runtimeConfig).resolve("frame::SignMessageError"), + "SignMessage" to RuntimeType.smithyEventStream(runtimeConfig).resolve("frame::SignMessage"), + "Message" to RuntimeType.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/endpoint/rulesgen/ExpressionGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/ExpressionGeneratorTest.kt index bdcd52b02088e3a211a90645cdedba63beac03de..34781b1eac96881c75b3e71bbf69737e2213e654 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/ExpressionGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/ExpressionGeneratorTest.kt @@ -17,9 +17,9 @@ import software.amazon.smithy.rulesengine.language.syntax.expr.Template import software.amazon.smithy.rulesengine.language.syntax.fn.LibraryFunction import software.amazon.smithy.rust.codegen.client.smithy.endpoint.Context import software.amazon.smithy.rust.codegen.client.smithy.endpoint.generators.FunctionRegistry -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest @@ -94,7 +94,7 @@ internal class ExprGeneratorTest { expected.insert("c".to_string(), #{Document}::Array(vec![true.into()])); assert_eq!(expected, #{actual:W}); """, - "Document" to CargoDependency.smithyTypes(TestRuntimeConfig).toType().member("Document"), + "Document" to RuntimeType.document(TestRuntimeConfig), "actual" to gen.generate( Literal.fromNode( Node.objectNode().withMember("a", true).withMember("b", "hello") 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 5448636ac11a0af18fc8bf2589ae5877c41a1fb7..f682446d0507397683b286defe012472a2830261 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 @@ -14,6 +14,7 @@ import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.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.implBlock import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig @@ -69,7 +70,7 @@ internal class EndpointTraitBindingsTest { implBlock(model.lookup("test#GetStatusInput"), sym) { rustBlock( "fn endpoint_prefix(&self) -> std::result::Result<#T::endpoint::EndpointPrefix, #T>", - TestRuntimeConfig.smithyHttp(), + RuntimeType.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 57bd1ae27798b5125a0c25a124dfb2c7350e5dbf..e6b1f53f2f7bc944b6f55d8c8dc44e7afa90ad7a 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 @@ -57,16 +57,16 @@ private class TestProtocolTraitImplGenerator( operationWriter.rustTemplate( """ impl #{parse_strict} for ${operationShape.id.name}{ - type Output = Result<#{output}, #{error}>; - fn parse(&self, _response: &#{response}<#{bytes}>) -> Self::Output { + type Output = Result<#{Output}, #{Error}>; + fn parse(&self, _response: &#{Response}<#{Bytes}>) -> Self::Output { ${operationWriter.escape(correctResponse)} } }""", "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, + "Output" to symbolProvider.toSymbol(operationShape.outputShape(codegenContext.model)), + "Error" to operationShape.errorSymbol(codegenContext.model, symbolProvider, codegenContext.target), + "Response" to RuntimeType.HttpResponse, + "Bytes" to RuntimeType.Bytes, ) } } 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 948304c569bc2e33f959581e935a1b32ebe722ae..6d355da68a99ff0c03744f11a6e53dbe982fc03e 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,7 +112,7 @@ class InlineDependency( } } -fun InlineDependency.toType() = RuntimeType(name = null, dependency = this, namespace = module.fullyQualifiedPath()) +fun InlineDependency.toType() = RuntimeType(module.fullyQualifiedPath(), this) data class Feature(val name: String, val default: Boolean, val deps: List) @@ -183,7 +183,7 @@ data class CargoDependency( } fun toType(): RuntimeType { - return RuntimeType(null, this, rustName) + return RuntimeType(rustName, this) } companion object { @@ -233,18 +233,17 @@ data class CargoDependency( features = setOf("env-filter", "json"), ) - fun smithyAsync(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("async") - fun smithyChecksums(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("checksums") - fun smithyClient(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("client") - fun smithyEventStream(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("eventstream") - fun smithyHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("http") - fun smithyHttpTower(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("http-tower") - fun smithyJson(runtimeConfig: RuntimeConfig): CargoDependency = runtimeConfig.runtimeCrate("json") + 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 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.runtimeCrate("protocol-test", scope = DependencyScope.Dev) - - fun smithyQuery(runtimeConfig: RuntimeConfig): CargoDependency = runtimeConfig.runtimeCrate("query") - fun smithyTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("types") - fun smithyXml(runtimeConfig: RuntimeConfig): CargoDependency = runtimeConfig.runtimeCrate("xml") + 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") } } 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 9654fa966c2af6b299a3fae7e00eda126612ca9d..489b3f08c074decea4cb7f1ad89910b9938b337c 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 @@ -6,6 +6,7 @@ package software.amazon.smithy.rust.codegen.core.rustlang import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.dq /** @@ -23,13 +24,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 @@ -91,8 +90,9 @@ sealed class RustType { } object String : RustType() { - override val name: kotlin.String = "String" - override val namespace = "std::string" + private val runtimeType = RuntimeType.String + override val name = runtimeType.name + override val namespace = runtimeType.namespace } data class Float(val precision: Int) : RustType() { @@ -109,18 +109,18 @@ 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 = RuntimeType.HashMap.name + override val namespace = RuntimeType.HashMap.namespace companion object { - val RuntimeType = RuntimeType("HashMap", dependency = null, namespace = "std::collections") + val Type = RuntimeType.HashMap.name + val Namespace = RuntimeType.HashMap.namespace } } data class HashSet(override val member: RustType) : RustType(), Container { - override val name = Type - override val namespace = Namespace + override val name = RuntimeType.Vec.name + override val namespace = RuntimeType.Vec.namespace companion object { // This is Vec intentionally. Note the following passage from the Smithy spec: @@ -128,9 +128,8 @@ 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 Type = RuntimeType.Vec.name + val Namespace = RuntimeType.Vec.namespace } } @@ -139,8 +138,9 @@ sealed class RustType { } data class Option(override val member: RustType) : RustType(), Container { - override val name = "Option" - override val namespace = "std::option" + private val runtimeType = RuntimeType.Option + override val name = runtimeType.name + override val namespace = runtimeType.namespace /** Convert `Option` to `Option<&T>` **/ fun referenced(lifetime: kotlin.String?): Option { @@ -149,14 +149,15 @@ sealed class RustType { } data class MaybeConstrained(override val member: RustType) : RustType(), Container { - val runtimeType: RuntimeType = RuntimeType.MaybeConstrained() - override val name = runtimeType.name!! + private val runtimeType = RuntimeType.MaybeConstrained + override val name = runtimeType.name override val namespace = runtimeType.namespace } data class Box(override val member: RustType) : RustType(), Container { - override val name = "Box" - override val namespace = "std::boxed" + private val runtimeType = RuntimeType.Box + override val name = runtimeType.name + override val namespace = runtimeType.namespace } data class Dyn(override val member: RustType) : RustType(), Container { @@ -165,8 +166,9 @@ sealed class RustType { } data class Vec(override val member: RustType) : RustType(), Container { - override val name = "Vec" - override val namespace = "std::vec" + private val runtimeType: RuntimeType = RuntimeType.Vec + override val name = runtimeType.name + override val namespace = runtimeType.namespace } data class Opaque(override val name: kotlin.String, override val namespace: kotlin.String? = null) : RustType() @@ -452,7 +454,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(")]") @@ -481,7 +483,11 @@ sealed class Attribute { val bang = if (container) "!" else "" writer.raw("#$bang[$annotation]") symbols.forEach { - writer.addDependency(it.dependency) + try { + writer.addDependency(it.dependency) + } catch (ex: Exception) { + PANIC("failed to add dependency for RuntimeType $it") + } } } 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 5cf2180ee2f72a1a788ebf88968453f20041766f..df3b66e6baf278ac0a94e10d00347aa80c12f82d 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"), + * runtimeConfig.smithyHttp().resolve("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 5ddb7e580d293d2ac1b88092af384a69311644a4..7d29b3c0673d6de9f29ffc3d7e19274b31eb4691 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 @@ -16,7 +16,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo import software.amazon.smithy.rust.codegen.core.rustlang.DependencyLocation import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency -import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency.Companion.constrained import software.amazon.smithy.rust.codegen.core.rustlang.Local import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule @@ -24,7 +23,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.rustInlineTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.toType import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.util.orNull import java.util.Optional @@ -72,7 +70,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 { @@ -89,7 +87,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, ) } @@ -97,7 +95,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, @@ -111,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` */ @@ -144,193 +153,151 @@ 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 } /** * The companion object contains commonly used RuntimeTypes */ companion object { - fun errorKind(runtimeConfig: RuntimeConfig) = RuntimeType( - "ErrorKind", - dependency = CargoDependency.smithyTypes(runtimeConfig), - namespace = "${runtimeConfig.crateSrcPrefix}_types::retry", - ) - - fun provideErrorKind(runtimeConfig: RuntimeConfig) = RuntimeType( - "ProvideErrorKind", - dependency = CargoDependency.smithyTypes(runtimeConfig), - namespace = "${runtimeConfig.crateSrcPrefix}_types::retry", - ) - - 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 Eq = std.member("cmp::Eq") - val From = RuntimeType("From", dependency = null, namespace = "std::convert") - val Hash = std.member("hash::Hash") - 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}_types") - - fun GenericError(runtimeConfig: RuntimeConfig) = - RuntimeType("Error", CargoDependency.smithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_types") - - fun Blob(runtimeConfig: RuntimeConfig) = - RuntimeType("Blob", CargoDependency.smithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_types") - - fun ByteStream(runtimeConfig: RuntimeConfig) = - RuntimeType( - "ByteStream", - CargoDependency.smithyHttp(runtimeConfig), - "${runtimeConfig.crateSrcPrefix}_http::byte_stream", - ) - - fun Document(runtimeConfig: RuntimeConfig): RuntimeType = - RuntimeType("Document", CargoDependency.smithyTypes(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_types") - - fun LabelFormat(runtimeConfig: RuntimeConfig, func: String) = - RuntimeType(func, CargoDependency.smithyHttp(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http::label") - - fun QueryFormat(runtimeConfig: RuntimeConfig, func: String) = - RuntimeType(func, CargoDependency.smithyHttp(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http::query") - - fun Base64Encode(runtimeConfig: RuntimeConfig): RuntimeType = - RuntimeType( - "encode", - CargoDependency.smithyTypes(runtimeConfig), - "${runtimeConfig.crateSrcPrefix}_types::base64", - ) - - fun Base64Decode(runtimeConfig: RuntimeConfig): RuntimeType = - RuntimeType( - "decode", - CargoDependency.smithyTypes(runtimeConfig), - "${runtimeConfig.crateSrcPrefix}_types::base64", - ) - - fun TimestampFormat(runtimeConfig: RuntimeConfig, format: TimestampFormatTrait.Format): RuntimeType { + // stdlib types + val std = RuntimeType("std") + val stdCmp = std.resolve("cmp") + val stdFmt = std.resolve("fmt") + val stdConvert = std.resolve("convert") + val AsRef = stdConvert.resolve("AsRef") + val ByteSlab = std.resolve("vec::Vec") + val Box = std.resolve("boxed::Box") + val Clone = std.resolve("clone::Clone") + val Cow = std.resolve("borrow::Cow") + val Debug = stdFmt.resolve("Debug") + val Default = std.resolve("default::Default") + val Display = stdFmt.resolve("Display") + val Eq = stdCmp.resolve("Eq") + val From = stdConvert.resolve("From") + val Hash = std.resolve("hash::Hash") + val HashMap = std.resolve("collections::HashMap") + val Ord = stdCmp.resolve("Ord") + val Option = std.resolve("option::Option") + val PartialEq = stdCmp.resolve("PartialEq") + val PartialOrd = stdCmp.resolve("PartialOrd") + val Phantom = std.resolve("marker::PhantomData") + val StdError = std.resolve("error::Error") + val String = std.resolve("string::String") + val TryFrom = stdConvert.resolve("TryFrom") + val Vec = std.resolve("vec::Vec") + + // external cargo dependency types + val Bytes = CargoDependency.Bytes.toType().resolve("Bytes") + val Http = CargoDependency.Http.toType() + val HttpBody = CargoDependency.HttpBody.toType() + val HttpHeaderMap = Http.resolve("HeaderMap") + val HttpRequest = Http.resolve("Request") + val HttpRequestBuilder = Http.resolve("request::Builder") + val HttpResponse = Http.resolve("Response") + val HttpResponseBuilder = Http.resolve("response::Builder") + val Hyper = CargoDependency.Hyper.toType() + val LazyStatic = CargoDependency.LazyStatic.toType() + val Md5 = CargoDependency.Md5.toType() + val OnceCell = CargoDependency.OnceCell.toType() + val PercentEncoding = CargoDependency.PercentEncoding.toType() + val PrettyAssertions = CargoDependency.PrettyAssertions.toType() + val Regex = CargoDependency.Regex.toType() + val TokioStream = CargoDependency.TokioStream.toType() + val Tower = CargoDependency.Tower.toType() + val Tracing = CargoDependency.Tracing.toType() + + // codegen types + val Config = RuntimeType("crate::config") + val ConstrainedTrait = RuntimeType("crate::constrained::Constrained", InlineDependency.constrained()) + val MaybeConstrained = RuntimeType("crate::constrained::MaybeConstrained", InlineDependency.constrained()) + + // smithy runtime types + 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() + private fun smithyProtocolTest(runtimeConfig: RuntimeConfig) = CargoDependency.smithyProtocolTestHelpers(runtimeConfig).toType() + + // smithy runtime type members + 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 classifyRetry(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("retry::ClassifyRetry") + 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).resolve("label::$func") + fun operation(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("operation::Operation") + fun operationModule(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("operation") + fun parseHttpResponse(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 sdkError(runtimeConfig: RuntimeConfig): RuntimeType = smithyHttp(runtimeConfig).resolve("result::SdkError") + fun sdkSuccess(runtimeConfig: RuntimeConfig): RuntimeType = smithyHttp(runtimeConfig).resolve("result::SdkSuccess") + 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}_types::date_time::Format", - ) - } - - fun ConstrainedTrait() = constrained().toType().member("Constrained") - fun MaybeConstrained() = constrained().toType().member("MaybeConstrained") - - fun ProtocolTestHelper(runtimeConfig: RuntimeConfig, func: String): RuntimeType = - RuntimeType( - func, CargoDependency.smithyProtocolTestHelpers(runtimeConfig), "aws_smithy_protocol_test", - ) - - val http = CargoDependency.Http.toType() - 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).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, + "${module.fullyQualifiedPath()}::$name", dependency = InlineDependency(name, module, listOf(), func), - namespace = module.fullyQualifiedPath(), - ) - - 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/SymbolMetadataProvider.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt index 6ae9886cec7a8b10733f3adcb5863296044b54de..ac2bd6398bf4a9a538f1ecd6e9b04f89aa42920c 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 @@ -137,13 +137,13 @@ class BaseSymbolMetadataProvider( override fun enumMeta(stringShape: StringShape): RustMetadata { return containerDefault(stringShape).withDerives( - RuntimeType.std.member("hash::Hash"), + RuntimeType.std.resolve("hash::Hash"), ).withDerives( // enums can be eq because they can only contain ints and strings - RuntimeType.std.member("cmp::Eq"), + RuntimeType.std.resolve("cmp::Eq"), // enums can be Ord because they can only contain ints and 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/SymbolVisitor.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt index 29ce9bced2b04892dedd4049e0a449357bbf4e5a..5bd41943d9133fd73d0469babc9330cc887dc451 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 @@ -226,7 +226,7 @@ open class SymbolVisitor( } override fun blobShape(shape: BlobShape?): Symbol { - return RuntimeType.Blob(config.runtimeConfig).toSymbol() + return RuntimeType.blob(config.runtimeConfig).toSymbol() } /** @@ -290,7 +290,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 { @@ -356,7 +356,7 @@ open class SymbolVisitor( } override fun timestampShape(shape: TimestampShape?): Symbol { - return RuntimeType.DateTime(config.runtimeConfig).toSymbol() + return RuntimeType.dateTime(config.runtimeConfig).toSymbol() } } 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 159c1974d4badf2e77f73b4d92096a37ea7666a5..b612ca19fcb329798e0ca442c1af5ce39bbc550b 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 @@ -66,8 +66,8 @@ fun StructureShape.builderSymbol(symbolProvider: RustSymbolProvider): Symbol { .build() } -fun RuntimeConfig.operationBuildError() = RuntimeType.operationModule(this).member("error::BuildError") -fun RuntimeConfig.serializationError() = RuntimeType.operationModule(this).member("error::SerializationError") +fun RuntimeConfig.operationBuildError() = RuntimeType.operationModule(this).resolve("error::BuildError") +fun RuntimeConfig.serializationError() = RuntimeType.operationModule(this).resolve("error::SerializationError") class OperationBuildError(private val runtimeConfig: RuntimeConfig) { fun missingField(field: String, details: String) = writable { @@ -236,7 +236,7 @@ class BuilderGenerator( private fun renderDebugImpl(writer: RustWriter) { writer.rustBlock("impl #T for $builderName", RuntimeType.Debug) { - writer.rustBlock("fn fmt(&self, f: &mut #1T::Formatter<'_>) -> #1T::Result", RuntimeType.stdfmt) { + writer.rustBlock("fn fmt(&self, f: &mut #1T::Formatter<'_>) -> #1T::Result", RuntimeType.stdFmt) { rust("""let mut formatter = f.debug_struct(${builderName.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/EnumGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt index 011c8152ec3dd650e7105086eb3e4f734b03550c..b5c4d1ace0b79ba2a8b0eea093f7040b0a55e09c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt @@ -251,7 +251,7 @@ open class EnumGenerator( } """, "Debug" to RuntimeType.Debug, - "StdFmt" to RuntimeType.stdfmt, + "StdFmt" to RuntimeType.stdFmt, ) } 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 f188aba5d2793878eb8aedccc8e1bcd4fd286f64..4da5b667841ad98e60308075e3a3b489762a0593 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 @@ -109,7 +109,7 @@ open class Instantiator( // Wrapped Shapes is TimestampShape -> writer.rust( "#T::from_secs(${(data as NumberNode).value})", - RuntimeType.DateTime(runtimeConfig), + RuntimeType.dateTime(runtimeConfig), ) /** @@ -120,12 +120,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), ) } @@ -138,7 +138,7 @@ open class Instantiator( writer.rust( """<#T as #T>::parse_smithy_primitive(${data.value.dq()}).expect("invalid string for number")""", numberSymbol, - CargoDependency.smithyTypes(runtimeConfig).toType().member("primitive::Parse"), + RuntimeType.smithyTypes(runtimeConfig).resolve("primitive::Parse"), ) } @@ -154,8 +154,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.member("deserialize::token::expect_document"), - "json_token_iter" to smithyJson.member("deserialize::json_token_iter"), + "expect_document" to smithyJson.resolve("deserialize::token::expect_document"), + "json_token_iter" to smithyJson.resolve("deserialize::json_token_iter"), ) } @@ -218,10 +218,10 @@ open class Instantiator( */ private fun renderMap(writer: RustWriter, shape: MapShape, data: ObjectNode, ctx: Ctx) { if (data.members.isEmpty()) { - writer.rust("#T::new()", RustType.HashMap.RuntimeType) + writer.rust("#T::new()", RuntimeType.HashMap) } else { writer.rustBlock("") { - rust("let mut ret = #T::new();", RustType.HashMap.RuntimeType) + rust("let mut ret = #T::new();", RuntimeType.HashMap) for ((key, value) in data.members) { withBlock("ret.insert(", ");") { renderMember(this, shape.key, key, ctx) 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 2fb106a609fd56e61b564a4ccff810888e6d761b..5f4e9ffb91036b420a826cc68f8e10c663bf2605 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 @@ -88,7 +88,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 #1T::Formatter<'_>) -> #1T::Result", RuntimeType.stdFmt) { 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 dd46fcba423c87501e0f00125c90eea95aceaa2c..b79200f952ab6bd145a069ccfcc2dd076be04e79 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/UnionGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt index 827dfa89f556fa34c97f0308b06618fc33ab02f3..15615f6069b015648648085824c3736055a57fd8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt @@ -137,13 +137,13 @@ class UnionGenerator( } """, "Debug" to RuntimeType.Debug, - "StdFmt" to RuntimeType.stdfmt, + "StdFmt" to RuntimeType.stdFmt, ) } private fun renderDebugImpl() { writer.rustBlock("impl #T for ${unionSymbol.name}", RuntimeType.Debug) { - writer.rustBlock("fn fmt(&self, f: &mut #1T::Formatter<'_>) -> #1T::Result", RuntimeType.stdfmt) { + writer.rustBlock("fn fmt(&self, f: &mut #1T::Formatter<'_>) -> #1T::Result", RuntimeType.stdFmt) { rustBlock("match self") { sortedMembers.forEach { member -> val memberName = symbolProvider.toMemberName(member) 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 485878f033e5c847018ef7dc328bd0bcfb49a59d..d4dbc2c7bb15f8d2f83d8e73c47601e254b44da9 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 @@ -13,7 +13,6 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.RetryableTrait 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.RustMetadata import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter @@ -94,7 +93,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) { @@ -125,12 +124,12 @@ 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) private val createUnhandledError = - CargoDependency.smithyHttp(runtimeConfig).toType().member("result::CreateUnhandledError") + RuntimeType.smithyHttp(runtimeConfig).resolve("result::CreateUnhandledError") 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) } @@ -155,7 +154,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.rustBlock("impl #T for ${errorSymbol.name}", createUnhandledError) { 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 de6c09a5ac2627dd9550dde54e29821cd341a4ea..6ce5bc8c9381c8b238ab022081f56acf21174437 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 e43c8a444eb0ebcb2b0ed6c08f8e0a0322d7f728..bf3c8ccb995614770704cad2282f93ffcf1659a5 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 @@ -9,7 +9,6 @@ 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.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter @@ -51,7 +50,8 @@ 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).toType().member("result::SdkError") + private val sdkError = RuntimeType.sdkError(codegenContext.runtimeConfig) + 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 1dfd208acec35dd20fcb2d5b739cf517f8dcb1a8..597ff267e26b1cae641ce2070f8cedbec5dc1330 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 @@ -26,7 +26,6 @@ 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 @@ -125,9 +124,9 @@ class HttpBindingGenerator( private val model = codegenContext.model private val service = codegenContext.serviceShape private val index = HttpBindingIndex.of(model) - private val headerUtil = CargoDependency.smithyHttp(runtimeConfig).toType().member("header") + private val headerUtil = RuntimeType.smithyHttp(runtimeConfig).resolve("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") /** @@ -149,7 +148,7 @@ class HttpBindingGenerator( return RuntimeType.forInlineFun(fnName, httpSerdeModule) { rustBlock( "pub(crate) fn $fnName(header_map: &#T::HeaderMap) -> std::result::Result<#T, #T::ParseError>", - RuntimeType.http, + RuntimeType.Http, outputT, headerUtil, ) { @@ -168,7 +167,7 @@ class HttpBindingGenerator( val inner = RuntimeType.forInlineFun("${fnName}_inner", httpSerdeModule) { rustBlock( "pub fn ${fnName}_inner(headers: #T::header::ValueIter) -> std::result::Result, #T::ParseError>", - RuntimeType.http, + RuntimeType.Http, symbolProvider.toSymbol(model.expectShape(target.value.target)), headerUtil, ) { @@ -179,7 +178,7 @@ class HttpBindingGenerator( return RuntimeType.forInlineFun(fnName, httpSerdeModule) { rustBlock( "pub(crate) fn $fnName(header_map: &#T::HeaderMap) -> std::result::Result<#T, #T::ParseError>", - RuntimeType.http, + RuntimeType.Http, returnTypeSymbol, headerUtil, ) { @@ -368,7 +367,7 @@ class HttpBindingGenerator( HttpBinding.Location.HEADER, defaultTimestampFormat, ) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) rust( "let $parsedValue: Vec<${coreType.render()}> = #T::many_dates(headers, #T)?;", headerUtil, @@ -393,7 +392,7 @@ class HttpBindingGenerator( .and_then(|bytes|String::from_utf8(bytes).map_err(|_|#{header}::ParseError::new("base64 encoded data was not valid utf-8"))) ).collect(); """, - "base_64_decode" to RuntimeType.Base64Decode(runtimeConfig), + "base_64_decode" to RuntimeType.base64Decode(runtimeConfig), "header" to headerUtil, ) rust("let $parsedValue = $parsedValue?;") @@ -635,7 +634,7 @@ class HttpBindingGenerator( val block: RustWriter.(value: ValueExpression) -> Unit = { variableName -> if (shape.isPrimitive()) { - val encoder = CargoDependency.smithyTypes(runtimeConfig).toType().member("primitive::Encoder") + val encoder = RuntimeType.smithyTypes(runtimeConfig).resolve("primitive::Encoder") rust("let mut encoder = #T::from(${variableName.asValue()});", encoder) } val formatted = headerFmtFun( @@ -737,7 +736,7 @@ class HttpBindingGenerator( fun quoteValue(value: String): String { // Timestamp shapes are not quoted in header lists return if (isMultiValuedHeader && !target.isTimestampShape) { - val quoteFn = writer.format(headerUtil.member("quote_header_value")) + val quoteFn = writer.format(headerUtil.resolve("quote_header_value")) "$quoteFn($value)" } else { value @@ -746,7 +745,7 @@ 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("$targetName.as_str()") @@ -754,7 +753,7 @@ class HttpBindingGenerator( } target.isTimestampShape -> { - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) quoteValue("$targetName.fmt(${writer.format(timestampFormatType)})?") } 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 e5d0a74c8ee47b27e8d9138c35635bace354f3f8..25b39008fb93d29b5d98153f783c483f7e1b5c2a 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 @@ -17,7 +17,6 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.EnumTrait 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.autoDeref import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -74,7 +73,7 @@ class RequestBindingGenerator( private val httpBindingGenerator = HttpBindingGenerator(protocol, codegenContext, codegenContext.symbolProvider, operationShape, ::builderSymbol) private val index = HttpBindingIndex.of(model) - private val encoder = CargoDependency.smithyTypes(runtimeConfig).toType().member("primitive::Encoder") + private val encoder = RuntimeType.smithyTypes(runtimeConfig).resolve("primitive::Encoder") private val codegenScope = arrayOf( "BuildError" to runtimeConfig.operationBuildError(), @@ -131,7 +130,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, @@ -174,7 +173,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` @@ -193,7 +192,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, @@ -272,15 +271,15 @@ 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)})?" } @@ -308,11 +307,11 @@ 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) } @@ -320,8 +319,8 @@ class RequestBindingGenerator( 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)})?;") } 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 2a93d75ddfcb7a249f5a28767c876a1d93a3c8fe..9e0d12b44e63e289575b4ffcc026d27360e6e54f 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,7 +6,6 @@ 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.Writable import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.withBlock @@ -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( *extraCodegenScope, "PathSegmentsVec" to pathSegmentsVec, "QuerySegmentsVec" to querySegmentsVec, - "Method" to CargoDependency.Http.toType().member("Method"), + "Method" to RuntimeType.Http.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 47747babd16b764f6072d0afac3ce0c83db6c26e..959d71cf8b546b751647bb7f1bad5c52a585fd95 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,7 +9,6 @@ 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.docs import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -48,8 +47,8 @@ open class MakeOperationGenerator( protected val runtimeConfig = codegenContext.runtimeConfig protected val symbolProvider = codegenContext.symbolProvider protected val httpBindingResolver = protocol.httpBindingResolver - private val defaultClassifier = CargoDependency.smithyHttp(runtimeConfig) - .toType().member("retry::DefaultResponseRetryClassifier") + private val defaultClassifier = RuntimeType.smithyHttp(runtimeConfig) + .resolve("retry::DefaultResponseRetryClassifier") private val sdkId = codegenContext.serviceShape.getTrait()?.sdkId?.lowercase()?.replace(" ", "") @@ -57,12 +56,12 @@ open class MakeOperationGenerator( private val codegenScope = arrayOf( "config" to RuntimeType.Config, - "header_util" to CargoDependency.smithyHttp(runtimeConfig).toType().member("header"), - "http" to RuntimeType.http, + "header_util" to RuntimeType.smithyHttp(runtimeConfig).resolve("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 RuntimeType.sdkBody(runtimeConfig), ) fun generateMakeOperation( 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 c5c13db5f158818789faa34213f30c101ec6d54c..8c0ad26d88c6eab82fbab8ea8408d7d9715e8883 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 @@ -111,11 +111,11 @@ open class AwsJson( private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( "Bytes" to RuntimeType.Bytes, - "Error" to RuntimeType.GenericError(runtimeConfig), - "HeaderMap" to RuntimeType.http.member("HeaderMap"), + "Error" to RuntimeType.genericError(runtimeConfig), + "HeaderMap" to RuntimeType.Http.resolve("HeaderMap"), "JsonError" to CargoDependency.smithyJson(runtimeConfig).toType() - .member("deserialize::error::DeserializeError"), - "Response" to RuntimeType.http.member("Response"), + .resolve("deserialize::error::DeserializeError"), + "Response" to RuntimeType.Http.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 60985edd5be72307186152e57d2229fecdf83119..6bb7a62a58e950b1b698bfb3ce80c34eebb071cd 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 @@ -14,7 +14,6 @@ import software.amazon.smithy.model.shapes.StructureShape 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.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate @@ -46,10 +45,10 @@ class AwsQueryProtocol(private val codegenContext: CodegenContext) : Protocol { 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"), - "XmlDecodeError" to CargoDependency.smithyXml(runtimeConfig).toType().member("decode::XmlDecodeError"), + "Error" to RuntimeType.genericError(runtimeConfig), + "HeaderMap" to RuntimeType.HttpHeaderMap, + "Response" to RuntimeType.HttpResponse, + "XmlDecodeError" to RuntimeType.smithyXml(runtimeConfig).resolve("decode::XmlDecodeError"), ) 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 2ab550048f438bc3847b36ed50e8415217803504..c388b8e85b40ffdc1f1ed481159f5dc768428480 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 @@ -11,7 +11,6 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape 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.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate @@ -28,10 +27,10 @@ class Ec2QueryProtocol(private val codegenContext: CodegenContext) : Protocol { 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"), - "XmlDecodeError" to CargoDependency.smithyXml(runtimeConfig).toType().member("decode::XmlDecodeError"), + "Error" to RuntimeType.genericError(runtimeConfig), + "HeaderMap" to RuntimeType.HttpHeaderMap, + "Response" to RuntimeType.HttpResponse, + "XmlDecodeError" to RuntimeType.smithyXml(runtimeConfig).resolve("decode::XmlDecodeError"), ) 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 4c6d6141391849c0a27498d361f1b3bec55666a9..3751732a5b2431646a35650c2f595ca0ac888f07 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 @@ -54,16 +54,14 @@ 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 smithyEventStream = RuntimeType.smithyEventStream(runtimeConfig) private val codegenScope = arrayOf( "hyper" to CargoDependency.HyperWithStream.toType(), "SdkBody" to RuntimeType.sdkBody(runtimeConfig), "BuildError" to runtimeConfig.operationBuildError(), - "SmithyHttp" to CargoDependency.smithyHttp(runtimeConfig).toType(), - "NoOpSigner" to RuntimeType("NoOpSigner", smithyEventStream, "aws_smithy_eventstream::frame"), + "SmithyHttp" to RuntimeType.smithyHttp(runtimeConfig), + "NoOpSigner" to smithyEventStream.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 6e8cf0f13ab9b6154c1b8c1b446b04bed3ca65b9..cbcd2d511b05cbcb95359c3009422cbc1d1e4f8c 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 @@ -66,11 +66,11 @@ 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"), + "Error" to RuntimeType.genericError(runtimeConfig), + "HeaderMap" to RuntimeType.Http.resolve("HeaderMap"), "JsonError" to CargoDependency.smithyJson(runtimeConfig).toType() - .member("deserialize::error::DeserializeError"), - "Response" to RuntimeType.http.member("Response"), + .resolve("deserialize::error::DeserializeError"), + "Response" to RuntimeType.Http.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 a87f607670ad5d44d85a5fc7bed400fdbd28d87e..44a9631ef74342e0d8c67db75c4308cc9ac32899 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 @@ -10,7 +10,6 @@ import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape 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.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate @@ -28,10 +27,10 @@ open class RestXml(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"), - "Response" to RuntimeType.http.member("Response"), - "XmlDecodeError" to CargoDependency.smithyXml(runtimeConfig).toType().member("decode::XmlDecodeError"), + "Error" to RuntimeType.genericError(runtimeConfig), + "HeaderMap" to RuntimeType.HttpHeaderMap, + "Response" to RuntimeType.HttpResponse, + "XmlDecodeError" to RuntimeType.smithyXml(runtimeConfig).resolve("decode::XmlDecodeError"), ) 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 da4c4d396ddb202048643847b72d619d5cec95bb..b78f347002a0c353546e83386a40141dbb35a767 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 @@ -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.conditionalBlock @@ -58,25 +57,26 @@ class EventStreamUnmarshallerGenerator( private val codegenTarget = codegenContext.target private val runtimeConfig = codegenContext.runtimeConfig private val unionSymbol = symbolProvider.toSymbol(unionShape) - private val smithyEventStream = CargoDependency.smithyEventStream(runtimeConfig) private val errorSymbol = if (codegenTarget == CodegenTarget.SERVER && unionShape.eventStreamErrors().isEmpty()) { - RuntimeType("MessageStreamError", smithyEventStream, "aws_smithy_http::event_stream").toSymbol() + RuntimeType.smithyHttp(runtimeConfig).resolve("event_stream::MessageStreamError").toSymbol() } else { unionShape.eventStreamErrorSymbol(model, symbolProvider, codegenTarget).toSymbol() } + private val smithyEventStream = RuntimeType.smithyEventStream(runtimeConfig) 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 RuntimeType.blob(runtimeConfig), + "expect_fns" to smithyEventStream.resolve("smithy"), + "MarshallMessage" to smithyEventStream.resolve("frame::MarshallMessage"), + "Message" to smithyEventStream.resolve("frame::Message"), + "Header" to smithyEventStream.resolve("frame::Header"), + "HeaderValue" to smithyEventStream.resolve("frame::HeaderValue"), + "Error" to smithyEventStream.resolve("error::Error"), "OpError" to errorSymbol, - "SmithyError" to RuntimeType("Error", CargoDependency.smithyTypes(runtimeConfig), "aws_smithy_types"), - "tracing" to CargoDependency.Tracing.toType(), - "UnmarshalledMessage" to RuntimeType("UnmarshalledMessage", smithyEventStream, "aws_smithy_eventstream::frame"), - "UnmarshallMessage" to RuntimeType("UnmarshallMessage", smithyEventStream, "aws_smithy_eventstream::frame"), + "SmithyError" to RuntimeType.smithyTypes(runtimeConfig).resolve("Error"), + "tracing" to RuntimeType.Tracing, + "UnmarshalledMessage" to smithyEventStream.resolve("frame::UnmarshalledMessage"), + "UnmarshallMessage" to smithyEventStream.resolve("frame::UnmarshallMessage"), ) fun render(): RuntimeType { @@ -411,6 +411,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 6d4148122c8fd3e9df911fea130dbd3f7dee2428..731729b828d790496724e91fe368aea2031a9a9d 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 @@ -25,7 +25,6 @@ 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.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.escape @@ -101,20 +100,20 @@ class JsonParserGenerator( private val jsonDeserModule = RustModule.private("json_deser") private val typeConversionGenerator = TypeConversionGenerator(model, symbolProvider, runtimeConfig) private val codegenScope = arrayOf( - "Error" to smithyJson.member("deserialize::error::DeserializeError"), - "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"), - "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"), + "Error" to smithyJson.resolve("deserialize::error::DeserializeError"), + "expect_blob_or_null" to smithyJson.resolve("deserialize::token::expect_blob_or_null"), + "expect_bool_or_null" to smithyJson.resolve("deserialize::token::expect_bool_or_null"), + "expect_document" to smithyJson.resolve("deserialize::token::expect_document"), + "expect_number_or_null" to smithyJson.resolve("deserialize::token::expect_number_or_null"), + "expect_start_array" to smithyJson.resolve("deserialize::token::expect_start_array"), + "expect_start_object" to smithyJson.resolve("deserialize::token::expect_start_object"), + "expect_string_or_null" to smithyJson.resolve("deserialize::token::expect_string_or_null"), + "expect_timestamp_or_null" to smithyJson.resolve("deserialize::token::expect_timestamp_or_null"), + "json_token_iter" to smithyJson.resolve("deserialize::json_token_iter"), + "Peekable" to RuntimeType.std.resolve("iter::Peekable"), + "skip_value" to smithyJson.resolve("deserialize::token::skip_value"), + "skip_to_end" to smithyJson.resolve("deserialize::token::skip_to_end"), + "Token" to smithyJson.resolve("deserialize::Token"), "or_empty" to orEmptyJson(), ) @@ -348,7 +347,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, @@ -423,7 +422,7 @@ class JsonParserGenerator( *codegenScope, ) { startObjectOrNull { - rust("let mut map = #T::new();", RustType.HashMap.RuntimeType) + rust("let mut map = #T::new();", RuntimeType.HashMap) objectKeyLoop(hasMembers = true) { withBlock("let key =", "?;") { deserializeStringInner(keyTarget, "key") 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 1a9b6ae39d34c7044444cf44ea61863e2d4f3fb1..74b71bb7a90262250d3ed175c8bd31f835d30bb4 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 @@ -98,18 +98,18 @@ class XmlBindingTraitParserGenerator( private val symbolProvider = codegenContext.symbolProvider private val smithyXml = CargoDependency.smithyXml(codegenContext.runtimeConfig).toType() - private val xmlDecodeError = smithyXml.member("decode::XmlDecodeError") + private val xmlDecodeError = smithyXml.resolve("decode::XmlDecodeError") - private val scopedDecoder = smithyXml.member("decode::ScopedDecoder") + private val scopedDecoder = smithyXml.resolve("decode::ScopedDecoder") private val runtimeConfig = codegenContext.runtimeConfig // The symbols we want all the time private val codegenScope = arrayOf( - "Blob" to RuntimeType.Blob(runtimeConfig), - "Document" to smithyXml.member("decode::Document"), + "Blob" to RuntimeType.blob(runtimeConfig), + "Document" to smithyXml.resolve("decode::Document"), "XmlDecodeError" to xmlDecodeError, - "next_start_element" to smithyXml.member("decode::next_start_element"), - "try_data" to smithyXml.member("decode::try_data"), + "next_start_element" to smithyXml.resolve("decode::next_start_element"), + "try_data" to smithyXml.resolve("decode::try_data"), "ScopedDecoder" to scopedDecoder, "aws_smithy_types" to CargoDependency.smithyTypes(runtimeConfig).toType(), ) @@ -539,7 +539,7 @@ class XmlBindingTraitParserGenerator( *codegenScope, "Map" to symbolProvider.toSymbol(target), ) { - rust("let mut out = #T::new();", software.amazon.smithy.rust.codegen.core.rustlang.RustType.HashMap.RuntimeType) + rust("let mut out = #T::new();", RuntimeType.HashMap) parseLoop(Ctx(tag = "decoder", accum = null)) { ctx -> rustBlock("s if ${XmlName("entry").matchExpression("s")} => ") { rust("#T(&mut ${ctx.tag}, &mut out)?;", mapEntryParser(target, ctx)) @@ -638,8 +638,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) } @@ -649,7 +649,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 a8793919ea2e87850393710dc239525289c6ec62..e6e234be7ec051ccb7535ae13aba314d82482a6c 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,12 +8,10 @@ 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 @@ -45,20 +43,21 @@ 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 = RuntimeType.smithyEventStream(runtimeConfig) + private val operationErrorSymbol = if (target == CodegenTarget.SERVER && unionShape.eventStreamErrors().isEmpty()) { - RuntimeType("MessageStreamError", smithyEventStream, "aws_smithy_http::event_stream").toSymbol() + RuntimeType.smithyHttp(runtimeConfig).resolve("event_stream::MessageStreamError").toSymbol() } else { unionShape.eventStreamErrorSymbol(model, symbolProvider, target).toSymbol() } 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 smithyEventStream.resolve("frame::MarshallMessage"), + "Message" to smithyEventStream.resolve("frame::Message"), + "Header" to smithyEventStream.resolve("frame::Header"), + "HeaderValue" to smithyEventStream.resolve("frame::HeaderValue"), + "Error" to smithyEventStream.resolve("error::Error"), ) override fun render(): RuntimeType { @@ -160,11 +159,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 3db50608144b20266ac38be0613ead22a13df201..cb6833aaf756665f731f649c451a8189540562de 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 @@ -53,14 +52,14 @@ open class EventStreamMarshallerGenerator( private val serializerGenerator: StructuredDataSerializerGenerator, private val payloadContentType: String, ) { - private val smithyEventStream = CargoDependency.smithyEventStream(runtimeConfig) + private val smithyEventStream = RuntimeType.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 smithyEventStream.resolve("frame::MarshallMessage"), + "Message" to smithyEventStream.resolve("frame::Message"), + "Header" to smithyEventStream.resolve("frame::Header"), + "HeaderValue" to smithyEventStream.resolve("frame::HeaderValue"), + "Error" to smithyEventStream.resolve("error::Error"), ) open fun render(): RuntimeType { @@ -250,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 1ef02d9dc1471cb33fcbf00be685617ba7f73f1b..69deb870d70c44f34bebe94f5d86acdafe0d1c77 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 @@ -26,7 +26,6 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape 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.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -169,14 +168,12 @@ class JsonSerializerGenerator( private val symbolProvider = codegenContext.symbolProvider private val codegenTarget = codegenContext.target private val runtimeConfig = codegenContext.runtimeConfig - private val smithyTypes = CargoDependency.smithyTypes(runtimeConfig).toType() - private val smithyJson = CargoDependency.smithyJson(runtimeConfig).toType() 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"), + "JsonObjectWriter" to RuntimeType.smithyJson(runtimeConfig).resolve("serialize::JsonObjectWriter"), + "JsonValueWriter" to RuntimeType.smithyJson(runtimeConfig).resolve("serialize::JsonValueWriter"), "ByteSlab" to RuntimeType.ByteSlab, ) private val serializerUtil = SerializerUtil(model) @@ -282,7 +279,7 @@ class JsonSerializerGenerator( out.into_bytes() } """, - "Document" to RuntimeType.Document(runtimeConfig), *codegenScope, + "Document" to RuntimeType.document(runtimeConfig), *codegenScope, ) } } @@ -397,19 +394,19 @@ class JsonSerializerGenerator( } rust( "$writer.number(##[allow(clippy::useless_conversion)]#T::$numberType((${value.asValue()}).into()));", - smithyTypes.member("Number"), + RuntimeType.smithyTypes(runtimeConfig).resolve("Number"), ) } 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 40dbe5f891f9b599310b349dab1b28edd98e848e..2e141b2ce8ad007bc844f2522461d101884327a8 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,7 +21,6 @@ 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 @@ -93,15 +92,15 @@ 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).toType() - private val smithyQuery = CargoDependency.smithyQuery(runtimeConfig).toType() + private val smithyTypes = RuntimeType.smithyTypes(runtimeConfig) + private val smithyQuery = RuntimeType.smithyQuery(runtimeConfig) 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"), + "QueryWriter" to smithyQuery.resolve("QueryWriter"), + "QueryValueWriter" to smithyQuery.resolve("QueryValueWriter"), ) private val operationSerModule = RustModule.private("operation_ser") private val querySerModule = RustModule.private("query_ser") @@ -231,16 +230,16 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct } rust( "$writer.number(##[allow(clippy::useless_conversion)]#T::$numberType((${value.asValue()}).into()));", - smithyTypes.member("Number"), + smithyTypes.resolve("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 fb595f80322ac26c5f90f6eac2c7b12b64a85f26..3d69218e253a601aaa5ed2f092a9536dac3f5a98 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,7 +23,6 @@ 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 @@ -62,12 +61,11 @@ class XmlBindingTraitSerializerGenerator( private val symbolProvider = codegenContext.symbolProvider private val runtimeConfig = codegenContext.runtimeConfig private val model = codegenContext.model - private val smithyXml = CargoDependency.smithyXml(runtimeConfig).toType() private val codegenTarget = codegenContext.target private val codegenScope = arrayOf( - "XmlWriter" to smithyXml.member("encode::XmlWriter"), - "ElementWriter" to smithyXml.member("encode::ElWriter"), + "XmlWriter" to RuntimeType.smithyXml(runtimeConfig).resolve("encode::XmlWriter"), + "ElementWriter" to RuntimeType.smithyXml(runtimeConfig).resolve("encode::ElWriter"), "SdkBody" to RuntimeType.sdkBody(runtimeConfig), "Error" to runtimeConfig.serializationError(), ) @@ -303,10 +301,10 @@ class XmlBindingTraitSerializerGenerator( is BooleanShape, is NumberShape -> { rust( "#T::from(${autoDeref(input)}).encode()", - CargoDependency.smithyTypes(runtimeConfig).toType().member("primitive::Encoder"), + RuntimeType.smithyTypes(runtimeConfig).resolve("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( @@ -314,7 +312,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/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 3fff4b78044db4c94c233df3c8226a9e6da63a41..40f0014327ae5174a18daa4b09aa496bbb9b4861 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 @@ -12,8 +12,6 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape 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.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.smithy.BaseSymbolMetadataProvider @@ -114,11 +112,4 @@ fun StructureShape.renderWithModelBuilder( } } -val TokioWithTestMacros = CargoDependency( - "tokio", - CratesIo("1"), - features = setOf("macros", "test-util", "rt", "rt-multi-thread"), - scope = DependencyScope.Dev, -) - -val TokioTest = Attribute.Custom("tokio::test", listOf(TokioWithTestMacros.toType())) +val TokioTest = Attribute.Custom("tokio::test", listOf(CargoDependency.Tokio.toType())) 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 87004473c4d1ad096caf711d44ee19b4d5ae2bf1..a8eb41353f53739e258a031f564f76b74e9e04d7 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 b3a8e6529c8189cd63057b43a2c40c9022d6a533..a78ccecd6f797ae3095d983825c5ba6a7d4bd808 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 @@ -155,7 +155,7 @@ class RustWriterTest { sut.rustTemplate( "inner: #{Inner:W}, regular: #{http}", "Inner" to inner, - "http" to CargoDependency.Http.toType().member("foo"), + "http" to RuntimeType.Http.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 67419a572848dc37f2e2784fa7543ebf253511fd..7da056245152045ca78241eb36bb5c2e6b435f7b 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,13 +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) + val runtimeType = RuntimeType.String forInputExpectOutput(runtimeType, "''") } @@ -50,9 +50,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-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 09574054544060de66ba5d9f488e858910d61cbe..7e5fd040ff50cb3f0b079818d99db8f69e956d4e 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 @@ -11,7 +11,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig /** * Object used *exclusively* in the runtime of the Python server, for separation concerns. - * Analogous to the companion object in [CargoDependency] and [ServerCargoDependency]; see its documentation for details. + * Analogous to the companion object in [CargoDependency] and [software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency]; see its documentation for details. * For a dependency that is used in the client, or in both the client and the server, use [CargoDependency] directly. */ object PythonServerCargoDependency { @@ -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 0452dacdf1883f617e4390f02bbfa5b8abafe83b..1faa2661fa287786aecc25b34cdc088ef7454fa5 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 @@ -10,23 +10,16 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType /** * Object used *exclusively* in the runtime of the Python server, for separation concerns. - * Analogous to the companion object in [RuntimeType] and [ServerRuntimeType]; see its documentation for details. + * Analogous to the companion object in [RuntimeType] and [software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType]; see its documentation for details. * For a runtime type that is used in the client, or in both the client and the server, use [RuntimeType] directly. */ object PythonServerRuntimeType { + fun blob(runtimeConfig: RuntimeConfig) = + PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig).toType().resolve("types::Blob") - fun PySocket(runtimeConfig: RuntimeConfig) = - RuntimeType("PySocket", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server_python") + fun byteStream(runtimeConfig: RuntimeConfig) = + PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig).toType().resolve("types::ByteStream") - fun Blob(runtimeConfig: RuntimeConfig) = - RuntimeType("Blob", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server_python::types") - - fun ByteStream(runtimeConfig: RuntimeConfig) = - RuntimeType("ByteStream", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server_python::types") - - fun DateTime(runtimeConfig: RuntimeConfig) = - RuntimeType("DateTime", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server_python::types") - - fun PyError(runtimeConfig: RuntimeConfig) = - RuntimeType("Error", PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server_python") + fun dateTime(runtimeConfig: RuntimeConfig) = + PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig).toType().resolve("types::DateTime") } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt index 1e6f2b7ea83f25bbd4d044a7424a7f4b1aafb396..1247d1e064c93f62743de79681ae62c01f95c72f 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt @@ -64,18 +64,18 @@ class PythonServerSymbolVisitor( // For example a TimestampShape doesn't become a different symbol when streaming is involved, but BlobShape // become a ByteStream. return if (target is BlobShape && shape.isStreaming(model)) { - PythonServerRuntimeType.ByteStream(config().runtimeConfig).toSymbol() + PythonServerRuntimeType.byteStream(config().runtimeConfig).toSymbol() } else { initial } } override fun timestampShape(shape: TimestampShape?): Symbol { - return PythonServerRuntimeType.DateTime(runtimeConfig).toSymbol() + return PythonServerRuntimeType.dateTime(runtimeConfig).toSymbol() } override fun blobShape(shape: BlobShape?): Symbol { - return PythonServerRuntimeType.Blob(runtimeConfig).toSymbol() + return PythonServerRuntimeType.blob(runtimeConfig).toSymbol() } } 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 150896eb546a71597307703301c1d304c7fd5d48..58713a1d05dacd1120fef6a2256ca98e20e71421 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 @@ -60,8 +60,8 @@ class PubUsePythonTypes(private val codegenContext: ServerCodegenContext) : LibR is LibRsSection.Body -> writable { docs("Re-exported Python types from supporting crates.") rustBlock("pub mod python_types") { - rust("pub use #T;", PythonServerRuntimeType.Blob(codegenContext.runtimeConfig).toSymbol()) - rust("pub use #T;", PythonServerRuntimeType.DateTime(codegenContext.runtimeConfig).toSymbol()) + rust("pub use #T;", PythonServerRuntimeType.blob(codegenContext.runtimeConfig).toSymbol()) + rust("pub use #T;", PythonServerRuntimeType.dateTime(codegenContext.runtimeConfig).toSymbol()) } } else -> emptySection 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 7d5635b72ffdd4eb6d787a0ef1816da4256696cf..d7547f1d173d5b2f46c84693a842a085de039789 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,7 +7,6 @@ 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.RustType 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.rustBlockTemplate @@ -75,8 +74,8 @@ class PythonApplicationGenerator( private val model = codegenContext.model private val codegenScope = arrayOf( - "SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig).toType(), - "SmithyServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).toType(), + "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(), @@ -85,9 +84,9 @@ class PythonApplicationGenerator( "tower_http" to PythonServerCargoDependency.TowerHttp.toType(), "num_cpus" to PythonServerCargoDependency.NumCpus.toType(), "hyper" to PythonServerCargoDependency.Hyper.toType(), - "HashMap" to RustType.HashMap.RuntimeType, + "HashMap" to RuntimeType.HashMap, "parking_lot" to PythonServerCargoDependency.ParkingLot.toType(), - "http" to RuntimeType.http, + "http" to RuntimeType.Http, ) 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 a8620e63127ae2c1b1ffadd26f19764dd3649094..45d2bcec498dd8d4bd30b4d0fc13be0f4ba69ecb 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,7 +25,7 @@ class PythonServerModuleGenerator( private val serviceShapes: Set, ) { private val codegenScope = arrayOf( - "SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(codegenContext.runtimeConfig).toType(), + "SmithyPython" to PythonServerCargoDependency.smithyHttpServerPython(codegenContext.runtimeConfig).toType(), "pyo3" to PythonServerCargoDependency.PyO3.toType(), ) 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 e7b1aaddb5a31921ba380a022084b2e982ec2d89..a523ae3d6eb720f7a7c998de69656afef3bd0c9c 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 @@ -13,7 +13,6 @@ 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.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency -import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerOperationHandlerGenerator import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol @@ -25,7 +24,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.Ser * Rust application), which are built into a `Router` by [PythonApplicationGenerator]. * * To call a Python function from Rust, anything dealing with Python runs inside an async - * block that allows to catch stacktraces. The handler function is extracted from `PyHandler` + * block that allows to catch stack traces. The handler function is extracted from `PyHandler` * and called with the necessary arguments inside a blocking Tokio task. * At the end the block is awaited and errors are collected and reported. * @@ -40,8 +39,8 @@ class PythonServerOperationHandlerGenerator( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( - "SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig).toType(), - "SmithyServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).toType(), + "SmithyPython" to PythonServerCargoDependency.smithyHttpServerPython(runtimeConfig).toType(), + "SmithyServer" to PythonServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), "pyo3" to PythonServerCargoDependency.PyO3.toType(), "pyo3_asyncio" to PythonServerCargoDependency.PyO3Asyncio.toType(), "tokio" to PythonServerCargoDependency.Tokio.toType(), 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 651ff1b56c25abc8be217645a501427bf054b260..5bfb0f98f2b9e159c26c16e875c2aa101e9caf0c 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 @@ -28,26 +28,26 @@ object ServerCargoDependency { val TokioDev: CargoDependency = CargoDependency("tokio", CratesIo("1.8.4"), scope = DependencyScope.Dev) val Regex: CargoDependency = CargoDependency("regex", CratesIo("1.5.5")) - fun SmithyHttpServer(runtimeConfig: RuntimeConfig) = runtimeConfig.runtimeCrate("http-server") + fun smithyHttpServer(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http-server") } /** * A dependency on a snippet of code * * ServerInlineDependency 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] * * ServerInlineDependencies 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. */ object ServerInlineDependency { fun serverOperationHandler(runtimeConfig: RuntimeConfig): InlineDependency = InlineDependency.forRustFile( RustModule.private("server_operation_handler_trait"), "/inlineable/src/server_operation_handler_trait.rs", - 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 d1d74d80bfedf930269ba90e7e2c4759a1dea765..a0a1baa23d995ae5b0431edb560672f6bbb803b8 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 @@ -15,29 +15,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") + fun forInlineDependency(inlineDependency: InlineDependency) = RuntimeType("crate::${inlineDependency.name}", inlineDependency) - val Phantom = RuntimeType("PhantomData", dependency = null, namespace = "std::marker") - val Cow = RuntimeType("Cow", dependency = null, namespace = "std::borrow") + fun router(runtimeConfig: RuntimeConfig) = ServerCargoDependency.smithyHttpServer(runtimeConfig).toType().resolve("routing::Router") - fun Router(runtimeConfig: RuntimeConfig) = - RuntimeType("Router", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::routing") - - fun OperationHandler(runtimeConfig: RuntimeConfig) = + fun operationHandler(runtimeConfig: RuntimeConfig) = forInlineDependency(ServerInlineDependency.serverOperationHandler(runtimeConfig)) - fun RuntimeError(runtimeConfig: RuntimeConfig) = - RuntimeType("RuntimeError", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::runtime_error") + fun runtimeError(runtimeConfig: RuntimeConfig) = ServerCargoDependency.smithyHttpServer(runtimeConfig).toType().resolve("runtime_error::RuntimeError") - fun RequestRejection(runtimeConfig: RuntimeConfig) = - RuntimeType("RequestRejection", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::rejection") + fun requestRejection(runtimeConfig: RuntimeConfig) = ServerCargoDependency.smithyHttpServer(runtimeConfig).toType().resolve("rejection::RequestRejection") - fun ResponseRejection(runtimeConfig: RuntimeConfig) = - RuntimeType("ResponseRejection", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::rejection") + fun responseRejection(runtimeConfig: RuntimeConfig) = ServerCargoDependency.smithyHttpServer(runtimeConfig).toType().resolve("rejection::ResponseRejection") - fun Protocol(name: String, path: String, runtimeConfig: RuntimeConfig) = - RuntimeType(name, ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::proto::" + path) + fun protocol(name: String, path: String, runtimeConfig: RuntimeConfig) = ServerCargoDependency.smithyHttpServer(runtimeConfig).toType().resolve("proto::$path::$name") - fun Protocol(runtimeConfig: RuntimeConfig) = Protocol("Protocol", "", runtimeConfig) + fun protocol(runtimeConfig: RuntimeConfig) = protocol("Protocol", "", runtimeConfig) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedCollectionGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedCollectionGenerator.kt index 857b6aa829e35dec54058f70f4f781a836833ec7..51842ceda532690af8946aa77557de54bc54d8b4 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedCollectionGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedCollectionGenerator.kt @@ -157,7 +157,7 @@ class ConstrainedCollectionGenerator( type Unconstrained = #{UnconstrainedSymbol}; } """, - "ConstrainedTrait" to RuntimeType.ConstrainedTrait(), + "ConstrainedTrait" to RuntimeType.ConstrainedTrait, "UnconstrainedSymbol" to unconstrainedSymbol, ) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedMapGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedMapGenerator.kt index 69cfafc698f0ef0edef2f8e120333e88e2c46159..0066004045415ad618d32e1988805c0ec08eb4ac 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedMapGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedMapGenerator.kt @@ -140,7 +140,7 @@ class ConstrainedMapGenerator( type Unconstrained = #{UnconstrainedSymbol}; } """, - "ConstrainedTrait" to RuntimeType.ConstrainedTrait(), + "ConstrainedTrait" to RuntimeType.ConstrainedTrait, "UnconstrainedSymbol" to unconstrainedSymbol, ) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedNumberGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedNumberGenerator.kt index e393083ec0459ea71f1efcba4f55760fdfa891a8..45d368a6a87d3758c59cc58f366fc697972a6f64 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedNumberGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedNumberGenerator.kt @@ -137,7 +137,7 @@ class ConstrainedNumberGenerator( } } """, - "ConstrainedTrait" to RuntimeType.ConstrainedTrait(), + "ConstrainedTrait" to RuntimeType.ConstrainedTrait, "ConstraintViolation" to constraintViolation, "MaybeConstrained" to symbol.makeMaybeConstrained(), "Display" to RuntimeType.Display, diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedStringGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedStringGenerator.kt index 6bf017b61f893d196bd1e04a5b8630714392fb6c..18a041ecccc106c214eaf30e8222e13e3a39c7f8 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedStringGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedStringGenerator.kt @@ -134,7 +134,7 @@ class ConstrainedStringGenerator( } } """, - "ConstrainedTrait" to RuntimeType.ConstrainedTrait(), + "ConstrainedTrait" to RuntimeType.ConstrainedTrait, "ConstraintViolation" to constraintViolation, "MaybeConstrained" to symbol.makeMaybeConstrained(), "Display" to RuntimeType.Display, diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedTraitForEnumGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedTraitForEnumGenerator.kt index 288065d75cb33ff1256a7cfaf48a301b532567af..44992f4a48aa9a675f8cd73c56d977601278c522 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedTraitForEnumGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedTraitForEnumGenerator.kt @@ -37,14 +37,14 @@ class ConstrainedTraitForEnumGenerator( impl #{ConstrainedTrait} for $name { type Unconstrained = $unconstrainedType; } - + impl From<$unconstrainedType> for #{MaybeConstrained} { fn from(value: $unconstrainedType) -> Self { Self::Unconstrained(value) } } """, - "ConstrainedTrait" to RuntimeType.ConstrainedTrait(), + "ConstrainedTrait" to RuntimeType.ConstrainedTrait, "MaybeConstrained" to symbol.makeMaybeConstrained(), ) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/PubCrateConstrainedCollectionGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/PubCrateConstrainedCollectionGenerator.kt index 66380dd6383952d1af203f6b100352f0ac22db06..a85b4c610730255f96fb44a557a4016d386a35ee 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/PubCrateConstrainedCollectionGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/PubCrateConstrainedCollectionGenerator.kt @@ -62,7 +62,7 @@ class PubCrateConstrainedCollectionGenerator( val codegenScope = arrayOf( "InnerConstrainedSymbol" to innerConstrainedSymbol, - "ConstrainedTrait" to RuntimeType.ConstrainedTrait(), + "ConstrainedTrait" to RuntimeType.ConstrainedTrait, "UnconstrainedSymbol" to unconstrainedSymbol, "Symbol" to symbol, "From" to RuntimeType.From, diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/PubCrateConstrainedMapGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/PubCrateConstrainedMapGenerator.kt index d11bcad6b8d4f0b3fab08587c5dd5a6d70e49194..abbce1d59e3793a6a39de669935f98cd5dd8c0ec 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/PubCrateConstrainedMapGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/PubCrateConstrainedMapGenerator.kt @@ -63,7 +63,7 @@ class PubCrateConstrainedMapGenerator( val codegenScope = arrayOf( "KeySymbol" to keySymbol, "ValueSymbol" to valueSymbol, - "ConstrainedTrait" to RuntimeType.ConstrainedTrait(), + "ConstrainedTrait" to RuntimeType.ConstrainedTrait, "UnconstrainedSymbol" to unconstrainedSymbol, "Symbol" to symbol, "From" to RuntimeType.From, diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerBuilderGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerBuilderGenerator.kt index e49a046e64726796d8fd87b576ad8857b3b85ad5..facb2c5b0a8402da09628ab35c50763da7c1c29e 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerBuilderGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerBuilderGenerator.kt @@ -126,11 +126,11 @@ class ServerBuilderGenerator( ServerBuilderConstraintViolations(codegenContext, shape, takeInUnconstrainedTypes) private val codegenScope = arrayOf( - "RequestRejection" to ServerRuntimeType.RequestRejection(runtimeConfig), + "RequestRejection" to ServerRuntimeType.requestRejection(runtimeConfig), "Structure" to structureSymbol, "From" to RuntimeType.From, "TryFrom" to RuntimeType.TryFrom, - "MaybeConstrained" to RuntimeType.MaybeConstrained(), + "MaybeConstrained" to RuntimeType.MaybeConstrained, ) fun render(writer: RustWriter) { @@ -425,7 +425,7 @@ class ServerBuilderGenerator( private fun renderImplDebugForBuilder(writer: RustWriter) { writer.rustBlock("impl #T for Builder", RuntimeType.Debug) { - writer.rustBlock("fn fmt(&self, f: &mut #1T::Formatter<'_>) -> #1T::Result", RuntimeType.stdfmt) { + writer.rustBlock("fn fmt(&self, f: &mut #1T::Formatter<'_>) -> #1T::Result", RuntimeType.stdFmt) { rust("""let mut formatter = f.debug_struct("Builder");""") members.forEach { member -> val memberName = symbolProvider.toMemberName(member) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerBuilderGeneratorWithoutPublicConstrainedTypes.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerBuilderGeneratorWithoutPublicConstrainedTypes.kt index e342d5c8cfdd37295584f828da342db0fcb2320b..d83446dc833844d3b3e2a78d7a4751221750110f 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerBuilderGeneratorWithoutPublicConstrainedTypes.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerBuilderGeneratorWithoutPublicConstrainedTypes.kt @@ -74,11 +74,11 @@ class ServerBuilderGeneratorWithoutPublicConstrainedTypes( ServerBuilderConstraintViolations(codegenContext, shape, builderTakesInUnconstrainedTypes = false) private val codegenScope = arrayOf( - "RequestRejection" to ServerRuntimeType.RequestRejection(codegenContext.runtimeConfig), + "RequestRejection" to ServerRuntimeType.requestRejection(codegenContext.runtimeConfig), "Structure" to structureSymbol, "From" to RuntimeType.From, "TryFrom" to RuntimeType.TryFrom, - "MaybeConstrained" to RuntimeType.MaybeConstrained(), + "MaybeConstrained" to RuntimeType.MaybeConstrained, ) fun render(writer: RustWriter) { 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 f2b6ddef817b219f04106da7f12672774d5e0b55..47b42825fa0fe49b30e3f7218bac836e863e6698 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).toType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), ) /** 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).toType()) + arrayOf("SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType()) /** 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).toType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), "Http" to CargoDependency.Http.toType(), ) @@ -219,7 +219,7 @@ sealed class QuerySensitivity( runtimeConfig: RuntimeConfig, ) { private val codegenScope = - arrayOf("SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).toType()) + arrayOf("SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType()) /** 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).toType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), "Http" to CargoDependency.Http.toType(), ) 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 2636440399529bf0002508f4913f1b4f589942ab..9d757310dd0f40afd2a525155c2b2ce847e10a12 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).toType(), + 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 fb8501fd10c58ef9224233d654501d2e1c16cc96..f86a2f2289b94577a90825aed59cbe90f625d365 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.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate @@ -39,11 +38,11 @@ open class ServerOperationHandlerGenerator( "AsyncTrait" to ServerCargoDependency.AsyncTrait.toType(), "Tower" to ServerCargoDependency.Tower.toType(), "FuturesUtil" to ServerCargoDependency.FuturesUtil.toType(), - "SmithyHttp" to CargoDependency.smithyHttp(runtimeConfig).toType(), - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).toType(), - "Phantom" to ServerRuntimeType.Phantom, - "ServerOperationHandler" to ServerRuntimeType.OperationHandler(runtimeConfig), - "http" to RuntimeType.http, + "SmithyHttp" to RuntimeType.smithyHttp(runtimeConfig), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), + "Phantom" to RuntimeType.Phantom, + "ServerOperationHandler" to ServerRuntimeType.operationHandler(runtimeConfig), + "http" to RuntimeType.Http, ) 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 1c2b459f536bddff4cb97d69341b2d65d55b2d6e..494d137e7dabec190e2c74783a60fc025244fda8 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 @@ -58,11 +58,11 @@ class ServerOperationRegistryGenerator( private val operationNames = operations.map { RustReservedWords.escapeIfNeeded(symbolProvider.toSymbol(it).name.toSnakeCase()) } private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( - "Router" to ServerRuntimeType.Router(runtimeConfig), - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).toType(), - "ServerOperationHandler" to ServerRuntimeType.OperationHandler(runtimeConfig), + "Router" to ServerRuntimeType.router(runtimeConfig), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), + "ServerOperationHandler" to ServerRuntimeType.operationHandler(runtimeConfig), "Tower" to ServerCargoDependency.Tower.toType(), - "Phantom" to ServerRuntimeType.Phantom, + "Phantom" to RuntimeType.Phantom, "StdError" to RuntimeType.StdError, "Display" to RuntimeType.Display, "From" to RuntimeType.From, @@ -155,7 +155,7 @@ ${operationImplementationStubs(operations)} /// [operations]: https://awslabs.github.io/smithy/1.0/spec/core/model.html##operation /// [Hyper server]: https://docs.rs/hyper/latest/hyper/server/index.html """, - "Router" to ServerRuntimeType.Router(runtimeConfig), + "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.toType(), @@ -402,6 +402,6 @@ ${operationImplementationStubs(operations)} this, symbolProvider.toSymbol(this).name, serviceName, - ServerCargoDependency.SmithyHttpServer(runtimeConfig).toType().member("routing::request_spec"), + ServerCargoDependency.smithyHttpServer(runtimeConfig).toType().resolve("routing::request_spec"), ) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationShapeGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationShapeGenerator.kt index 7e201c33678b3e8f9d100d60110e07e995332fe3..0804c60999ebf4200402984cf07e05da14baec96 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationShapeGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationShapeGenerator.kt @@ -7,7 +7,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.rust 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.util.toPascalCase @@ -61,7 +60,7 @@ class ServerOperationShapeGenerator( //! operation specific information to the [`Layer`](#{Tower}::Layer) being applied. """.trimIndent(), "SmithyHttpServer" to - ServerCargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).toType(), + ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).toType(), "Tower" to ServerCargoDependency.Tower.toType(), "Handler" to DocHandlerGenerator(codegenContext, operations[0], "handler", "//!")::render, ) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt index 0e720d00f1fde941bc683899169bb674ac0fcc0a..a42a1379a2d3c34ec7cbf67ab88ace9a952a01b3 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt @@ -225,7 +225,7 @@ open class ServerServiceGenerator( """, "Handlers" to handlers, "ExampleHandler" to operations.take(1).map { operation -> DocHandlerGenerator(codegenContext, operation, builderFieldNames[operation]!!, "//!").docSignature() }, - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).toType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).toType(), "Tower" to ServerCargoDependency.Tower.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 824761cf254b575f33eab7394417adffba3b0cb8..a196a36e6c68c63b4253fe560107fc15c7b7f7a2 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 @@ -7,7 +7,6 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.knowledge.TopDownIndex import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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 @@ -17,6 +16,7 @@ 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.util.toPascalCase import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency @@ -27,15 +27,15 @@ class ServerServiceGeneratorV2( private val protocol: ServerProtocol, ) { private val runtimeConfig = codegenContext.runtimeConfig - private val smithyHttpServer = ServerCargoDependency.SmithyHttpServer(runtimeConfig).toType() + private val smithyHttpServer = ServerCargoDependency.smithyHttpServer(runtimeConfig).toType() private val codegenScope = arrayOf( - "Bytes" to CargoDependency.Bytes.toType(), - "Http" to CargoDependency.Http.toType(), - "SmithyHttp" to CargoDependency.smithyHttp(runtimeConfig).toType(), - "HttpBody" to CargoDependency.HttpBody.toType(), + "Bytes" to RuntimeType.Bytes, + "Http" to RuntimeType.Http, + "SmithyHttp" to RuntimeType.smithyHttp(runtimeConfig), + "HttpBody" to RuntimeType.HttpBody, "SmithyHttpServer" to smithyHttpServer, - "Tower" to CargoDependency.Tower.toType(), + "Tower" to RuntimeType.Tower, ) private val model = codegenContext.model private val symbolProvider = codegenContext.symbolProvider @@ -76,7 +76,7 @@ class ServerServiceGeneratorV2( operationShape, operationName, serviceName, - smithyHttpServer.member("routing::request_spec"), + smithyHttpServer.resolve("routing::request_spec"), ) val functionName = RustReservedWords.escapeIfNeeded(operationName.toSnakeCase()) val functionBody = writable { @@ -87,7 +87,7 @@ class ServerServiceGeneratorV2( } """, "Spec" to spec, - "SpecType" to protocol.serverRouterRequestSpecType(smithyHttpServer.member("routing::request_spec")), + "SpecType" to protocol.serverRouterRequestSpecType(smithyHttpServer.resolve("routing::request_spec")), ) } Pair(functionName, functionBody) @@ -414,7 +414,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/ServerStructureConstrainedTraitImpl.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerStructureConstrainedTraitImpl.kt index 2812c59d7455b8684eda6e923abc3557c8a832c8..b28f8786a134cff6c21b1e5b94fa0bd0ca89b3d9 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerStructureConstrainedTraitImpl.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerStructureConstrainedTraitImpl.kt @@ -24,7 +24,7 @@ class ServerStructureConstrainedTraitImpl( type Unconstrained = #{Builder}; } """, - "ConstrainedTrait" to RuntimeType.ConstrainedTrait(), + "ConstrainedTrait" to RuntimeType.ConstrainedTrait, "Structure" to symbolProvider.toSymbol(shape), "Builder" to shape.serverBuilderSymbol(symbolProvider, !publicConstrainedTypes), ) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/UnconstrainedUnionGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/UnconstrainedUnionGenerator.kt index 022fc92650ba98a41a6ab31f1b530dbc5c4f32d2..af97976aebdec9c35ae1805a917ee073d8a1338a 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/UnconstrainedUnionGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/UnconstrainedUnionGenerator.kt @@ -120,7 +120,7 @@ class UnconstrainedUnionGenerator( } } """, - "ConstrainedTrait" to RuntimeType.ConstrainedTrait(), + "ConstrainedTrait" to RuntimeType.ConstrainedTrait, "MaybeConstrained" to constrainedSymbol.makeMaybeConstrained(), "ConstrainedSymbol" to constrainedSymbol, "UnconstrainedSymbol" to symbol, 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 1ed50883d0bd925663c768649be306098a38f213..09eb45a5e64e713c09b6559fb909411efcfffb23 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 @@ -113,15 +113,16 @@ class ServerAwsJsonProtocol( override fun markerStruct(): RuntimeType { return when (version) { is AwsJsonVersion.Json10 -> { - ServerRuntimeType.Protocol("AwsJson1_0", "aws_json_10", runtimeConfig) + ServerRuntimeType.protocol("AwsJson1_0", "aws_json_10", runtimeConfig) } is AwsJsonVersion.Json11 -> { - ServerRuntimeType.Protocol("AwsJson1_1", "aws_json_11", runtimeConfig) + ServerRuntimeType.protocol("AwsJson1_1", "aws_json_11", runtimeConfig) } } } - override fun routerType() = RuntimeType("AwsJsonRouter", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::proto::aws_json::router") + override fun routerType() = ServerCargoDependency.smithyHttpServer(runtimeConfig).toType() + .resolve("proto::aws_json::router::AwsJsonRouter") /** * Returns the operation name as required by the awsJson1.x protocols. @@ -137,8 +138,7 @@ class ServerAwsJsonProtocol( override fun serverRouterRequestSpecType( requestSpecModule: RuntimeType, - ): RuntimeType = - RuntimeType("String", null, "std::string") + ): RuntimeType = RuntimeType.String override fun serverRouterRuntimeConstructor() = when (version) { AwsJsonVersion.Json10 -> "new_aws_json_10_router" @@ -146,7 +146,9 @@ class ServerAwsJsonProtocol( } } -private fun restRouterType(runtimeConfig: RuntimeConfig) = RuntimeType("RestRouter", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::proto::rest::router") +private fun restRouterType(runtimeConfig: RuntimeConfig) = + ServerCargoDependency.smithyHttpServer(runtimeConfig).toType() + .resolve("proto::rest::router::RestRouter") class ServerRestJsonProtocol( private val serverCodegenContext: ServerCodegenContext, @@ -179,7 +181,7 @@ class ServerRestJsonProtocol( override fun structuredDataSerializer(operationShape: OperationShape): StructuredDataSerializerGenerator = ServerRestJsonSerializerGenerator(serverCodegenContext, httpBindingResolver) - override fun markerStruct() = ServerRuntimeType.Protocol("RestJson1", "rest_json_1", runtimeConfig) + override fun markerStruct() = ServerRuntimeType.protocol("RestJson1", "rest_json_1", runtimeConfig) override fun routerType() = restRouterType(runtimeConfig) @@ -191,7 +193,7 @@ class ServerRestJsonProtocol( ): Writable = RestRequestSpecGenerator(httpBindingResolver, requestSpecModule).generate(operationShape) override fun serverRouterRequestSpecType(requestSpecModule: RuntimeType): RuntimeType = - requestSpecModule.member("RequestSpec") + requestSpecModule.resolve("RequestSpec") override fun serverRouterRuntimeConstructor() = "new_rest_json_router" @@ -203,7 +205,7 @@ class ServerRestXmlProtocol( ) : RestXml(codegenContext), ServerProtocol { val runtimeConfig = codegenContext.runtimeConfig - override fun markerStruct() = ServerRuntimeType.Protocol("RestXml", "rest_xml", runtimeConfig) + override fun markerStruct() = ServerRuntimeType.protocol("RestXml", "rest_xml", runtimeConfig) override fun routerType() = restRouterType(runtimeConfig) @@ -215,7 +217,7 @@ class ServerRestXmlProtocol( ): Writable = RestRequestSpecGenerator(httpBindingResolver, requestSpecModule).generate(operationShape) override fun serverRouterRequestSpecType(requestSpecModule: RuntimeType): RuntimeType = - requestSpecModule.member("RequestSpec") + requestSpecModule.resolve("RequestSpec") override fun serverRouterRuntimeConstructor() = "new_rest_xml_router" 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 e73c3902fb1865b851cd0d5169a3c1fdc4991f74..b68439f53eb056e1dea2a3f1df08a389fb4b7585 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 @@ -25,7 +25,6 @@ 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.RustMetadata import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords @@ -91,7 +90,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>" } @@ -103,14 +102,14 @@ class ServerProtocolTestGenerator( private val codegenScope = arrayOf( "Bytes" to RuntimeType.Bytes, - "SmithyHttp" to CargoDependency.smithyHttp(codegenContext.runtimeConfig).toType(), - "Http" to CargoDependency.Http.toType(), - "Hyper" to CargoDependency.Hyper.toType(), + "SmithyHttp" to RuntimeType.smithyHttp(codegenContext.runtimeConfig), + "Http" to RuntimeType.Http, + "Hyper" to RuntimeType.Hyper, "Tokio" to ServerCargoDependency.TokioDev.toType(), - "Tower" to CargoDependency.Tower.toType(), - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).toType(), - "AssertEq" to CargoDependency.PrettyAssertions.toType().member("assert_eq!"), - "Router" to ServerRuntimeType.Router(codegenContext.runtimeConfig), + "Tower" to RuntimeType.Tower, + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).toType(), + "AssertEq" to RuntimeType.PrettyAssertions.resolve("assert_eq!"), + "Router" to ServerRuntimeType.router(codegenContext.runtimeConfig), ) sealed class TestCase { @@ -699,7 +698,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( @@ -797,8 +796,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"), ) } } @@ -851,7 +850,7 @@ class ServerProtocolTestGenerator( assertOk(rustWriter) { rust( "#T($actualExpression, $variableName)", - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "validate_headers"), + RuntimeType.protocolTest(codegenContext.runtimeConfig, "validate_headers"), ) } } @@ -872,7 +871,7 @@ class ServerProtocolTestGenerator( assertOk(rustWriter) { rustWriter.rust( "#T($actualExpression, $expectedVariableName)", - RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, checkFunction), + RuntimeType.protocolTest(codegenContext.runtimeConfig, checkFunction), ) } } @@ -882,7 +881,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 01f498db1ab99364d323bdd98beb4c3a5703f92a..c466a04797944f33b5c33ae6c0de4c77fa7acee4 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,14 +26,12 @@ import software.amazon.smithy.model.traits.HttpPayloadTrait 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.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.conditionalBlock import software.amazon.smithy.rust.codegen.core.rustlang.escape -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 @@ -129,24 +127,24 @@ private class ServerHttpBoundProtocolTraitImplGenerator( private val codegenScope = arrayOf( "AsyncTrait" to ServerCargoDependency.AsyncTrait.toType(), - "Cow" to ServerRuntimeType.Cow, - "DateTime" to RuntimeType.DateTime(runtimeConfig), + "Cow" to RuntimeType.Cow, + "DateTime" to RuntimeType.dateTime(runtimeConfig), "FormUrlEncoded" to ServerCargoDependency.FormUrlEncoded.toType(), - "HttpBody" to CargoDependency.HttpBody.toType(), - "header_util" to CargoDependency.smithyHttp(runtimeConfig).toType().member("header"), - "Hyper" to CargoDependency.Hyper.toType(), - "LazyStatic" to CargoDependency.LazyStatic.toType(), + "HttpBody" to RuntimeType.HttpBody, + "header_util" to RuntimeType.smithyHttp(runtimeConfig).resolve("header"), + "Hyper" to RuntimeType.Hyper, + "LazyStatic" to RuntimeType.LazyStatic, "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 CargoDependency.smithyHttp(runtimeConfig).toType(), - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).toType(), - "RuntimeError" to ServerRuntimeType.RuntimeError(runtimeConfig), - "RequestRejection" to ServerRuntimeType.RequestRejection(runtimeConfig), - "ResponseRejection" to ServerRuntimeType.ResponseRejection(runtimeConfig), - "http" to RuntimeType.http, + "OnceCell" to RuntimeType.OnceCell, + "PercentEncoding" to RuntimeType.PercentEncoding, + "Regex" to RuntimeType.Regex, + "SmithyHttp" to RuntimeType.smithyHttp(runtimeConfig), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), + "RuntimeError" to ServerRuntimeType.runtimeError(runtimeConfig), + "RequestRejection" to ServerRuntimeType.requestRejection(runtimeConfig), + "ResponseRejection" to ServerRuntimeType.responseRejection(runtimeConfig), + "http" to RuntimeType.Http, ) override fun generateTraitImpls(operationWriter: RustWriter, operationShape: OperationShape, customizations: List) { @@ -983,7 +981,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( val targetSymbol = unconstrainedShapeSymbolProvider.toSymbol(target) withBlock("let mut query_params: #T = ", ";", targetSymbol) { conditionalBlock("#T(", ")", conditional = hasConstrainedTarget, targetSymbol) { - rust("#T::new()", RustType.HashMap.RuntimeType) + rust("#T::new()", RuntimeType.HashMap) } } } @@ -1035,7 +1033,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}; @@ -1050,7 +1048,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( """ let v = <_ as #T>::parse_smithy_primitive(&v)?; """.trimIndent(), - CargoDependency.smithyTypes(runtimeConfig).toType().member("primitive::Parse"), + RuntimeType.smithyTypes(runtimeConfig).resolve("primitive::Parse"), ) } } @@ -1188,7 +1186,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( binding.location, protocol.defaultTimestampFormat, ) - val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) + val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat) if (percentDecoding) { rustTemplate( @@ -1244,14 +1242,14 @@ private class ServerHttpBoundProtocolTraitImplGenerator( check(binding.location == HttpLocation.PAYLOAD) if (model.expectShape(binding.member.target) is StringShape) { - return ServerRuntimeType.RequestRejection(runtimeConfig) + return ServerRuntimeType.requestRejection(runtimeConfig) } return when (codegenContext.protocol) { RestJson1Trait.ID, AwsJson1_0Trait.ID, AwsJson1_1Trait.ID -> { - CargoDependency.smithyJson(runtimeConfig).toType().member("deserialize::error::DeserializeError") + RuntimeType.smithyJson(runtimeConfig).resolve("deserialize::error::DeserializeError") } RestXmlTrait.ID -> { - CargoDependency.smithyXml(runtimeConfig).toType().member("decode").member("XmlDecodeError") + RuntimeType.smithyXml(runtimeConfig).resolve("decode::XmlDecodeError") } 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 d00dcd842ccde263a28b963cd29709639f1f7f21..9a8ae01cabf5097cf808983a206d151b6cc66cf6 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,7 +22,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverTestSymb class ServerHttpSensitivityGeneratorTest { private val codegenScope = arrayOf( - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(TestRuntimeConfig).toType(), + "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(TestRuntimeConfig).toType(), "Http" to CargoDependency.Http.toType(), ) 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 4449caae37fdc4327e08a8f6bb8061d0a0d34e3b..213318b027d8dedfb910f93f1195e56080f8a456 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 @@ -72,8 +72,8 @@ class EventStreamMarshallerGeneratorTest { HeaderValue::String(value.into()) } """, - "validate_body" to protocolTestHelpers.toType().member("validate_body"), - "MediaType" to protocolTestHelpers.toType().member("MediaType"), + "validate_body" to protocolTestHelpers.toType().resolve("validate_body"), + "MediaType" to protocolTestHelpers.toType().resolve("MediaType"), ) unitTest(