tako_rs_core/route/
openapi.rs1#![cfg(any(feature = "utoipa", feature = "vespera"))]
10
11use super::Route;
12use crate::openapi::RouteOpenApi;
13
14impl Route {
15 #[cfg(any(feature = "utoipa", feature = "vespera"))]
24 #[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
25 pub fn operation_id(&self, id: impl Into<String>) -> &Self {
26 let mut guard = self.openapi.write();
27 let openapi = guard.get_or_insert_with(RouteOpenApi::default);
28 openapi.operation_id = Some(id.into());
29 self
30 }
31
32 #[cfg(any(feature = "utoipa", feature = "vespera"))]
41 #[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
42 pub fn summary(&self, summary: impl Into<String>) -> &Self {
43 let mut guard = self.openapi.write();
44 let openapi = guard.get_or_insert_with(RouteOpenApi::default);
45 openapi.summary = Some(summary.into());
46 self
47 }
48
49 #[cfg(any(feature = "utoipa", feature = "vespera"))]
58 #[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
59 pub fn description(&self, description: impl Into<String>) -> &Self {
60 let mut guard = self.openapi.write();
61 let openapi = guard.get_or_insert_with(RouteOpenApi::default);
62 openapi.description = Some(description.into());
63 self
64 }
65
66 #[cfg(any(feature = "utoipa", feature = "vespera"))]
76 #[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
77 pub fn tag(&self, tag: impl Into<String>) -> &Self {
78 let mut guard = self.openapi.write();
79 let openapi = guard.get_or_insert_with(RouteOpenApi::default);
80 openapi.tags.push(tag.into());
81 self
82 }
83
84 #[cfg(any(feature = "utoipa", feature = "vespera"))]
93 #[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
94 pub fn deprecated(&self) -> &Self {
95 let mut guard = self.openapi.write();
96 let openapi = guard.get_or_insert_with(RouteOpenApi::default);
97 openapi.deprecated = true;
98 self
99 }
100
101 #[cfg(any(feature = "utoipa", feature = "vespera"))]
111 #[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
112 pub fn response(&self, status: u16, description: impl Into<String>) -> &Self {
113 let mut guard = self.openapi.write();
114 let openapi = guard.get_or_insert_with(RouteOpenApi::default);
115 openapi.responses.insert(status, description.into());
116 self
117 }
118
119 #[cfg(any(feature = "utoipa", feature = "vespera"))]
135 #[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
136 pub fn parameter(&self, param: crate::openapi::OpenApiParameter) -> &Self {
137 let mut guard = self.openapi.write();
138 let openapi = guard.get_or_insert_with(RouteOpenApi::default);
139 openapi.parameters.push(param);
140 self
141 }
142
143 #[cfg(any(feature = "utoipa", feature = "vespera"))]
158 #[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
159 pub fn request_body(&self, body: crate::openapi::OpenApiRequestBody) -> &Self {
160 let mut guard = self.openapi.write();
161 let openapi = guard.get_or_insert_with(RouteOpenApi::default);
162 openapi.request_body = Some(body);
163 self
164 }
165
166 #[cfg(any(feature = "utoipa", feature = "vespera"))]
175 #[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
176 pub fn security(&self, requirement: impl Into<String>) -> &Self {
177 let mut guard = self.openapi.write();
178 let openapi = guard.get_or_insert_with(RouteOpenApi::default);
179 openapi.security.push(requirement.into());
180 self
181 }
182
183 #[cfg(any(feature = "utoipa", feature = "vespera"))]
185 #[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
186 pub fn openapi_metadata(&self) -> Option<RouteOpenApi> {
187 self.openapi.read().clone()
188 }
189}