AWS SDK

AWS SDK

rev. 32b1b3c3761061baed26023be3219639e42d7d12 (ignoring whitespace)

Files changed:

tmp-codegen-diff/aws-sdk/sdk/aws-config/Cargo.toml

@@ -41,41 +106,110 @@
   61     61   
path = "../aws-smithy-http"
   62     62   
version = "0.63.6"
   63     63   
   64     64   
[dependencies.aws-smithy-json]
   65     65   
path = "../aws-smithy-json"
   66     66   
version = "0.62.6"
   67     67   
   68     68   
[dependencies.aws-smithy-runtime]
   69     69   
path = "../aws-smithy-runtime"
   70     70   
features = ["client"]
   71         -
version = "1.10.3"
          71  +
version = "1.10.4"
   72     72   
   73     73   
[dependencies.aws-smithy-runtime-api]
   74     74   
path = "../aws-smithy-runtime-api"
   75     75   
features = ["client"]
   76         -
version = "1.11.6"
          76  +
version = "1.11.7"
          77  +
          78  +
[dependencies.aws-smithy-schema]
          79  +
path = "../aws-smithy-schema"
          80  +
version = "1.0.0"
   77     81   
   78     82   
[dependencies.aws-smithy-types]
   79     83   
path = "../aws-smithy-types"
   80     84   
version = "1.4.7"
   81     85   
   82     86   
[dependencies.aws-types]
   83     87   
path = "../aws-types"
   84     88   
version = "1.4.0"
   85     89   
   86     90   
[dependencies.time]
@@ -136,140 +187,191 @@
  156    160   
version = "1.2.14"
  157    161   
  158    162   
[dev-dependencies.aws-smithy-http-client]
  159    163   
path = "../aws-smithy-http-client"
  160    164   
features = ["default-client", "test-util"]
  161    165   
version = "1.1.12"
  162    166   
  163    167   
[dev-dependencies.aws-smithy-runtime]
  164    168   
path = "../aws-smithy-runtime"
  165    169   
features = ["client", "test-util"]
  166         -
version = "1.10.3"
         170  +
version = "1.10.4"
  167    171   
  168    172   
[dev-dependencies.aws-smithy-runtime-api]
  169    173   
path = "../aws-smithy-runtime-api"
  170    174   
features = ["test-util"]
  171         -
version = "1.11.6"
         175  +
version = "1.11.7"
  172    176   
  173    177   
[dev-dependencies.futures-util]
  174    178   
version = "0.3.29"
  175    179   
default-features = false
  176    180   
  177    181   
[dev-dependencies.tracing-subscriber]
  178    182   
version = "0.3.16"
  179    183   
features = ["fmt", "json"]
  180    184   
  181    185   
[dev-dependencies.tokio]

tmp-codegen-diff/aws-sdk/sdk/aws-config/external-types.toml

@@ -2,2 +39,40 @@
   22     22   
   "aws_smithy_runtime_api::box_error::BoxError",
   23     23   
   "aws_smithy_runtime_api::client::behavior_version::BehaviorVersion",
   24     24   
   "aws_smithy_runtime_api::client::dns::ResolveDns",
   25     25   
   "aws_smithy_runtime_api::client::http::HttpClient",
   26     26   
   "aws_smithy_runtime_api::client::identity::ResolveCachedIdentity",
   27     27   
   "aws_smithy_runtime_api::client::identity::ResolveIdentity",
   28     28   
   "aws_smithy_runtime_api::client::orchestrator::HttpResponse",
   29     29   
   "aws_smithy_runtime_api::client::retries::classifiers::ClassifyRetry",
   30     30   
   "aws_smithy_runtime_api::client::retries::classifiers::SharedRetryClassifier",
   31     31   
   "aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig",
          32  +
   "aws_smithy_schema::schema::protocol::ClientProtocol",
   32     33   
   "aws_smithy_types::checksum_config::RequestChecksumCalculation",
   33     34   
   "aws_smithy_types::checksum_config::ResponseChecksumValidation",
   34     35   
   "aws_smithy_types::retry::*",
   35     36   
   "aws_smithy_types::timeout::OperationTimeoutConfig",
   36     37   
   "aws_smithy_types::timeout::TimeoutConfig",
   37     38   
   "aws_smithy_types::timeout::TimeoutConfigBuilder",
   38     39   
   "aws_types::*",
   39     40   
]

tmp-codegen-diff/aws-sdk/sdk/aws-config/src/lib.rs

@@ -204,204 +263,264 @@
  224    224   
    use aws_credential_types::Credentials;
  225    225   
    use aws_smithy_async::rt::sleep::{default_async_sleep, AsyncSleep, SharedAsyncSleep};
  226    226   
    use aws_smithy_async::time::{SharedTimeSource, TimeSource};
  227    227   
    use aws_smithy_runtime::client::identity::IdentityCache;
  228    228   
    use aws_smithy_runtime_api::client::auth::AuthSchemePreference;
  229    229   
    use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
  230    230   
    use aws_smithy_runtime_api::client::http::HttpClient;
  231    231   
    use aws_smithy_runtime_api::client::identity::{ResolveCachedIdentity, SharedIdentityCache};
  232    232   
    use aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig;
  233    233   
    use aws_smithy_runtime_api::shared::IntoShared;
         234  +
    use aws_smithy_schema::protocol::{ClientProtocol, SharedClientProtocol};
  234    235   
    use aws_smithy_types::checksum_config::{
  235    236   
        RequestChecksumCalculation, ResponseChecksumValidation,
  236    237   
    };
  237    238   
    use aws_smithy_types::retry::RetryConfig;
  238    239   
    use aws_smithy_types::timeout::TimeoutConfig;
  239    240   
    use aws_types::app_name::AppName;
  240    241   
    use aws_types::docs_for;
  241    242   
    use aws_types::endpoint_config::AccountIdEndpointMode;
  242    243   
    use aws_types::origin::Origin;
  243    244   
    use aws_types::os_shim_internal::{Env, Fs};
@@ -276,277 +335,337 @@
  296    297   
        use_dual_stack: Option<bool>,
  297    298   
        time_source: Option<SharedTimeSource>,
  298    299   
        disable_request_compression: Option<bool>,
  299    300   
        request_min_compression_size_bytes: Option<u32>,
  300    301   
        stalled_stream_protection_config: Option<StalledStreamProtectionConfig>,
  301    302   
        env: Option<Env>,
  302    303   
        fs: Option<Fs>,
  303    304   
        behavior_version: Option<BehaviorVersion>,
  304    305   
        request_checksum_calculation: Option<RequestChecksumCalculation>,
  305    306   
        response_checksum_validation: Option<ResponseChecksumValidation>,
         307  +
        protocol: Option<SharedClientProtocol>,
  306    308   
    }
  307    309   
  308    310   
    impl ConfigLoader {
  309    311   
        /// Sets the [`BehaviorVersion`] used to build [`SdkConfig`].
  310    312   
        pub fn behavior_version(mut self, behavior_version: BehaviorVersion) -> Self {
  311    313   
            self.behavior_version = Some(behavior_version);
  312    314   
            self
  313    315   
        }
  314    316   
  315    317   
        /// Override the region used to build [`SdkConfig`].
@@ -383,385 +442,452 @@
  403    405   
        ///
  404    406   
        /// The HTTP client will be used for both AWS services and credentials providers.
  405    407   
        ///
  406    408   
        /// If you wish to use a separate HTTP client for credentials providers when creating clients,
  407    409   
        /// then override the HTTP client set with this function on the client-specific `Config`s.
  408    410   
        pub fn http_client(mut self, http_client: impl HttpClient + 'static) -> Self {
  409    411   
            self.http_client = Some(http_client.into_shared());
  410    412   
            self
  411    413   
        }
  412    414   
         415  +
        /// Sets the client protocol to use for serialization and deserialization.
         416  +
        ///
         417  +
        /// This overrides the default protocol determined by the service model.
         418  +
        pub fn protocol(mut self, protocol: impl ClientProtocol + 'static) -> Self {
         419  +
            self.protocol = Some(SharedClientProtocol::new(protocol));
         420  +
            self
         421  +
        }
         422  +
  413    423   
        #[doc = docs_for!(auth_scheme_preference)]
  414    424   
        ///
  415    425   
        /// # Examples
  416    426   
        /// ```no_run
  417    427   
        /// # use aws_smithy_runtime_api::client::auth::AuthSchemeId;
  418    428   
        /// # async fn create_config() {
  419    429   
        /// let config = aws_config::from_env()
  420    430   
        ///     // Favors a custom auth scheme over the SigV4 auth scheme.
  421    431   
        ///     // Note: This will not result in an error, even if the custom scheme is missing from the resolved auth schemes.
  422    432   
        ///     .auth_scheme_preference([AuthSchemeId::from("custom"), aws_runtime::auth::sigv4::SCHEME_ID])
@@ -963,973 +1022,1033 @@
  983    993   
                    }
  984    994   
                    // Not setting `Origin` in this arm, and that's good for now as long as we know
  985    995   
                    // it's not programmatically set in the shared config.
  986    996   
                    // We can consider adding `Origin::Default` if needed.
  987    997   
                }
  988    998   
            };
  989    999   
  990   1000   
            builder.set_endpoint_url(endpoint_url);
  991   1001   
            builder.set_behavior_version(self.behavior_version);
  992   1002   
            builder.set_http_client(self.http_client);
        1003  +
            builder.set_protocol(self.protocol);
  993   1004   
            builder.set_app_name(app_name);
  994   1005   
  995   1006   
            let identity_cache = match self.identity_cache {
  996   1007   
                None => match self.behavior_version {
  997   1008   
                    #[allow(deprecated)]
  998   1009   
                    Some(bv) if bv.is_at_least(BehaviorVersion::v2024_03_28()) => {
  999   1010   
                        Some(IdentityCache::lazy().build())
 1000   1011   
                    }
 1001   1012   
                    _ => None,
 1002   1013   
                },

tmp-codegen-diff/aws-sdk/sdk/aws-config/src/login.rs

@@ -470,470 +529,530 @@
  490    490   
                    )));
  491    491   
                }
  492    492   
                if let Some(resp) = &mock.response {
  493    493   
                    let body = format!(
  494    494   
                        r#"{{
  495    495   
                            "accessToken": {{
  496    496   
                                "accessKeyId": "{}",
  497    497   
                                "secretAccessKey": "{}",
  498    498   
                                "sessionToken": "{}"
  499    499   
                            }},
         500  +
                            "tokenType": "Bearer",
  500    501   
                            "expiresIn": {},
  501    502   
                            "refreshToken": "{}"
  502    503   
                        }}"#,
  503    504   
                        resp.token_output.access_token.access_key_id,
  504    505   
                        resp.token_output.access_token.secret_access_key,
  505    506   
                        resp.token_output.access_token.session_token,
  506    507   
                        resp.token_output.expires_in,
  507    508   
                        resp.token_output.refresh_token
  508    509   
                    );
  509    510   
                    return HttpConnectorFuture::ready(Ok(HttpResponse::new(

tmp-codegen-diff/aws-sdk/sdk/aws-config/src/profile/credentials.rs

@@ -836,836 +895,896 @@
  856    856   
  857    857   
    impl TestClient {
  858    858   
        fn new_success() -> Self {
  859    859   
            let call_count = Arc::new(AtomicUsize::new(0));
  860    860   
            let response = r#"{
  861    861   
                "accessToken": {
  862    862   
                    "accessKeyId": "ASIARTESTID",
  863    863   
                    "secretAccessKey": "TESTSECRETKEY",
  864    864   
                    "sessionToken": "TESTSESSIONTOKEN"
  865    865   
                },
         866  +
                "tokenType": "Bearer",
  866    867   
                "expiresIn": 3600,
  867    868   
                "refreshToken": "new-refresh-token"
  868    869   
            }"#;
  869    870   
            let inner = TestClientInner {
  870    871   
                call_count: call_count.clone(),
  871    872   
                response: Some(response),
  872    873   
            };
  873    874   
            Self {
  874    875   
                inner: SharedHttpConnector::new(inner),
  875    876   
                call_count,

tmp-codegen-diff/aws-sdk/sdk/aws-config/test-data/login-provider-test-cases.json

@@ -132,132 +191,192 @@
  152    152   
            "grantType": "refresh_token"
  153    153   
          }
  154    154   
        },
  155    155   
        "response": {
  156    156   
          "tokenOutput": {
  157    157   
            "accessToken": {
  158    158   
              "accessKeyId": "NEWREFRESHEDKEY",
  159    159   
              "secretAccessKey": "newRefreshedSecretKey",
  160    160   
              "sessionToken": "newRefreshedSessionToken"
  161    161   
            },
         162  +
            "tokenType": "Bearer",
  162    163   
            "refreshToken": "new_refresh_token",
  163    164   
            "expiresIn": 900
  164    165   
          }
  165    166   
        }
  166    167   
      }
  167    168   
    ],
  168    169   
    "outcomes": [
  169    170   
      {
  170    171   
        "result": "credentials",
  171    172   
        "accessKeyId": "NEWREFRESHEDKEY",

tmp-codegen-diff/aws-sdk/sdk/aws-credential-types/Cargo.toml

@@ -8,8 +50,50 @@
   28     28   
path = "../aws-smithy-async"
   29     29   
version = "1.2.14"
   30     30   
   31     31   
[dependencies.aws-smithy-types]
   32     32   
path = "../aws-smithy-types"
   33     33   
version = "1.4.7"
   34     34   
   35     35   
[dependencies.aws-smithy-runtime-api]
   36     36   
path = "../aws-smithy-runtime-api"
   37     37   
features = ["client", "http-auth"]
   38         -
version = "1.11.6"
          38  +
version = "1.11.7"
   39     39   
   40     40   
[dev-dependencies]
   41     41   
async-trait = "0.1.74"
   42     42   
   43     43   
[dev-dependencies.aws-smithy-runtime-api]
   44     44   
path = "../aws-smithy-runtime-api"
   45     45   
features = ["test-util"]
   46         -
version = "1.11.6"
          46  +
version = "1.11.7"
   47     47   
   48     48   
[dev-dependencies.tokio]
   49     49   
version = "1.49.0"
   50     50   
features = ["full", "test-util", "rt"]

tmp-codegen-diff/aws-sdk/sdk/aws-runtime/Cargo.toml

@@ -30,30 +95,95 @@
   50     50   
optional = true
   51     51   
version = "0.60.20"
   52     52   
   53     53   
[dependencies.aws-smithy-http]
   54     54   
path = "../aws-smithy-http"
   55     55   
version = "0.63.6"
   56     56   
   57     57   
[dependencies.aws-smithy-runtime]
   58     58   
path = "../aws-smithy-runtime"
   59     59   
features = ["client"]
   60         -
version = "1.10.3"
          60  +
version = "1.10.4"
   61     61   
   62     62   
[dependencies.aws-smithy-runtime-api]
   63     63   
path = "../aws-smithy-runtime-api"
   64     64   
features = ["client", "http-1x"]
   65         -
version = "1.11.6"
          65  +
version = "1.11.7"
   66     66   
   67     67   
[dependencies.aws-smithy-types]
   68     68   
path = "../aws-smithy-types"
   69     69   
features = ["http-body-1-x"]
   70     70   
version = "1.4.7"
   71     71   
   72     72   
[dependencies.aws-types]
   73     73   
path = "../aws-types"
   74     74   
version = "1.4.0"
   75     75   
@@ -97,97 +148,148 @@
  117    117   
features = ["test-util"]
  118    118   
version = "1.2.14"
  119    119   
  120    120   
[dev-dependencies.aws-smithy-protocol-test]
  121    121   
path = "../aws-smithy-protocol-test"
  122    122   
version = "0.63.14"
  123    123   
  124    124   
[dev-dependencies.aws-smithy-runtime-api]
  125    125   
path = "../aws-smithy-runtime-api"
  126    126   
features = ["test-util", "http-1x"]
  127         -
version = "1.11.6"
         127  +
version = "1.11.7"
  128    128   
  129    129   
[dev-dependencies.aws-smithy-types]
  130    130   
path = "../aws-smithy-types"
  131    131   
features = ["test-util"]
  132    132   
version = "1.4.7"
  133    133   
  134    134   
[dev-dependencies.futures-util]
  135    135   
version = "0.3.29"
  136    136   
default-features = false
  137    137   

tmp-codegen-diff/aws-sdk/sdk/aws-sigv4/Cargo.toml

@@ -32,32 +92,92 @@
   52     52   
optional = true
   53     53   
version = "0.60.20"
   54     54   
   55     55   
[dependencies.aws-smithy-http]
   56     56   
path = "../aws-smithy-http"
   57     57   
version = "0.63.6"
   58     58   
   59     59   
[dependencies.aws-smithy-runtime-api]
   60     60   
path = "../aws-smithy-runtime-api"
   61     61   
features = ["client"]
   62         -
version = "1.11.6"
          62  +
version = "1.11.7"
   63     63   
   64     64   
[dependencies.aws-smithy-types]
   65     65   
path = "../aws-smithy-types"
   66     66   
version = "1.4.7"
   67     67   
   68     68   
[dependencies.form_urlencoded]
   69     69   
version = "1.2.1"
   70     70   
optional = true
   71     71   
   72     72   
[dependencies.http0]
@@ -95,95 +131,131 @@
  115    115   
criterion = "0.5"
  116    116   
  117    117   
[dev-dependencies.aws-credential-types]
  118    118   
path = "../aws-credential-types"
  119    119   
features = ["test-util", "hardcoded-credentials"]
  120    120   
version = "1.2.14"
  121    121   
  122    122   
[dev-dependencies.aws-smithy-runtime-api]
  123    123   
path = "../aws-smithy-runtime-api"
  124    124   
features = ["client", "test-util"]
  125         -
version = "1.11.6"
         125  +
version = "1.11.7"
  126    126   
  127    127   
[dev-dependencies.time]
  128    128   
version = "0.3.5"
  129    129   
features = ["parsing"]
  130    130   
[target."cfg(not(any(target_arch = \"powerpc\", target_arch = \"powerpc64\")))".dev-dependencies]
  131    131   
ring = "0.17.5"

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-compression/Cargo.toml

@@ -2,2 +51,51 @@
   22     22   
futures-util = "0.3"
   23     23   
pin-project-lite = "0.2.14"
   24     24   
tracing = "0.1.44"
   25     25   
   26     26   
[dependencies.aws-smithy-types]
   27     27   
path = "../aws-smithy-types"
   28     28   
version = "1.4.7"
   29     29   
   30     30   
[dependencies.aws-smithy-runtime-api]
   31     31   
path = "../aws-smithy-runtime-api"
   32         -
version = "1.11.6"
          32  +
version = "1.11.7"
   33     33   
   34     34   
[dependencies.http-1x]
   35     35   
package = "http"
   36     36   
version = "1.3.1"
   37     37   
   38     38   
[dependencies.http-body-1x]
   39     39   
package = "http-body"
   40     40   
version = "1.0.1"
   41     41   
   42     42   
[dependencies.http-body-util]

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-dns/Cargo.toml

@@ -1,1 +33,33 @@
   12     12   
all-features = true
   13     13   
targets = ["x86_64-unknown-linux-gnu"]
   14     14   
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
   15     15   
rustdoc-args = ["--cfg", "docsrs"]
   16     16   
   17     17   
[features]
   18     18   
hickory-dns = ["dep:hickory-resolver", "dep:tokio", "tokio/rt"]
   19     19   
[dependencies.aws-smithy-runtime-api]
   20     20   
path = "../aws-smithy-runtime-api"
   21     21   
features = ["client"]
   22         -
version = "1.11.6"
          22  +
version = "1.11.7"
   23     23   
   24     24   
[dependencies.tokio]
   25     25   
version = "1.49.0"
   26     26   
features = []
   27     27   
optional = true
   28     28   
[target."cfg(not(target_family = \"wasm\"))".dependencies.hickory-resolver]
   29     29   
version = "0.25.2"
   30     30   
optional = true
   31     31   
   32     32   
[dev-dependencies]

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-http-client/Cargo.toml

@@ -33,33 +93,93 @@
   53     53   
pin-project-lite = "0.2.14"
   54     54   
tracing = "0.1.44"
   55     55   
   56     56   
[dependencies.aws-smithy-async]
   57     57   
path = "../aws-smithy-async"
   58     58   
version = "1.2.14"
   59     59   
   60     60   
[dependencies.aws-smithy-runtime-api]
   61     61   
path = "../aws-smithy-runtime-api"
   62     62   
features = ["client"]
   63         -
version = "1.11.6"
          63  +
version = "1.11.7"
   64     64   
   65     65   
[dependencies.aws-smithy-types]
   66     66   
path = "../aws-smithy-types"
   67     67   
version = "1.4.7"
   68     68   
   69     69   
[dependencies.aws-smithy-protocol-test]
   70     70   
path = "../aws-smithy-protocol-test"
   71     71   
optional = true
   72     72   
version = "0.63.14"
   73     73   
@@ -184,184 +234,234 @@
  204    204   
tokio-rustls = "0.26.2"
  205    205   
  206    206   
[dev-dependencies.aws-smithy-async]
  207    207   
path = "../aws-smithy-async"
  208    208   
features = ["rt-tokio", "test-util"]
  209    209   
version = "1.2.14"
  210    210   
  211    211   
[dev-dependencies.aws-smithy-runtime-api]
  212    212   
path = "../aws-smithy-runtime-api"
  213    213   
features = ["test-util"]
  214         -
version = "1.11.6"
         214  +
version = "1.11.7"
  215    215   
  216    216   
[dev-dependencies.aws-smithy-types]
  217    217   
path = "../aws-smithy-types"
  218    218   
features = ["http-body-0-4-x", "test-util"]
  219    219   
version = "1.4.7"
  220    220   
  221    221   
[dev-dependencies.http-body-util]
  222    222   
version = "0.1.3"
  223    223   
  224    224   
[dev-dependencies.hyper-util]

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-http/Cargo.toml

@@ -9,9 +69,69 @@
   29     29   
futures-core = "0.3.31"
   30     30   
   31     31   
[dependencies.aws-smithy-eventstream]
   32     32   
path = "../aws-smithy-eventstream"
   33     33   
optional = true
   34     34   
version = "0.60.20"
   35     35   
   36     36   
[dependencies.aws-smithy-runtime-api]
   37     37   
path = "../aws-smithy-runtime-api"
   38     38   
features = ["client", "http-1x"]
   39         -
version = "1.11.6"
          39  +
version = "1.11.7"
   40     40   
   41     41   
[dependencies.aws-smithy-types]
   42     42   
path = "../aws-smithy-types"
   43     43   
features = ["byte-stream-poll-next", "http-body-1-x"]
   44     44   
version = "1.4.7"
   45     45   
   46     46   
[dependencies.http-1x]
   47     47   
package = "http"
   48     48   
version = "1.3.1"
   49     49   

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-json/Cargo.toml

@@ -1,1 +0,31 @@
    6      6   
description = "Token streaming JSON parser for smithy-rs."
    7      7   
edition = "2021"
    8      8   
license = "Apache-2.0"
    9      9   
repository = "https://github.com/smithy-lang/smithy-rs"
   10     10   
rust-version = "1.91.1"
   11     11   
[package.metadata.docs.rs]
   12     12   
all-features = true
   13     13   
targets = ["x86_64-unknown-linux-gnu"]
   14     14   
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
   15     15   
rustdoc-args = ["--cfg", "docsrs"]
          16  +
[dependencies.aws-smithy-runtime-api]
          17  +
path = "../aws-smithy-runtime-api"
          18  +
features = ["client", "http-02x"]
          19  +
version = "1.11.7"
          20  +
   16     21   
[dependencies.aws-smithy-schema]
   17     22   
path = "../aws-smithy-schema"
   18     23   
version = "1.0.0"
   19     24   
   20     25   
[dependencies.aws-smithy-types]
   21     26   
path = "../aws-smithy-types"
   22     27   
version = "1.4.7"
   23     28   
   24     29   
[dev-dependencies]
   25     30   
proptest = "1"
   26         -
serde_json = "1.0"
          31  +
serde_json = "=1.0.146"

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-json/src/codec.rs

@@ -1,1 +195,183 @@
    1      1   
/*
    2      2   
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
    3      3   
 * SPDX-License-Identifier: Apache-2.0
    4      4   
 */
    5      5   
    6      6   
//! JSON codec implementation for schema-based serialization.
    7      7   
    8      8   
use aws_smithy_schema::codec::Codec;
    9      9   
use aws_smithy_schema::Schema;
   10     10   
use aws_smithy_types::date_time::Format as TimestampFormat;
   11         -
use std::collections::HashMap;
   12         -
use std::sync::Mutex;
   13         -
   14     11   
use std::sync::Arc;
   15     12   
   16     13   
mod deserializer;
   17     14   
mod serializer;
   18     15   
   19     16   
pub use deserializer::JsonDeserializer;
   20     17   
pub use serializer::JsonSerializer;
   21     18   
   22     19   
/// Maps between Smithy member names and JSON wire field names.
   23     20   
///
   24     21   
/// When `@jsonName` is enabled, the wire name may differ from the member name.
   25     22   
/// This type handles the mapping in both directions and caches the reverse
   26     23   
/// lookup (wire name → member index) per struct schema.
   27     24   
#[derive(Debug)]
   28     25   
enum JsonFieldMapper {
   29     26   
    /// Uses member names directly, ignoring `@jsonName`.
   30     27   
    UseMemberName,
   31         -
    /// Uses `@jsonName` trait values when present, with a cached reverse map.
   32         -
    UseJsonName {
   33         -
        /// Cache from schema pointer → (wire name → member index).
   34         -
        cache: Mutex<HashMap<usize, HashMap<String, usize>>>,
   35         -
    },
          28  +
    /// Uses `@jsonName` trait values when present, falling back to member name.
          29  +
    UseJsonName,
   36     30   
}
   37     31   
   38     32   
impl JsonFieldMapper {
   39     33   
    /// Returns the JSON wire name for a member schema.
   40     34   
    fn member_to_field<'a>(&self, member: &'a Schema) -> Option<&'a str> {
   41     35   
        let name = member.member_name()?;
   42     36   
        match self {
   43     37   
            JsonFieldMapper::UseMemberName => Some(name),
   44         -
            JsonFieldMapper::UseJsonName { .. } => {
          38  +
            JsonFieldMapper::UseJsonName => {
   45     39   
                if let Some(jn) = member.json_name() {
   46     40   
                    return Some(jn.value());
   47     41   
                }
   48     42   
                Some(name)
   49     43   
            }
   50     44   
        }
   51     45   
    }
   52     46   
   53     47   
    /// Resolves a JSON wire field name to a member schema within a struct schema.
   54     48   
    fn field_to_member<'s>(&self, schema: &'s Schema, field_name: &str) -> Option<&'s Schema> {
   55     49   
        match self {
   56     50   
            JsonFieldMapper::UseMemberName => schema.member_schema(field_name),
   57         -
            JsonFieldMapper::UseJsonName { cache } => {
   58         -
                let key = std::ptr::from_ref(schema) as usize;
   59         -
                let mut cache = cache.lock().unwrap();
   60         -
                let map = cache.entry(key).or_insert_with(|| {
   61         -
                    let mut map = HashMap::new();
   62         -
                    for (idx, member) in schema.members().iter().enumerate() {
          51  +
            JsonFieldMapper::UseJsonName => {
          52  +
                // Check @jsonName on each member. For typical struct sizes
          53  +
                // (< 50 members), linear scan is faster than a cached HashMap
          54  +
                // behind a Mutex.
          55  +
                for member in schema.members() {
   63     56   
                    if let Some(jn) = member.json_name() {
   64         -
                            map.insert(jn.value().to_string(), idx);
          57  +
                        if jn.value() == field_name {
          58  +
                            return Some(member);
   65     59   
                        }
          60  +
                    } else if member.member_name() == Some(field_name) {
          61  +
                        return Some(member);
   66     62   
                    }
   67         -
                    map
   68         -
                });
   69         -
                if let Some(&idx) = map.get(field_name) {
   70         -
                    return schema.member_schema_by_index(idx);
   71     63   
                }
   72         -
                schema.member_schema(field_name)
          64  +
                None
   73     65   
            }
   74     66   
        }
   75     67   
    }
   76     68   
}
   77     69   
   78     70   
/// Configuration for JSON codec behavior.
   79     71   
///
   80     72   
/// Use the builder methods to construct settings:
   81     73   
/// ```
   82     74   
/// use aws_smithy_json::codec::JsonCodecSettings;
   83     75   
///
   84     76   
/// let settings = JsonCodecSettings::builder()
   85     77   
///     .use_json_name(false)
   86     78   
///     .build();
   87     79   
/// ```
   88     80   
#[derive(Debug)]
   89     81   
pub struct JsonCodecSettings {
   90     82   
    field_mapper: JsonFieldMapper,
   91     83   
    default_timestamp_format: TimestampFormat,
   92     84   
}
   93     85   
   94     86   
impl JsonCodecSettings {
   95     87   
    /// Creates a builder for `JsonCodecSettings`.
   96     88   
    pub fn builder() -> JsonCodecSettingsBuilder {
   97     89   
        JsonCodecSettingsBuilder::default()
   98     90   
    }
   99     91   
  100     92   
    /// Default timestamp format when not specified by `@timestampFormat` trait.
  101     93   
    pub fn default_timestamp_format(&self) -> TimestampFormat {
  102     94   
        self.default_timestamp_format
  103     95   
    }
  104     96   
  105     97   
    /// Returns the JSON wire name for a member schema.
  106     98   
    pub(crate) fn member_to_field<'a>(&self, member: &'a Schema) -> Option<&'a str> {
  107     99   
        self.field_mapper.member_to_field(member)
  108    100   
    }
  109    101   
  110    102   
    /// Resolves a JSON wire field name to a member schema.
  111    103   
    pub(crate) fn field_to_member<'s>(
  112    104   
        &self,
  113    105   
        schema: &'s Schema,
  114    106   
        field_name: &str,
  115    107   
    ) -> Option<&'s Schema> {
  116    108   
        self.field_mapper.field_to_member(schema, field_name)
  117    109   
    }
  118    110   
}
  119    111   
  120    112   
impl Default for JsonCodecSettings {
  121    113   
    fn default() -> Self {
  122    114   
        Self {
  123         -
            field_mapper: JsonFieldMapper::UseJsonName {
  124         -
                cache: Mutex::new(HashMap::new()),
  125         -
            },
         115  +
            field_mapper: JsonFieldMapper::UseJsonName,
  126    116   
            default_timestamp_format: TimestampFormat::EpochSeconds,
  127    117   
        }
  128    118   
    }
  129    119   
}
  130    120   
  131    121   
/// Builder for [`JsonCodecSettings`].
  132    122   
#[derive(Debug, Clone)]
  133    123   
pub struct JsonCodecSettingsBuilder {
  134    124   
    use_json_name: bool,
  135    125   
    default_timestamp_format: TimestampFormat,
  136    126   
}
  137    127   
  138    128   
impl Default for JsonCodecSettingsBuilder {
  139    129   
    fn default() -> Self {
  140    130   
        Self {
  141    131   
            use_json_name: true,
  142    132   
            default_timestamp_format: TimestampFormat::EpochSeconds,
  143    133   
        }
  144    134   
    }
  145    135   
}
  146    136   
  147    137   
impl JsonCodecSettingsBuilder {
  148    138   
    /// Whether to use the `@jsonName` trait for member names.
  149    139   
    pub fn use_json_name(mut self, value: bool) -> Self {
  150    140   
        self.use_json_name = value;
  151    141   
        self
  152    142   
    }
  153    143   
  154    144   
    /// Default timestamp format when not specified by `@timestampFormat` trait.
  155    145   
    pub fn default_timestamp_format(mut self, value: TimestampFormat) -> Self {
  156    146   
        self.default_timestamp_format = value;
  157    147   
        self
  158    148   
    }
  159    149   
  160    150   
    /// Builds the settings.
  161    151   
    pub fn build(self) -> JsonCodecSettings {
  162    152   
        let field_mapper = if self.use_json_name {
  163         -
            JsonFieldMapper::UseJsonName {
  164         -
                cache: Mutex::new(HashMap::new()),
  165         -
            }
         153  +
            JsonFieldMapper::UseJsonName
  166    154   
        } else {
  167    155   
            JsonFieldMapper::UseMemberName
  168    156   
        };
  169    157   
        JsonCodecSettings {
  170    158   
            field_mapper,
  171    159   
            default_timestamp_format: self.default_timestamp_format,
  172    160   
        }
  173    161   
    }
  174    162   
}
  175    163