Skip to main content

aws_smithy_schema/schema/
prelude.rs

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
11use crate::{shape_id, Schema, ShapeType};
12
13/// Schema for `smithy.api#String`
14pub static STRING: Schema<'static> =
15    Schema::new(shape_id!("smithy.api", "String"), ShapeType::String);
16
17/// Schema for `smithy.api#Boolean`
18pub static BOOLEAN: Schema<'static> =
19    Schema::new(shape_id!("smithy.api", "Boolean"), ShapeType::Boolean);
20
21/// Schema for `smithy.api#Byte`
22pub static BYTE: Schema<'static> = Schema::new(shape_id!("smithy.api", "Byte"), ShapeType::Byte);
23
24/// Schema for `smithy.api#Short`
25pub static SHORT: Schema<'static> = Schema::new(shape_id!("smithy.api", "Short"), ShapeType::Short);
26
27/// Schema for `smithy.api#Integer`
28pub static INTEGER: Schema<'static> =
29    Schema::new(shape_id!("smithy.api", "Integer"), ShapeType::Integer);
30
31/// Schema for `smithy.api#Long`
32pub static LONG: Schema<'static> = Schema::new(shape_id!("smithy.api", "Long"), ShapeType::Long);
33
34/// Schema for `smithy.api#Float`
35pub static FLOAT: Schema<'static> = Schema::new(shape_id!("smithy.api", "Float"), ShapeType::Float);
36
37/// Schema for `smithy.api#Double`
38pub static DOUBLE: Schema<'static> =
39    Schema::new(shape_id!("smithy.api", "Double"), ShapeType::Double);
40
41/// Schema for `smithy.api#BigInteger`
42pub static BIG_INTEGER: Schema<'static> =
43    Schema::new(shape_id!("smithy.api", "BigInteger"), ShapeType::BigInteger);
44
45/// Schema for `smithy.api#BigDecimal`
46pub static BIG_DECIMAL: Schema<'static> =
47    Schema::new(shape_id!("smithy.api", "BigDecimal"), ShapeType::BigDecimal);
48
49/// Schema for `smithy.api#Blob`
50pub static BLOB: Schema<'static> = Schema::new(shape_id!("smithy.api", "Blob"), ShapeType::Blob);
51
52/// Schema for `smithy.api#Timestamp`
53pub static TIMESTAMP: Schema<'static> =
54    Schema::new(shape_id!("smithy.api", "Timestamp"), ShapeType::Timestamp);
55
56/// Schema for `smithy.api#Document`
57pub static DOCUMENT: Schema<'static> =
58    Schema::new(shape_id!("smithy.api", "Document"), ShapeType::Document);
59
60/// Schema for `smithy.api#Unit`, a structure with no members.
61pub static UNIT: Schema<'static> =
62    Schema::new_struct(shape_id!("smithy.api", "Unit"), ShapeType::Structure, &[]);
63
64#[cfg(test)]
65mod tests {
66    use super::*;
67
68    #[test]
69    fn test_string_schema() {
70        assert_eq!(STRING.shape_id().as_str(), "smithy.api#String");
71        assert_eq!(STRING.shape_type(), ShapeType::String);
72        assert!(STRING.is_string());
73        assert!(STRING.traits().is_none());
74    }
75
76    #[test]
77    fn test_boolean_schema() {
78        assert_eq!(BOOLEAN.shape_id().as_str(), "smithy.api#Boolean");
79        assert_eq!(BOOLEAN.shape_type(), ShapeType::Boolean);
80        assert!(BOOLEAN.traits().is_none());
81    }
82
83    #[test]
84    fn test_numeric_schemas() {
85        assert_eq!(BYTE.shape_type(), ShapeType::Byte);
86        assert_eq!(SHORT.shape_type(), ShapeType::Short);
87        assert_eq!(INTEGER.shape_type(), ShapeType::Integer);
88        assert_eq!(LONG.shape_type(), ShapeType::Long);
89        assert_eq!(FLOAT.shape_type(), ShapeType::Float);
90        assert_eq!(DOUBLE.shape_type(), ShapeType::Double);
91        assert_eq!(BIG_INTEGER.shape_type(), ShapeType::BigInteger);
92        assert_eq!(BIG_DECIMAL.shape_type(), ShapeType::BigDecimal);
93    }
94
95    #[test]
96    fn test_blob_schema() {
97        assert_eq!(BLOB.shape_id().as_str(), "smithy.api#Blob");
98        assert_eq!(BLOB.shape_type(), ShapeType::Blob);
99        assert!(BLOB.is_blob());
100    }
101
102    #[test]
103    fn test_timestamp_schema() {
104        assert_eq!(TIMESTAMP.shape_id().as_str(), "smithy.api#Timestamp");
105        assert_eq!(TIMESTAMP.shape_type(), ShapeType::Timestamp);
106    }
107
108    #[test]
109    fn test_document_schema() {
110        assert_eq!(DOCUMENT.shape_id().as_str(), "smithy.api#Document");
111        assert_eq!(DOCUMENT.shape_type(), ShapeType::Document);
112    }
113
114    #[test]
115    fn test_all_prelude_types_are_simple() {
116        assert!(STRING.shape_type().is_simple());
117        assert!(BOOLEAN.shape_type().is_simple());
118        assert!(BYTE.shape_type().is_simple());
119        assert!(SHORT.shape_type().is_simple());
120        assert!(INTEGER.shape_type().is_simple());
121        assert!(LONG.shape_type().is_simple());
122        assert!(FLOAT.shape_type().is_simple());
123        assert!(DOUBLE.shape_type().is_simple());
124        assert!(BIG_INTEGER.shape_type().is_simple());
125        assert!(BIG_DECIMAL.shape_type().is_simple());
126        assert!(BLOB.shape_type().is_simple());
127        assert!(TIMESTAMP.shape_type().is_simple());
128        assert!(DOCUMENT.shape_type().is_simple());
129    }
130}