AWS SDK

AWS SDK

rev. bcb15a1f8b102ab3e59dfc703dfbe8602636364b (ignoring whitespace)

Files changed:

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

@@ -0,1 +0,21 @@
           1  +
# Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
[package]
           3  +
name = "aws-smithy-schema"
           4  +
version = "0.1.0"
           5  +
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>"]
           6  +
description = "Schema types for the smithy-rs ecosystem"
           7  +
edition = "2021"
           8  +
license = "Apache-2.0"
           9  +
repository = "https://github.com/smithy-lang/smithy-rs"
          10  +
rust-version = "1.91"
          11  +
[package.metadata.docs.rs]
          12  +
all-features = true
          13  +
targets = ["x86_64-unknown-linux-gnu"]
          14  +
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
          15  +
rustdoc-args = ["--cfg", "docsrs"]
          16  +
[dependencies.aws-smithy-types]
          17  +
path = "../aws-smithy-types"
          18  +
default-features = false
          19  +
version = "1.4.5"
          20  +
          21  +
[dev-dependencies]

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/LICENSE

@@ -0,1 +0,175 @@
           1  +
           2  +
                                 Apache License
           3  +
                           Version 2.0, January 2004
           4  +
                        http://www.apache.org/licenses/
           5  +
           6  +
   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
           7  +
           8  +
   1. Definitions.
           9  +
          10  +
      "License" shall mean the terms and conditions for use, reproduction,
          11  +
      and distribution as defined by Sections 1 through 9 of this document.
          12  +
          13  +
      "Licensor" shall mean the copyright owner or entity authorized by
          14  +
      the copyright owner that is granting the License.
          15  +
          16  +
      "Legal Entity" shall mean the union of the acting entity and all
          17  +
      other entities that control, are controlled by, or are under common
          18  +
      control with that entity. For the purposes of this definition,
          19  +
      "control" means (i) the power, direct or indirect, to cause the
          20  +
      direction or management of such entity, whether by contract or
          21  +
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
          22  +
      outstanding shares, or (iii) beneficial ownership of such entity.
          23  +
          24  +
      "You" (or "Your") shall mean an individual or Legal Entity
          25  +
      exercising permissions granted by this License.
          26  +
          27  +
      "Source" form shall mean the preferred form for making modifications,
          28  +
      including but not limited to software source code, documentation
          29  +
      source, and configuration files.
          30  +
          31  +
      "Object" form shall mean any form resulting from mechanical
          32  +
      transformation or translation of a Source form, including but
          33  +
      not limited to compiled object code, generated documentation,
          34  +
      and conversions to other media types.
          35  +
          36  +
      "Work" shall mean the work of authorship, whether in Source or
          37  +
      Object form, made available under the License, as indicated by a
          38  +
      copyright notice that is included in or attached to the work
          39  +
      (an example is provided in the Appendix below).
          40  +
          41  +
      "Derivative Works" shall mean any work, whether in Source or Object
          42  +
      form, that is based on (or derived from) the Work and for which the
          43  +
      editorial revisions, annotations, elaborations, or other modifications
          44  +
      represent, as a whole, an original work of authorship. For the purposes
          45  +
      of this License, Derivative Works shall not include works that remain
          46  +
      separable from, or merely link (or bind by name) to the interfaces of,
          47  +
      the Work and Derivative Works thereof.
          48  +
          49  +
      "Contribution" shall mean any work of authorship, including
          50  +
      the original version of the Work and any modifications or additions
          51  +
      to that Work or Derivative Works thereof, that is intentionally
          52  +
      submitted to Licensor for inclusion in the Work by the copyright owner
          53  +
      or by an individual or Legal Entity authorized to submit on behalf of
          54  +
      the copyright owner. For the purposes of this definition, "submitted"
          55  +
      means any form of electronic, verbal, or written communication sent
          56  +
      to the Licensor or its representatives, including but not limited to
          57  +
      communication on electronic mailing lists, source code control systems,
          58  +
      and issue tracking systems that are managed by, or on behalf of, the
          59  +
      Licensor for the purpose of discussing and improving the Work, but
          60  +
      excluding communication that is conspicuously marked or otherwise
          61  +
      designated in writing by the copyright owner as "Not a Contribution."
          62  +
          63  +
      "Contributor" shall mean Licensor and any individual or Legal Entity
          64  +
      on behalf of whom a Contribution has been received by Licensor and
          65  +
      subsequently incorporated within the Work.
          66  +
          67  +
   2. Grant of Copyright License. Subject to the terms and conditions of
          68  +
      this License, each Contributor hereby grants to You a perpetual,
          69  +
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
          70  +
      copyright license to reproduce, prepare Derivative Works of,
          71  +
      publicly display, publicly perform, sublicense, and distribute the
          72  +
      Work and such Derivative Works in Source or Object form.
          73  +
          74  +
   3. Grant of Patent License. Subject to the terms and conditions of
          75  +
      this License, each Contributor hereby grants to You a perpetual,
          76  +
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
          77  +
      (except as stated in this section) patent license to make, have made,
          78  +
      use, offer to sell, sell, import, and otherwise transfer the Work,
          79  +
      where such license applies only to those patent claims licensable
          80  +
      by such Contributor that are necessarily infringed by their
          81  +
      Contribution(s) alone or by combination of their Contribution(s)
          82  +
      with the Work to which such Contribution(s) was submitted. If You
          83  +
      institute patent litigation against any entity (including a
          84  +
      cross-claim or counterclaim in a lawsuit) alleging that the Work
          85  +
      or a Contribution incorporated within the Work constitutes direct
          86  +
      or contributory patent infringement, then any patent licenses
          87  +
      granted to You under this License for that Work shall terminate
          88  +
      as of the date such litigation is filed.
          89  +
          90  +
   4. Redistribution. You may reproduce and distribute copies of the
          91  +
      Work or Derivative Works thereof in any medium, with or without
          92  +
      modifications, and in Source or Object form, provided that You
          93  +
      meet the following conditions:
          94  +
          95  +
      (a) You must give any other recipients of the Work or
          96  +
          Derivative Works a copy of this License; and
          97  +
          98  +
      (b) You must cause any modified files to carry prominent notices
          99  +
          stating that You changed the files; and
         100  +
         101  +
      (c) You must retain, in the Source form of any Derivative Works
         102  +
          that You distribute, all copyright, patent, trademark, and
         103  +
          attribution notices from the Source form of the Work,
         104  +
          excluding those notices that do not pertain to any part of
         105  +
          the Derivative Works; and
         106  +
         107  +
      (d) If the Work includes a "NOTICE" text file as part of its
         108  +
          distribution, then any Derivative Works that You distribute must
         109  +
          include a readable copy of the attribution notices contained
         110  +
          within such NOTICE file, excluding those notices that do not
         111  +
          pertain to any part of the Derivative Works, in at least one
         112  +
          of the following places: within a NOTICE text file distributed
         113  +
          as part of the Derivative Works; within the Source form or
         114  +
          documentation, if provided along with the Derivative Works; or,
         115  +
          within a display generated by the Derivative Works, if and
         116  +
          wherever such third-party notices normally appear. The contents
         117  +
          of the NOTICE file are for informational purposes only and
         118  +
          do not modify the License. You may add Your own attribution
         119  +
          notices within Derivative Works that You distribute, alongside
         120  +
          or as an addendum to the NOTICE text from the Work, provided
         121  +
          that such additional attribution notices cannot be construed
         122  +
          as modifying the License.
         123  +
         124  +
      You may add Your own copyright statement to Your modifications and
         125  +
      may provide additional or different license terms and conditions
         126  +
      for use, reproduction, or distribution of Your modifications, or
         127  +
      for any such Derivative Works as a whole, provided Your use,
         128  +
      reproduction, and distribution of the Work otherwise complies with
         129  +
      the conditions stated in this License.
         130  +
         131  +
   5. Submission of Contributions. Unless You explicitly state otherwise,
         132  +
      any Contribution intentionally submitted for inclusion in the Work
         133  +
      by You to the Licensor shall be under the terms and conditions of
         134  +
      this License, without any additional terms or conditions.
         135  +
      Notwithstanding the above, nothing herein shall supersede or modify
         136  +
      the terms of any separate license agreement you may have executed
         137  +
      with Licensor regarding such Contributions.
         138  +
         139  +
   6. Trademarks. This License does not grant permission to use the trade
         140  +
      names, trademarks, service marks, or product names of the Licensor,
         141  +
      except as required for reasonable and customary use in describing the
         142  +
      origin of the Work and reproducing the content of the NOTICE file.
         143  +
         144  +
   7. Disclaimer of Warranty. Unless required by applicable law or
         145  +
      agreed to in writing, Licensor provides the Work (and each
         146  +
      Contributor provides its Contributions) on an "AS IS" BASIS,
         147  +
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
         148  +
      implied, including, without limitation, any warranties or conditions
         149  +
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
         150  +
      PARTICULAR PURPOSE. You are solely responsible for determining the
         151  +
      appropriateness of using or redistributing the Work and assume any
         152  +
      risks associated with Your exercise of permissions under this License.
         153  +
         154  +
   8. Limitation of Liability. In no event and under no legal theory,
         155  +
      whether in tort (including negligence), contract, or otherwise,
         156  +
      unless required by applicable law (such as deliberate and grossly
         157  +
      negligent acts) or agreed to in writing, shall any Contributor be
         158  +
      liable to You for damages, including any direct, indirect, special,
         159  +
      incidental, or consequential damages of any character arising as a
         160  +
      result of this License or out of the use or inability to use the
         161  +
      Work (including but not limited to damages for loss of goodwill,
         162  +
      work stoppage, computer failure or malfunction, or any and all
         163  +
      other commercial damages or losses), even if such Contributor
         164  +
      has been advised of the possibility of such damages.
         165  +
         166  +
   9. Accepting Warranty or Additional Liability. While redistributing
         167  +
      the Work or Derivative Works thereof, You may choose to offer,
         168  +
      and charge a fee for, acceptance of support, warranty, indemnity,
         169  +
      or other liability obligations and/or rights consistent with this
         170  +
      License. However, in accepting such obligations, You may act only
         171  +
      on Your own behalf and on Your sole responsibility, not on behalf
         172  +
      of any other Contributor, and only if You agree to indemnify,
         173  +
      defend, and hold each Contributor harmless for any liability
         174  +
      incurred by, or claims asserted against, such Contributor by reason
         175  +
      of your accepting any such warranty or additional liability.

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/README.md

@@ -0,1 +0,7 @@
           1  +
# aws-smithy-schema
           2  +
           3  +
Schema types for the smithy-rs ecosystem.
           4  +
           5  +
<!-- anchor_start:footer -->
           6  +
This crate is part of the [AWS SDK for Rust](https://awslabs.github.io/aws-sdk-rust/) and the [smithy-rs](https://github.com/smithy-lang/smithy-rs) code generator. In most cases, it should not be used directly.
           7  +
<!-- anchor_end:footer -->

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/lib.rs

@@ -0,1 +0,268 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
/* Automatically managed default lints */
           7  +
#![cfg_attr(docsrs, feature(doc_cfg))]
           8  +
/* End of automatically managed default lints */
           9  +
          10  +
//! Runtime schema types for Smithy shapes.
          11  +
//!
          12  +
//! This module provides the core types for representing Smithy schemas at runtime,
          13  +
//! enabling protocol-agnostic serialization and deserialization.
          14  +
          15  +
mod schema {
          16  +
    pub mod shape_id;
          17  +
    pub mod shape_type;
          18  +
    pub mod trait_map;
          19  +
    pub mod trait_type;
          20  +
          21  +
    pub mod prelude;
          22  +
    pub mod serde;
          23  +
}
          24  +
          25  +
pub use schema::shape_id::ShapeId;
          26  +
pub use schema::shape_type::ShapeType;
          27  +
pub use schema::trait_map::TraitMap;
          28  +
pub use schema::trait_type::Trait;
          29  +
          30  +
pub mod prelude {
          31  +
    pub use crate::schema::prelude::*;
          32  +
}
          33  +
          34  +
pub mod serde {
          35  +
    pub use crate::schema::serde::*;
          36  +
}
          37  +
          38  +
/// Core trait representing a Smithy schema at runtime.
          39  +
///
          40  +
/// A schema is a lightweight runtime representation of a Smithy shape,
          41  +
/// containing the shape's ID, type, traits, and references to member schemas.
          42  +
pub trait Schema: Send + Sync {
          43  +
    /// Returns the Shape ID of this schema.
          44  +
    fn shape_id(&self) -> &ShapeId;
          45  +
          46  +
    /// Returns the shape type.
          47  +
    fn shape_type(&self) -> ShapeType;
          48  +
          49  +
    /// Returns the traits associated with this schema.
          50  +
    fn traits(&self) -> &TraitMap;
          51  +
          52  +
    /// Returns the member name if this is a member schema.
          53  +
    fn member_name(&self) -> Option<&str> {
          54  +
        None
          55  +
    }
          56  +
          57  +
    /// Returns the member schema by name (for structures and unions).
          58  +
    fn member_schema(&self, _name: &str) -> Option<&dyn Schema> {
          59  +
        None
          60  +
    }
          61  +
          62  +
    /// Returns the member schema by position index (for structures and unions).
          63  +
    ///
          64  +
    /// This is an optimization for generated code to avoid string lookups.
          65  +
    /// Consumer code should not rely on specific position values as they may change.
          66  +
    fn member_schema_by_index(&self, _index: usize) -> Option<&dyn Schema> {
          67  +
        None
          68  +
    }
          69  +
          70  +
    /// Returns the member schema for collections (list member or map value).
          71  +
    fn member(&self) -> Option<&dyn Schema> {
          72  +
        None
          73  +
    }
          74  +
          75  +
    /// Returns the key schema for maps.
          76  +
    fn key(&self) -> Option<&dyn Schema> {
          77  +
        None
          78  +
    }
          79  +
          80  +
    /// Returns an iterator over member schemas (for structures and unions).
          81  +
    fn members(&self) -> Box<dyn Iterator<Item = &dyn Schema> + '_> {
          82  +
        Box::new(std::iter::empty())
          83  +
    }
          84  +
          85  +
    /// Returns the member index for member schemas.
          86  +
    ///
          87  +
    /// This is used internally by generated code for efficient member lookup.
          88  +
    /// Returns None if not applicable or not a member schema.
          89  +
    fn member_index(&self) -> Option<usize> {
          90  +
        None
          91  +
    }
          92  +
}
          93  +
          94  +
/// Helper methods for Schema trait.
          95  +
pub trait SchemaExt: Schema {
          96  +
    /// Returns true if this is a member schema.
          97  +
    fn is_member(&self) -> bool {
          98  +
        self.shape_type().is_member()
          99  +
    }
         100  +
         101  +
    /// Returns true if this is a structure schema.
         102  +
    fn is_structure(&self) -> bool {
         103  +
        self.shape_type() == ShapeType::Structure
         104  +
    }
         105  +
         106  +
    /// Returns true if this is a union schema.
         107  +
    fn is_union(&self) -> bool {
         108  +
        self.shape_type() == ShapeType::Union
         109  +
    }
         110  +
         111  +
    /// Returns true if this is a list schema.
         112  +
    fn is_list(&self) -> bool {
         113  +
        self.shape_type() == ShapeType::List
         114  +
    }
         115  +
         116  +
    /// Returns true if this is a map schema.
         117  +
    fn is_map(&self) -> bool {
         118  +
        self.shape_type() == ShapeType::Map
         119  +
    }
         120  +
         121  +
    /// Returns true if this is a blob schema.
         122  +
    fn is_blob(&self) -> bool {
         123  +
        self.shape_type() == ShapeType::Blob
         124  +
    }
         125  +
         126  +
    /// Returns true if this is a string schema.
         127  +
    fn is_string(&self) -> bool {
         128  +
        self.shape_type() == ShapeType::String
         129  +
    }
         130  +
}
         131  +
         132  +
impl<T: Schema + ?Sized> SchemaExt for T {}
         133  +
         134  +
#[cfg(test)]
         135  +
mod test {
         136  +
    use crate::{Schema, SchemaExt, ShapeId, ShapeType, Trait, TraitMap};
         137  +
         138  +
    // Simple test trait implementation
         139  +
    #[derive(Debug)]
         140  +
    struct TestTrait {
         141  +
        id: ShapeId,
         142  +
        #[allow(dead_code)]
         143  +
        value: String,
         144  +
    }
         145  +
         146  +
    impl Trait for TestTrait {
         147  +
        fn trait_id(&self) -> &ShapeId {
         148  +
            &self.id
         149  +
        }
         150  +
         151  +
        fn as_any(&self) -> &dyn std::any::Any {
         152  +
            self
         153  +
        }
         154  +
    }
         155  +
         156  +
    // Simple test schema implementation
         157  +
    struct TestSchema {
         158  +
        id: ShapeId,
         159  +
        shape_type: ShapeType,
         160  +
        traits: TraitMap,
         161  +
    }
         162  +
         163  +
    impl Schema for TestSchema {
         164  +
        fn shape_id(&self) -> &ShapeId {
         165  +
            &self.id
         166  +
        }
         167  +
         168  +
        fn shape_type(&self) -> ShapeType {
         169  +
            self.shape_type
         170  +
        }
         171  +
         172  +
        fn traits(&self) -> &TraitMap {
         173  +
            &self.traits
         174  +
        }
         175  +
    }
         176  +
         177  +
    #[test]
         178  +
    fn test_shape_type_simple() {
         179  +
        assert!(ShapeType::String.is_simple());
         180  +
        assert!(ShapeType::Integer.is_simple());
         181  +
        assert!(ShapeType::Boolean.is_simple());
         182  +
        assert!(!ShapeType::Structure.is_simple());
         183  +
        assert!(!ShapeType::List.is_simple());
         184  +
    }
         185  +
         186  +
    #[test]
         187  +
    fn test_shape_type_aggregate() {
         188  +
        assert!(ShapeType::Structure.is_aggregate());
         189  +
        assert!(ShapeType::Union.is_aggregate());
         190  +
        assert!(ShapeType::List.is_aggregate());
         191  +
        assert!(ShapeType::Map.is_aggregate());
         192  +
        assert!(!ShapeType::String.is_aggregate());
         193  +
    }
         194  +
         195  +
    #[test]
         196  +
    fn test_shape_type_member() {
         197  +
        assert!(ShapeType::Member.is_member());
         198  +
        assert!(!ShapeType::String.is_member());
         199  +
        assert!(!ShapeType::Structure.is_member());
         200  +
    }
         201  +
         202  +
    #[test]
         203  +
    fn test_shape_id_parsing() {
         204  +
        let id = ShapeId::new("smithy.api#String");
         205  +
        assert_eq!(id.namespace(), "smithy.api");
         206  +
        assert_eq!(id.shape_name(), "String");
         207  +
        assert_eq!(id.member_name(), None);
         208  +
    }
         209  +
         210  +
    #[test]
         211  +
    fn test_shape_id_with_member() {
         212  +
        let id = ShapeId::new("com.example#MyStruct$member");
         213  +
        assert_eq!(id.namespace(), "com.example");
         214  +
        assert_eq!(id.shape_name(), "MyStruct");
         215  +
        assert_eq!(id.member_name(), Some("member"));
         216  +
    }
         217  +
         218  +
    #[test]
         219  +
    fn test_trait_map() {
         220  +
        let mut map = TraitMap::new();
         221  +
        assert!(map.is_empty());
         222  +
        assert_eq!(map.len(), 0);
         223  +
         224  +
        let trait_id = ShapeId::new("smithy.api#required");
         225  +
        let test_trait = Box::new(TestTrait {
         226  +
            id: trait_id.clone(),
         227  +
            value: "test".to_string(),
         228  +
        });
         229  +
         230  +
        map.insert(test_trait);
         231  +
        assert!(!map.is_empty());
         232  +
        assert_eq!(map.len(), 1);
         233  +
        assert!(map.contains(&trait_id));
         234  +
         235  +
        let retrieved = map.get(&trait_id);
         236  +
        assert!(retrieved.is_some());
         237  +
    }
         238  +
         239  +
    #[test]
         240  +
    fn test_schema_ext() {
         241  +
        let schema = TestSchema {
         242  +
            id: ShapeId::new("com.example#MyStruct"),
         243  +
            shape_type: ShapeType::Structure,
         244  +
            traits: TraitMap::new(),
         245  +
        };
         246  +
         247  +
        assert!(schema.is_structure());
         248  +
        assert!(!schema.is_union());
         249  +
        assert!(!schema.is_list());
         250  +
        assert!(!schema.is_member());
         251  +
    }
         252  +
         253  +
    #[test]
         254  +
    fn test_schema_basic() {
         255  +
        let schema = TestSchema {
         256  +
            id: ShapeId::new("smithy.api#String"),
         257  +
            shape_type: ShapeType::String,
         258  +
            traits: TraitMap::new(),
         259  +
        };
         260  +
         261  +
        assert_eq!(schema.shape_id().as_str(), "smithy.api#String");
         262  +
        assert_eq!(schema.shape_type(), ShapeType::String);
         263  +
        assert!(schema.traits().is_empty());
         264  +
        assert!(schema.member_name().is_none());
         265  +
        assert!(schema.member_schema("test").is_none());
         266  +
        assert!(schema.member_schema_by_index(0).is_none());
         267  +
    }
         268  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/prelude.rs

@@ -0,1 +0,193 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! Prelude schemas for built-in Smithy types.
           7  +
//!
           8  +
//! This module provides const schemas for Smithy's prelude types,
           9  +
//! which are the fundamental types available in all Smithy models.
          10  +
          11  +
use std::sync::LazyLock;
          12  +
          13  +
use crate::{Schema, ShapeId, ShapeType, TraitMap};
          14  +
          15  +
/// A simple schema implementation for prelude types.
          16  +
#[derive(Debug)]
          17  +
pub struct PreludeSchema {
          18  +
    id: ShapeId,
          19  +
    shape_type: ShapeType,
          20  +
}
          21  +
          22  +
impl PreludeSchema {
          23  +
    /// Creates a new prelude schema.
          24  +
    pub const fn new(id: ShapeId, shape_type: ShapeType) -> Self {
          25  +
        Self { id, shape_type }
          26  +
    }
          27  +
}
          28  +
          29  +
impl Schema for PreludeSchema {
          30  +
    fn shape_id(&self) -> &ShapeId {
          31  +
        &self.id
          32  +
    }
          33  +
          34  +
    fn shape_type(&self) -> ShapeType {
          35  +
        self.shape_type
          36  +
    }
          37  +
          38  +
    fn traits(&self) -> &TraitMap {
          39  +
        static MAP: LazyLock<TraitMap> = LazyLock::new(TraitMap::empty);
          40  +
          41  +
        &MAP
          42  +
    }
          43  +
}
          44  +
          45  +
// TODO(schema): We should probably test with these as `pub static` too since that could
          46  +
// theoretically cut down on binary size (at the expense of some runtime performance)
          47  +
          48  +
/// Schema for `smithy.api#String`
          49  +
pub const STRING: PreludeSchema = PreludeSchema::new(
          50  +
    ShapeId::from_static("smithy.api#String", "smithy.api", "String"),
          51  +
    ShapeType::String,
          52  +
);
          53  +
          54  +
/// Schema for `smithy.api#Boolean`
          55  +
pub const BOOLEAN: PreludeSchema = PreludeSchema::new(
          56  +
    ShapeId::from_static("smithy.api#Boolean", "smithy.api", "Boolean"),
          57  +
    ShapeType::Boolean,
          58  +
);
          59  +
          60  +
/// Schema for `smithy.api#Byte`
          61  +
pub const BYTE: PreludeSchema = PreludeSchema::new(
          62  +
    ShapeId::from_static("smithy.api#Byte", "smithy.api", "Byte"),
          63  +
    ShapeType::Byte,
          64  +
);
          65  +
          66  +
/// Schema for `smithy.api#Short`
          67  +
pub const SHORT: PreludeSchema = PreludeSchema::new(
          68  +
    ShapeId::from_static("smithy.api#Short", "smithy.api", "Short"),
          69  +
    ShapeType::Short,
          70  +
);
          71  +
          72  +
/// Schema for `smithy.api#Integer`
          73  +
pub const INTEGER: PreludeSchema = PreludeSchema::new(
          74  +
    ShapeId::from_static("smithy.api#Integer", "smithy.api", "Integer"),
          75  +
    ShapeType::Integer,
          76  +
);
          77  +
          78  +
/// Schema for `smithy.api#Long`
          79  +
pub const LONG: PreludeSchema = PreludeSchema::new(
          80  +
    ShapeId::from_static("smithy.api#Long", "smithy.api", "Long"),
          81  +
    ShapeType::Long,
          82  +
);
          83  +
          84  +
/// Schema for `smithy.api#Float`
          85  +
pub const FLOAT: PreludeSchema = PreludeSchema::new(
          86  +
    ShapeId::from_static("smithy.api#Float", "smithy.api", "Float"),
          87  +
    ShapeType::Float,
          88  +
);
          89  +
          90  +
/// Schema for `smithy.api#Double`
          91  +
pub const DOUBLE: PreludeSchema = PreludeSchema::new(
          92  +
    ShapeId::from_static("smithy.api#Double", "smithy.api", "Double"),
          93  +
    ShapeType::Double,
          94  +
);
          95  +
          96  +
/// Schema for `smithy.api#BigInteger`
          97  +
pub const BIG_INTEGER: PreludeSchema = PreludeSchema::new(
          98  +
    ShapeId::from_static("smithy.api#BigInteger", "smithy.api", "BigInteger"),
          99  +
    ShapeType::BigInteger,
         100  +
);
         101  +
         102  +
/// Schema for `smithy.api#BigDecimal`
         103  +
pub const BIG_DECIMAL: PreludeSchema = PreludeSchema::new(
         104  +
    ShapeId::from_static("smithy.api#BigDecimal", "smithy.api", "BigDecimal"),
         105  +
    ShapeType::BigDecimal,
         106  +
);
         107  +
         108  +
/// Schema for `smithy.api#Blob`
         109  +
pub const BLOB: PreludeSchema = PreludeSchema::new(
         110  +
    ShapeId::from_static("smithy.api#Blob", "smithy.api", "Blob"),
         111  +
    ShapeType::Blob,
         112  +
);
         113  +
         114  +
/// Schema for `smithy.api#Timestamp`
         115  +
pub const TIMESTAMP: PreludeSchema = PreludeSchema::new(
         116  +
    ShapeId::from_static("smithy.api#Timestamp", "smithy.api", "Timestamp"),
         117  +
    ShapeType::Timestamp,
         118  +
);
         119  +
         120  +
/// Schema for `smithy.api#Document`
         121  +
pub const DOCUMENT: PreludeSchema = PreludeSchema::new(
         122  +
    ShapeId::from_static("smithy.api#Document", "smithy.api", "Document"),
         123  +
    ShapeType::Document,
         124  +
);
         125  +
         126  +
#[cfg(test)]
         127  +
mod tests {
         128  +
    use super::*;
         129  +
    use crate::SchemaExt;
         130  +
         131  +
    #[test]
         132  +
    fn test_string_schema() {
         133  +
        assert_eq!(STRING.shape_id().as_str(), "smithy.api#String");
         134  +
        assert_eq!(STRING.shape_type(), ShapeType::String);
         135  +
        assert!(STRING.is_string());
         136  +
        assert!(STRING.traits().is_empty());
         137  +
    }
         138  +
         139  +
    #[test]
         140  +
    fn test_boolean_schema() {
         141  +
        assert_eq!(BOOLEAN.shape_id().as_str(), "smithy.api#Boolean");
         142  +
        assert_eq!(BOOLEAN.shape_type(), ShapeType::Boolean);
         143  +
        assert!(BOOLEAN.traits().is_empty());
         144  +
    }
         145  +
         146  +
    #[test]
         147  +
    fn test_numeric_schemas() {
         148  +
        assert_eq!(BYTE.shape_type(), ShapeType::Byte);
         149  +
        assert_eq!(SHORT.shape_type(), ShapeType::Short);
         150  +
        assert_eq!(INTEGER.shape_type(), ShapeType::Integer);
         151  +
        assert_eq!(LONG.shape_type(), ShapeType::Long);
         152  +
        assert_eq!(FLOAT.shape_type(), ShapeType::Float);
         153  +
        assert_eq!(DOUBLE.shape_type(), ShapeType::Double);
         154  +
        assert_eq!(BIG_INTEGER.shape_type(), ShapeType::BigInteger);
         155  +
        assert_eq!(BIG_DECIMAL.shape_type(), ShapeType::BigDecimal);
         156  +
    }
         157  +
         158  +
    #[test]
         159  +
    fn test_blob_schema() {
         160  +
        assert_eq!(BLOB.shape_id().as_str(), "smithy.api#Blob");
         161  +
        assert_eq!(BLOB.shape_type(), ShapeType::Blob);
         162  +
        assert!(BLOB.is_blob());
         163  +
    }
         164  +
         165  +
    #[test]
         166  +
    fn test_timestamp_schema() {
         167  +
        assert_eq!(TIMESTAMP.shape_id().as_str(), "smithy.api#Timestamp");
         168  +
        assert_eq!(TIMESTAMP.shape_type(), ShapeType::Timestamp);
         169  +
    }
         170  +
         171  +
    #[test]
         172  +
    fn test_document_schema() {
         173  +
        assert_eq!(DOCUMENT.shape_id().as_str(), "smithy.api#Document");
         174  +
        assert_eq!(DOCUMENT.shape_type(), ShapeType::Document);
         175  +
    }
         176  +
         177  +
    #[test]
         178  +
    fn test_all_prelude_types_are_simple() {
         179  +
        assert!(STRING.shape_type().is_simple());
         180  +
        assert!(BOOLEAN.shape_type().is_simple());
         181  +
        assert!(BYTE.shape_type().is_simple());
         182  +
        assert!(SHORT.shape_type().is_simple());
         183  +
        assert!(INTEGER.shape_type().is_simple());
         184  +
        assert!(LONG.shape_type().is_simple());
         185  +
        assert!(FLOAT.shape_type().is_simple());
         186  +
        assert!(DOUBLE.shape_type().is_simple());
         187  +
        assert!(BIG_INTEGER.shape_type().is_simple());
         188  +
        assert!(BIG_DECIMAL.shape_type().is_simple());
         189  +
        assert!(BLOB.shape_type().is_simple());
         190  +
        assert!(TIMESTAMP.shape_type().is_simple());
         191  +
        assert!(DOCUMENT.shape_type().is_simple());
         192  +
    }
         193  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/serde.rs

@@ -0,1 +0,421 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! Serialization and deserialization interfaces for the Smithy data model.
           7  +
           8  +
mod deserializer;
           9  +
mod serializer;
          10  +
          11  +
pub use deserializer::ShapeDeserializer;
          12  +
pub use serializer::{SerializableStruct, ShapeSerializer};
          13  +
          14  +
#[cfg(test)]
          15  +
mod test {
          16  +
    use crate::serde::{ShapeDeserializer, ShapeSerializer};
          17  +
    use crate::{prelude::*, Schema};
          18  +
    use std::fmt;
          19  +
          20  +
    // Mock error type for testing
          21  +
    #[derive(Debug)]
          22  +
    struct MockError(String);
          23  +
          24  +
    impl fmt::Display for MockError {
          25  +
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
          26  +
            write!(f, "{}", self.0)
          27  +
        }
          28  +
    }
          29  +
          30  +
    impl std::error::Error for MockError {}
          31  +
          32  +
    // Mock serializer for testing
          33  +
    struct MockSerializer {
          34  +
        output: Vec<String>,
          35  +
    }
          36  +
          37  +
    impl ShapeSerializer for MockSerializer {
          38  +
        type Output = Vec<String>;
          39  +
        type Error = MockError;
          40  +
          41  +
        fn finish(self) -> Result<Self::Output, Self::Error> {
          42  +
            Ok(self.output)
          43  +
        }
          44  +
          45  +
        fn write_struct<F>(
          46  +
            &mut self,
          47  +
            schema: &dyn Schema,
          48  +
            write_members: F,
          49  +
        ) -> Result<(), Self::Error>
          50  +
        where
          51  +
            F: FnOnce(&mut Self) -> Result<(), Self::Error>,
          52  +
        {
          53  +
            self.output
          54  +
                .push(format!("struct({})", schema.shape_id().as_str()));
          55  +
            write_members(self)?;
          56  +
            self.output.push("end_struct".to_string());
          57  +
            Ok(())
          58  +
        }
          59  +
          60  +
        fn write_list<F>(
          61  +
            &mut self,
          62  +
            schema: &dyn Schema,
          63  +
            write_elements: F,
          64  +
        ) -> Result<(), Self::Error>
          65  +
        where
          66  +
            F: FnOnce(&mut Self) -> Result<(), Self::Error>,
          67  +
        {
          68  +
            self.output
          69  +
                .push(format!("list({})", schema.shape_id().as_str()));
          70  +
            write_elements(self)?;
          71  +
            self.output.push("end_list".to_string());
          72  +
            Ok(())
          73  +
        }
          74  +
          75  +
        fn write_map<F>(&mut self, schema: &dyn Schema, write_entries: F) -> Result<(), Self::Error>
          76  +
        where
          77  +
            F: FnOnce(&mut Self) -> Result<(), Self::Error>,
          78  +
        {
          79  +
            self.output
          80  +
                .push(format!("map({})", schema.shape_id().as_str()));
          81  +
            write_entries(self)?;
          82  +
            self.output.push("end_map".to_string());
          83  +
            Ok(())
          84  +
        }
          85  +
          86  +
        fn write_boolean(&mut self, _schema: &dyn Schema, value: bool) -> Result<(), Self::Error> {
          87  +
            self.output.push(format!("bool({})", value));
          88  +
            Ok(())
          89  +
        }
          90  +
          91  +
        fn write_byte(&mut self, _schema: &dyn Schema, value: i8) -> Result<(), Self::Error> {
          92  +
            self.output.push(format!("byte({})", value));
          93  +
            Ok(())
          94  +
        }
          95  +
          96  +
        fn write_short(&mut self, _schema: &dyn Schema, value: i16) -> Result<(), Self::Error> {
          97  +
            self.output.push(format!("short({})", value));
          98  +
            Ok(())
          99  +
        }
         100  +
         101  +
        fn write_integer(&mut self, _schema: &dyn Schema, value: i32) -> Result<(), Self::Error> {
         102  +
            self.output.push(format!("int({})", value));
         103  +
            Ok(())
         104  +
        }
         105  +
         106  +
        fn write_long(&mut self, _schema: &dyn Schema, value: i64) -> Result<(), Self::Error> {
         107  +
            self.output.push(format!("long({})", value));
         108  +
            Ok(())
         109  +
        }
         110  +
         111  +
        fn write_float(&mut self, _schema: &dyn Schema, value: f32) -> Result<(), Self::Error> {
         112  +
            self.output.push(format!("float({})", value));
         113  +
            Ok(())
         114  +
        }
         115  +
         116  +
        fn write_double(&mut self, _schema: &dyn Schema, value: f64) -> Result<(), Self::Error> {
         117  +
            self.output.push(format!("double({})", value));
         118  +
            Ok(())
         119  +
        }
         120  +
         121  +
        fn write_big_integer(
         122  +
            &mut self,
         123  +
            _schema: &dyn Schema,
         124  +
            value: &aws_smithy_types::BigInteger,
         125  +
        ) -> Result<(), Self::Error> {
         126  +
            self.output.push(format!("bigint({})", value.as_ref()));
         127  +
            Ok(())
         128  +
        }
         129  +
         130  +
        fn write_big_decimal(
         131  +
            &mut self,
         132  +
            _schema: &dyn Schema,
         133  +
            value: &aws_smithy_types::BigDecimal,
         134  +
        ) -> Result<(), Self::Error> {
         135  +
            self.output.push(format!("bigdec({})", value.as_ref()));
         136  +
            Ok(())
         137  +
        }
         138  +
         139  +
        fn write_string(&mut self, _schema: &dyn Schema, value: &str) -> Result<(), Self::Error> {
         140  +
            self.output.push(format!("string({})", value));
         141  +
            Ok(())
         142  +
        }
         143  +
         144  +
        fn write_blob(
         145  +
            &mut self,
         146  +
            _schema: &dyn Schema,
         147  +
            value: &aws_smithy_types::Blob,
         148  +
        ) -> Result<(), Self::Error> {
         149  +
            self.output
         150  +
                .push(format!("blob({} bytes)", value.as_ref().len()));
         151  +
            Ok(())
         152  +
        }
         153  +
         154  +
        fn write_timestamp(
         155  +
            &mut self,
         156  +
            _schema: &dyn Schema,
         157  +
            value: &aws_smithy_types::DateTime,
         158  +
        ) -> Result<(), Self::Error> {
         159  +
            self.output.push(format!("timestamp({})", value));
         160  +
            Ok(())
         161  +
        }
         162  +
         163  +
        fn write_document(
         164  +
            &mut self,
         165  +
            _schema: &dyn Schema,
         166  +
            _value: &aws_smithy_types::Document,
         167  +
        ) -> Result<(), Self::Error> {
         168  +
            self.output.push("document".to_string());
         169  +
            Ok(())
         170  +
        }
         171  +
         172  +
        fn write_null(&mut self, _schema: &dyn Schema) -> Result<(), Self::Error> {
         173  +
            self.output.push("null".to_string());
         174  +
            Ok(())
         175  +
        }
         176  +
    }
         177  +
         178  +
    // Mock deserializer for testing
         179  +
    struct MockDeserializer {
         180  +
        values: Vec<String>,
         181  +
        index: usize,
         182  +
    }
         183  +
         184  +
    impl MockDeserializer {
         185  +
        fn new(values: Vec<String>) -> Self {
         186  +
            Self { values, index: 0 }
         187  +
        }
         188  +
    }
         189  +
         190  +
    impl ShapeDeserializer for MockDeserializer {
         191  +
        type Error = MockError;
         192  +
         193  +
        fn read_struct<T, F>(
         194  +
            &mut self,
         195  +
            _schema: &dyn Schema,
         196  +
            state: T,
         197  +
            mut consumer: F,
         198  +
        ) -> Result<T, Self::Error>
         199  +
        where
         200  +
            F: FnMut(T, &dyn Schema, &mut Self) -> Result<T, Self::Error>,
         201  +
        {
         202  +
            // Simulate reading 2 members
         203  +
            let state = consumer(state, &STRING, self)?;
         204  +
            let state = consumer(state, &INTEGER, self)?;
         205  +
            Ok(state)
         206  +
        }
         207  +
         208  +
        fn read_list<T, F>(
         209  +
            &mut self,
         210  +
            _schema: &dyn Schema,
         211  +
            mut state: T,
         212  +
            mut consumer: F,
         213  +
        ) -> Result<T, Self::Error>
         214  +
        where
         215  +
            F: FnMut(T, &mut Self) -> Result<T, Self::Error>,
         216  +
        {
         217  +
            // Simulate reading 3 elements
         218  +
            for _ in 0..3 {
         219  +
                state = consumer(state, self)?;
         220  +
            }
         221  +
            Ok(state)
         222  +
        }
         223  +
         224  +
        fn read_map<T, F>(
         225  +
            &mut self,
         226  +
            _schema: &dyn Schema,
         227  +
            mut state: T,
         228  +
            mut consumer: F,
         229  +
        ) -> Result<T, Self::Error>
         230  +
        where
         231  +
            F: FnMut(T, String, &mut Self) -> Result<T, Self::Error>,
         232  +
        {
         233  +
            // Simulate reading 2 entries
         234  +
            state = consumer(state, "key1".to_string(), self)?;
         235  +
            state = consumer(state, "key2".to_string(), self)?;
         236  +
            Ok(state)
         237  +
        }
         238  +
         239  +
        fn read_boolean(&mut self, _schema: &dyn Schema) -> Result<bool, Self::Error> {
         240  +
            Ok(true)
         241  +
        }
         242  +
         243  +
        fn read_byte(&mut self, _schema: &dyn Schema) -> Result<i8, Self::Error> {
         244  +
            Ok(42)
         245  +
        }
         246  +
         247  +
        fn read_short(&mut self, _schema: &dyn Schema) -> Result<i16, Self::Error> {
         248  +
            Ok(1000)
         249  +
        }
         250  +
         251  +
        fn read_integer(&mut self, _schema: &dyn Schema) -> Result<i32, Self::Error> {
         252  +
            Ok(123456)
         253  +
        }
         254  +
         255  +
        fn read_long(&mut self, _schema: &dyn Schema) -> Result<i64, Self::Error> {
         256  +
            Ok(9876543210)
         257  +
        }
         258  +
         259  +
        fn read_float(&mut self, _schema: &dyn Schema) -> Result<f32, Self::Error> {
         260  +
            Ok(3.14)
         261  +
        }
         262  +
         263  +
        fn read_double(&mut self, _schema: &dyn Schema) -> Result<f64, Self::Error> {
         264  +
            Ok(2.71828)
         265  +
        }
         266  +
         267  +
        fn read_big_integer(
         268  +
            &mut self,
         269  +
            _schema: &dyn Schema,
         270  +
        ) -> Result<aws_smithy_types::BigInteger, Self::Error> {
         271  +
            use std::str::FromStr;
         272  +
            Ok(aws_smithy_types::BigInteger::from_str("12345").unwrap())
         273  +
        }
         274  +
         275  +
        fn read_big_decimal(
         276  +
            &mut self,
         277  +
            _schema: &dyn Schema,
         278  +
        ) -> Result<aws_smithy_types::BigDecimal, Self::Error> {
         279  +
            use std::str::FromStr;
         280  +
            Ok(aws_smithy_types::BigDecimal::from_str("123.45").unwrap())
         281  +
        }
         282  +
         283  +
        fn read_string(&mut self, _schema: &dyn Schema) -> Result<String, Self::Error> {
         284  +
            if self.index < self.values.len() {
         285  +
                let value = self.values[self.index].clone();
         286  +
                self.index += 1;
         287  +
                Ok(value)
         288  +
            } else {
         289  +
                Ok("default".to_string())
         290  +
            }
         291  +
        }
         292  +
         293  +
        fn read_blob(
         294  +
            &mut self,
         295  +
            _schema: &dyn Schema,
         296  +
        ) -> Result<aws_smithy_types::Blob, Self::Error> {
         297  +
            Ok(aws_smithy_types::Blob::new(vec![1, 2, 3, 4]))
         298  +
        }
         299  +
         300  +
        fn read_timestamp(
         301  +
            &mut self,
         302  +
            _schema: &dyn Schema,
         303  +
        ) -> Result<aws_smithy_types::DateTime, Self::Error> {
         304  +
            Ok(aws_smithy_types::DateTime::from_secs(1234567890))
         305  +
        }
         306  +
         307  +
        fn read_document(
         308  +
            &mut self,
         309  +
            _schema: &dyn Schema,
         310  +
        ) -> Result<aws_smithy_types::Document, Self::Error> {
         311  +
            Ok(aws_smithy_types::Document::Null)
         312  +
        }
         313  +
         314  +
        fn is_null(&self) -> bool {
         315  +
            false
         316  +
        }
         317  +
         318  +
        fn container_size(&self) -> Option<usize> {
         319  +
            Some(10)
         320  +
        }
         321  +
    }
         322  +
         323  +
    #[test]
         324  +
    fn test_serializer_simple_types() {
         325  +
        let mut ser = MockSerializer { output: Vec::new() };
         326  +
         327  +
        ser.write_boolean(&BOOLEAN, true).unwrap();
         328  +
        ser.write_integer(&INTEGER, 42).unwrap();
         329  +
        ser.write_string(&STRING, "hello").unwrap();
         330  +
         331  +
        let output = ser.finish().unwrap();
         332  +
        assert_eq!(output, vec!["bool(true)", "int(42)", "string(hello)"]);
         333  +
    }
         334  +
         335  +
    #[test]
         336  +
    fn test_serializer_struct() {
         337  +
        let mut ser = MockSerializer { output: Vec::new() };
         338  +
         339  +
        ser.write_struct(&STRING, |s| {
         340  +
            s.write_string(&STRING, "field1")?;
         341  +
            s.write_integer(&INTEGER, 123)?;
         342  +
            Ok(())
         343  +
        })
         344  +
        .unwrap();
         345  +
         346  +
        let output = ser.finish().unwrap();
         347  +
        assert_eq!(
         348  +
            output,
         349  +
            vec![
         350  +
                "struct(smithy.api#String)",
         351  +
                "string(field1)",
         352  +
                "int(123)",
         353  +
                "end_struct"
         354  +
            ]
         355  +
        );
         356  +
    }
         357  +
         358  +
    #[test]
         359  +
    fn test_deserializer_simple_types() {
         360  +
        let mut deser = MockDeserializer::new(vec!["test".to_string()]);
         361  +
         362  +
        assert_eq!(deser.read_boolean(&BOOLEAN).unwrap(), true);
         363  +
        assert_eq!(deser.read_integer(&INTEGER).unwrap(), 123456);
         364  +
        assert_eq!(deser.read_string(&STRING).unwrap(), "test");
         365  +
        assert_eq!(deser.container_size(), Some(10));
         366  +
        assert!(!deser.is_null());
         367  +
    }
         368  +
         369  +
    #[test]
         370  +
    fn test_deserializer_struct() {
         371  +
        let mut deser = MockDeserializer::new(vec!["value1".to_string(), "value2".to_string()]);
         372  +
         373  +
        let mut fields = Vec::new();
         374  +
        deser
         375  +
            .read_struct(&STRING, &mut fields, |fields, _member, d| {
         376  +
                fields.push(d.read_string(&STRING)?);
         377  +
                Ok(fields)
         378  +
            })
         379  +
            .unwrap();
         380  +
         381  +
        assert_eq!(fields, vec!["value1", "value2"]);
         382  +
    }
         383  +
         384  +
    #[test]
         385  +
    fn test_deserializer_list() {
         386  +
        let mut deser =
         387  +
            MockDeserializer::new(vec!["a".to_string(), "b".to_string(), "c".to_string()]);
         388  +
         389  +
        let mut elements = Vec::new();
         390  +
        deser
         391  +
            .read_list(&STRING, &mut elements, |elements, d| {
         392  +
                elements.push(d.read_string(&STRING)?);
         393  +
                Ok(elements)
         394  +
            })
         395  +
            .unwrap();
         396  +
         397  +
        assert_eq!(elements, vec!["a", "b", "c"]);
         398  +
    }
         399  +
         400  +
    #[test]
         401  +
    fn test_deserializer_map() {
         402  +
        let mut deser = MockDeserializer::new(vec!["val1".to_string(), "val2".to_string()]);
         403  +
         404  +
        let mut entries = Vec::new();
         405  +
        deser
         406  +
            .read_map(&STRING, &mut entries, |entries, key, d| {
         407  +
                let value = d.read_string(&STRING)?;
         408  +
                entries.push((key, value));
         409  +
                Ok(entries)
         410  +
            })
         411  +
            .unwrap();
         412  +
         413  +
        assert_eq!(
         414  +
            entries,
         415  +
            vec![
         416  +
                ("key1".to_string(), "val1".to_string()),
         417  +
                ("key2".to_string(), "val2".to_string())
         418  +
            ]
         419  +
        );
         420  +
    }
         421  +
}