1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//! This crate gives static type information for primitives and commonly used types from
//! the standard library and other commonly used libraries (see [features](#features))
//! when the according feature is enabled. Please refer to the [`Cargo.toml`] for a list
//! of all available feature flags and optional dependencies. Also, it provides a derive
//! macro for structs and enums to gain access to their static type information at
//! runtime.
//!
//! The core of this crate is the [`OpenapiType`] trait. It has three static function,
//! where [`schema`](OpenapiType::schema), which returns an [`OpenapiSchema`], is the one
//! you are probably looking for. It assembles the static type information in a way that
//! is convenient to use for a generated OpenAPI specification, but can also be utilized
//! in other use cases as well.
//!
//! # Custom Types
//!
//! To gain access to the static type information of your custom types at runtime, the
//! easiest way is to use the derive macro:
//!
//! ```rust
//! # use openapi_type::OpenapiType;
//! #[derive(OpenapiType)]
//! struct FooBar {
//! foo: Option<String>,
//! bar: u64
//! }
//! #
//! # // Test that the OpenAPI schema is the one we display below
//! # let schema = FooBar::schema();
//! # let schema_yaml = serde_saphyr::to_string_with_options(
//! # &schema.schema,
//! # serde_saphyr::ser::options::SerializerOptions {
//! # compact_list_indent: false,
//! # ..Default::default()
//! # }).unwrap();
//! # pretty_assertions::assert_eq!(include_str!("lib.rs_schema.yml"), schema_yaml);
//! #
//! # // Test that the Path Params is the one we display below
//! # let path_params = FooBar::path_params();
//! # let path_params_yaml = serde_saphyr::to_string_with_options(
//! # &path_params.params,
//! # serde_saphyr::ser::options::SerializerOptions {
//! # compact_list_indent: false,
//! # ..Default::default()
//! # }).unwrap();
//! # pretty_assertions::assert_eq!(include_str!("lib.rs_path_params.yml"), path_params_yaml);
//! #
//! # // Test that the Query Params is the one we display below
//! # let query_params = FooBar::query_params();
//! # let query_params_yaml = serde_saphyr::to_string_with_options(
//! # &query_params.params,
//! # serde_saphyr::ser::options::SerializerOptions {
//! # compact_list_indent: false,
//! # ..Default::default()
//! # }).unwrap();
//! # pretty_assertions::assert_eq!(include_str!("lib.rs_query_params.yml"), query_params_yaml);
//! ```
//!
//! # OpenAPI specification
//!
//! Using above type, running `FooBar::schema().into_schema()` yields
//!
//! ```yaml
//! ```
//!
//! Note, however, that this is not sufficient for more complex types. If one of your
//! structs fields is a type that has a name (that is, `Type::schema().name` is not
//! `None`), above schema will contain a reference to that schema. Therefore, always
//! remember to put the [`dependencies`](OpenapiSchema::dependencies) into the
//! specification alongside the type you are interested in.
//!
//! ## Path Parameters
//!
//! We can also treat the `FooBar` struct from above as a struct containing path
//! parameters, if we construct an [`Operation`](oas3::spec::Operation) for a path like
//! `/foo/{foo}/bar/{bar}`. Running `FooBar::path_params()` yields
//! ```yaml
//! ```
//!
//! ## Query Parameters
//!
//! Likewise, we can treat the `FooBar` struct from above as a struct containing query
//! parameters. Running `FooBar::query_params()` yields
//! ```yaml
//! ```
//!
//! # Features
//!
//! The following cargo features may be enabled for this crate to unlock additional
//! implementations for larger tuples. For example, the `tuples32` feature would unlock
//! the implementation for tuples with sizes up to 32.
//!
//! - `tuples16` (enabled by default)
//! - `tuples32`
//! - `tuples48`
//! - `tuples64`
//!
//! The following cargo features may be enabled for this crate to unlock additional
//! implementations for external crates:
//!
//! - `chrono`: Enable all of the below:
//! - `chrono04`: Enable implementations for [`chrono` 0.4](chrono04)
//! - `hashbrown`: Enable all of the below:
//! - `hashbrown016`: Enable implementations for [`hashbrown` 0.16](hashbrown016)
//! - `hashbrown017`: Enable implementations for [`hashbrown` 0.17](hashbrown017)
//! - `jiff`: Enable all of the below:
//! - `jiff02`: Enable implementations for [`jiff` 0.2](jiff02)
//! - `linked-hash-map`: Enable all of the below:
//! - `linked-hash-map05`: Enable implementations for [`linked-hash-map` 0.5](linked_hash_map05)
//! - `time`: Enable all of the below:
//! - `time03`: Enable implementations for [`time` 0.3](time03)
//! - `url`: Enable all of the below:
//! - `url2`: Enable implementations for [`url` 2.x](url2)
//! - `uuid`: Enable all of the below:
//! - `uuid1`: Enable implementations for [`uuid` 1.x](uuid1)
//!
//! Note that support for [`indexmap` 2.x](indexmap) is enabled by default.
//!
//! [`Cargo.toml`]: https://docs.rs/crate/openapi_type/latest/source/Cargo.toml.orig
pub use ;
pub use ;
pub use ;
pub use OpenapiType;
/// This trait needs to be implemented by every type that is being used in the OpenAPI Spec. It gives
/// access to the [OpenapiSchema] of this type. It is provided for primitive types, String and the
/// like. For use on your own types, there is a derive macro:
///
/// ```
/// # #[macro_use] extern crate openapi_type_derive;
/// #
/// #[derive(OpenapiType)]
/// struct MyResponse {
/// message: String
/// }
/// ```