1pub trait OpenApiSchema {
10 fn openapi_schema() -> crate::specification::Schema;
12
13 fn schema_name() -> String;
15}
16
17impl OpenApiSchema for String {
22 fn openapi_schema() -> crate::specification::Schema {
23 crate::specification::Schema {
24 schema_type: Some("string".to_string()),
25 ..Default::default()
26 }
27 }
28
29 fn schema_name() -> String {
30 "String".to_string()
31 }
32}
33
34impl OpenApiSchema for i32 {
35 fn openapi_schema() -> crate::specification::Schema {
36 crate::specification::Schema {
37 schema_type: Some("integer".to_string()),
38 format: Some("int32".to_string()),
39 ..Default::default()
40 }
41 }
42
43 fn schema_name() -> String {
44 "i32".to_string()
45 }
46}
47
48impl OpenApiSchema for i64 {
49 fn openapi_schema() -> crate::specification::Schema {
50 crate::specification::Schema {
51 schema_type: Some("integer".to_string()),
52 format: Some("int64".to_string()),
53 ..Default::default()
54 }
55 }
56
57 fn schema_name() -> String {
58 "i64".to_string()
59 }
60}
61
62impl OpenApiSchema for bool {
63 fn openapi_schema() -> crate::specification::Schema {
64 crate::specification::Schema {
65 schema_type: Some("boolean".to_string()),
66 ..Default::default()
67 }
68 }
69
70 fn schema_name() -> String {
71 "bool".to_string()
72 }
73}
74
75impl<T: OpenApiSchema> OpenApiSchema for Option<T> {
76 fn openapi_schema() -> crate::specification::Schema {
77 let mut schema = T::openapi_schema();
78 schema.nullable = Some(true);
79 schema
80 }
81
82 fn schema_name() -> String {
83 format!("Option<{}>", T::schema_name())
84 }
85}
86
87impl<T: OpenApiSchema> OpenApiSchema for Vec<T> {
88 fn openapi_schema() -> crate::specification::Schema {
89 crate::specification::Schema {
90 schema_type: Some("array".to_string()),
91 items: Some(Box::new(T::openapi_schema())),
92 ..Default::default()
93 }
94 }
95
96 fn schema_name() -> String {
97 format!("Vec<{}>", T::schema_name())
98 }
99}