From e3f0de42db727d5419948b03c7d5a3773b07e34b Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Fri, 12 Jan 2024 11:11:29 -0800 Subject: [PATCH] Move `Metadata` config bag type into a stable crate (#3325) This issue addresses a semver compatibility problem similar to the one described in #3318, except for the `aws_smithy_http::operation::Metadata` type. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --- CHANGELOG.next.toml | 8 +++- .../customizations/MetadataCustomization.kt | 2 +- .../protocol/ProtocolParserGenerator.kt | 1 - .../protocol/RequestSerializerGenerator.kt | 1 - .../MetadataCustomizationTest.kt | 2 +- .../rust/codegen/core/smithy/RuntimeType.kt | 2 - examples/Cargo.toml | 1 + .../pokemon-service-client-usage/Cargo.toml | 2 + .../custom-header-using-interceptor.rs | 5 +-- .../examples/response-header-interceptor.rs | 5 +-- rust-runtime/aws-smithy-http/src/operation.rs | 43 +++---------------- .../src/client/orchestrator.rs | 35 +++++++++++++++ 12 files changed, 57 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index fc4c4c257..380dcf52e 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -9,4 +9,10 @@ # message = "Fix typos in module documentation for generated crates" # references = ["smithy-rs#920"] # meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"} -# author = "rcoh" \ No newline at end of file +# author = "rcoh" + +[[smithy-rs]] +message = "The `Metadata` storable was moved from aws_smithy_http into aws_smithy_runtime_api. A deprecated type alias was left in place with a note showing where the new location is." +references = ["smithy-rs#3325"] +meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" } +author = "jdisanti" diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/MetadataCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/MetadataCustomization.kt index 513face07..df5a0e6ae 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/MetadataCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/MetadataCustomization.kt @@ -24,7 +24,7 @@ class MetadataCustomization( private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope by lazy { arrayOf( - "Metadata" to RuntimeType.operationModule(runtimeConfig).resolve("Metadata"), + "Metadata" to RuntimeType.smithyRuntimeApiClient(runtimeConfig).resolve("client::orchestrator::Metadata"), ) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolParserGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolParserGenerator.kt index 3b34aaed0..2181607b8 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolParserGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolParserGenerator.kt @@ -56,7 +56,6 @@ class ProtocolParserGenerator( "Headers" to RuntimeType.headers(codegenContext.runtimeConfig), "Response" to RuntimeType.smithyRuntimeApi(codegenContext.runtimeConfig).resolve("http::Response"), "http" to RuntimeType.Http, - "operation" to RuntimeType.operationModule(codegenContext.runtimeConfig), "SdkBody" to RuntimeType.sdkBody(codegenContext.runtimeConfig), ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/RequestSerializerGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/RequestSerializerGenerator.kt index 43cc46e8d..d2c1f8fc2 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/RequestSerializerGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/RequestSerializerGenerator.kt @@ -46,7 +46,6 @@ class RequestSerializerGenerator( "HttpRequest" to runtimeApi.resolve("client::orchestrator::HttpRequest"), "HttpRequestBuilder" to RuntimeType.HttpRequestBuilder, "Input" to interceptorContext.resolve("Input"), - "operation" to RuntimeType.operationModule(codegenContext.runtimeConfig), "SerializeRequest" to runtimeApi.resolve("client::ser_de::SerializeRequest"), "SdkBody" to RuntimeType.sdkBody(codegenContext.runtimeConfig), "HeaderSerializationSettings" to diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/MetadataCustomizationTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/MetadataCustomizationTest.kt index d96c25dca..693fd2f6e 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/MetadataCustomizationTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/MetadataCustomizationTest.kt @@ -27,7 +27,7 @@ class MetadataCustomizationTest { "BoxError" to RuntimeType.boxError(runtimeConfig), "ConfigBag" to RuntimeType.configBag(runtimeConfig), "Intercept" to RuntimeType.intercept(runtimeConfig), - "Metadata" to RuntimeType.operationModule(runtimeConfig).resolve("Metadata"), + "Metadata" to RuntimeType.smithyRuntimeApiClient(runtimeConfig).resolve("client::orchestrator::Metadata"), "capture_request" to RuntimeType.captureRequest(runtimeConfig), "RuntimeComponents" to RuntimeType.smithyRuntimeApiClient(runtimeConfig) 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 bbaaa6bda..f0fc3e833 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 @@ -448,8 +448,6 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null) fun operation(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("operation::Operation") - fun operationModule(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("operation") - fun protocolTest( runtimeConfig: RuntimeConfig, func: String, diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 9d38f8d77..d92869a66 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,5 +1,6 @@ # Without this configuration, the workspace will be read from `rust-runtime`, causing the build to fail. [workspace] +resolver = "2" members = [ "pokemon-service-common", "pokemon-service", diff --git a/examples/pokemon-service-client-usage/Cargo.toml b/examples/pokemon-service-client-usage/Cargo.toml index dc1acaeaf..290c8d80c 100644 --- a/examples/pokemon-service-client-usage/Cargo.toml +++ b/examples/pokemon-service-client-usage/Cargo.toml @@ -24,6 +24,8 @@ aws-smithy-types = { path = "../../rust-runtime/aws-smithy-types/" } # Required for `HyperClientBuilder` in `client-connector` example. aws-smithy-runtime = { path = "../../rust-runtime/aws-smithy-runtime/", features=["test-util"] } +# Required for `Metadata` in `custom-header-using-interceptor` example. +aws-smithy-runtime-api = { path = "../../rust-runtime/aws-smithy-runtime-api/", features=["client"] } hyper = { version = "0.14.25", features = ["client", "full"] } diff --git a/examples/pokemon-service-client-usage/examples/custom-header-using-interceptor.rs b/examples/pokemon-service-client-usage/examples/custom-header-using-interceptor.rs index 997cce306..00878beb5 100644 --- a/examples/pokemon-service-client-usage/examples/custom-header-using-interceptor.rs +++ b/examples/pokemon-service-client-usage/examples/custom-header-using-interceptor.rs @@ -14,6 +14,7 @@ /// use std::{collections::HashMap, time::Duration}; +use aws_smithy_runtime_api::client::orchestrator::Metadata; use pokemon_service_client::config::{ConfigBag, Intercept}; use pokemon_service_client::Client as PokemonClient; use pokemon_service_client::{ @@ -77,9 +78,7 @@ impl Intercept for TtlHeaderInterceptor { cfg: &mut ConfigBag, ) -> Result<(), BoxError> { // Metadata in the ConfigBag has the operation name. - let metadata = cfg - .load::() - .expect("metadata should exist"); + let metadata = cfg.load::().expect("metadata should exist"); let operation_name = metadata.name(); // Get operation specific or default HeaderValue to set for the header key. diff --git a/examples/pokemon-service-client-usage/examples/response-header-interceptor.rs b/examples/pokemon-service-client-usage/examples/response-header-interceptor.rs index a1ec25019..7f1538737 100644 --- a/examples/pokemon-service-client-usage/examples/response-header-interceptor.rs +++ b/examples/pokemon-service-client-usage/examples/response-header-interceptor.rs @@ -2,6 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ +use aws_smithy_runtime_api::client::orchestrator::Metadata; /// This example demonstrates how response headers can be examined before they are deserialized /// into the output type. /// @@ -88,9 +89,7 @@ impl Intercept for ResponseHeaderLoggingInterceptor { cfg: &mut ConfigBag, ) -> Result<(), BoxError> { // `Metadata` in the `ConfigBag` has the operation name in it. - let metadata = cfg - .load::() - .expect("metadata should exist"); + let metadata = cfg.load::().expect("metadata should exist"); let operation_name = metadata.name().to_string(); // Get the server side request ID and set it in the RequestID data type diff --git a/rust-runtime/aws-smithy-http/src/operation.rs b/rust-runtime/aws-smithy-http/src/operation.rs index cba508287..39f42d953 100644 --- a/rust-runtime/aws-smithy-http/src/operation.rs +++ b/rust-runtime/aws-smithy-http/src/operation.rs @@ -3,42 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -//! Types for representing the interaction between a service an a client, referred to as an "operation" in smithy. -//! Clients "send" operations to services, which are composed of 1 or more HTTP requests. - -use aws_smithy_types::config_bag::{Storable, StoreReplace}; -use std::borrow::Cow; +//! Deprecated metadata type. /// Metadata added to the [`ConfigBag`](aws_smithy_types::config_bag::ConfigBag) that identifies the API being called. -#[derive(Clone, Debug)] -pub struct Metadata { - operation: Cow<'static, str>, - service: Cow<'static, str>, -} - -impl Metadata { - /// Returns the operation name. - pub fn name(&self) -> &str { - &self.operation - } - - /// Returns the service name. - pub fn service(&self) -> &str { - &self.service - } - - /// Creates [`Metadata`]. - pub fn new( - operation: impl Into>, - service: impl Into>, - ) -> Self { - Metadata { - operation: operation.into(), - service: service.into(), - } - } -} - -impl Storable for Metadata { - type Storer = StoreReplace; -} +#[deprecated( + since = "0.60.2", + note = "Use aws_smithy_runtime_api::client::orchestrator::Metadata instead." +)] +pub type Metadata = aws_smithy_runtime_api::client::orchestrator::Metadata; diff --git a/rust-runtime/aws-smithy-runtime-api/src/client/orchestrator.rs b/rust-runtime/aws-smithy-runtime-api/src/client/orchestrator.rs index 873b8a1cc..ffad2dbf1 100644 --- a/rust-runtime/aws-smithy-runtime-api/src/client/orchestrator.rs +++ b/rust-runtime/aws-smithy-runtime-api/src/client/orchestrator.rs @@ -23,6 +23,7 @@ use crate::client::interceptors::InterceptorError; use crate::client::result::{ConnectorError, SdkError}; use aws_smithy_types::config_bag::{Storable, StoreReplace}; use bytes::Bytes; +use std::borrow::Cow; use std::error::Error as StdError; use std::fmt; @@ -287,3 +288,37 @@ impl From for OrchestratorError { Self::operation(err) } } + +/// Metadata added to the [`ConfigBag`](aws_smithy_types::config_bag::ConfigBag) that identifies the API being called. +#[derive(Clone, Debug)] +pub struct Metadata { + operation: Cow<'static, str>, + service: Cow<'static, str>, +} + +impl Metadata { + /// Returns the operation name. + pub fn name(&self) -> &str { + &self.operation + } + + /// Returns the service name. + pub fn service(&self) -> &str { + &self.service + } + + /// Creates [`Metadata`]. + pub fn new( + operation: impl Into>, + service: impl Into>, + ) -> Self { + Metadata { + operation: operation.into(), + service: service.into(), + } + } +} + +impl Storable for Metadata { + type Storer = StoreReplace; +} -- GitLab