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