#![cfg(any(feature = "utoipa", feature = "vespera"))]
use super::Route;
use crate::openapi::RouteOpenApi;
impl Route {
#[cfg(any(feature = "utoipa", feature = "vespera"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
pub fn operation_id(&self, id: impl Into<String>) -> &Self {
let mut guard = self.openapi.write();
let openapi = guard.get_or_insert_with(RouteOpenApi::default);
openapi.operation_id = Some(id.into());
self
}
#[cfg(any(feature = "utoipa", feature = "vespera"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
pub fn summary(&self, summary: impl Into<String>) -> &Self {
let mut guard = self.openapi.write();
let openapi = guard.get_or_insert_with(RouteOpenApi::default);
openapi.summary = Some(summary.into());
self
}
#[cfg(any(feature = "utoipa", feature = "vespera"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
pub fn description(&self, description: impl Into<String>) -> &Self {
let mut guard = self.openapi.write();
let openapi = guard.get_or_insert_with(RouteOpenApi::default);
openapi.description = Some(description.into());
self
}
#[cfg(any(feature = "utoipa", feature = "vespera"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
pub fn tag(&self, tag: impl Into<String>) -> &Self {
let mut guard = self.openapi.write();
let openapi = guard.get_or_insert_with(RouteOpenApi::default);
openapi.tags.push(tag.into());
self
}
#[cfg(any(feature = "utoipa", feature = "vespera"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
pub fn deprecated(&self) -> &Self {
let mut guard = self.openapi.write();
let openapi = guard.get_or_insert_with(RouteOpenApi::default);
openapi.deprecated = true;
self
}
#[cfg(any(feature = "utoipa", feature = "vespera"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
pub fn response(&self, status: u16, description: impl Into<String>) -> &Self {
let mut guard = self.openapi.write();
let openapi = guard.get_or_insert_with(RouteOpenApi::default);
openapi.responses.insert(status, description.into());
self
}
#[cfg(any(feature = "utoipa", feature = "vespera"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
pub fn parameter(&self, param: crate::openapi::OpenApiParameter) -> &Self {
let mut guard = self.openapi.write();
let openapi = guard.get_or_insert_with(RouteOpenApi::default);
openapi.parameters.push(param);
self
}
#[cfg(any(feature = "utoipa", feature = "vespera"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
pub fn request_body(&self, body: crate::openapi::OpenApiRequestBody) -> &Self {
let mut guard = self.openapi.write();
let openapi = guard.get_or_insert_with(RouteOpenApi::default);
openapi.request_body = Some(body);
self
}
#[cfg(any(feature = "utoipa", feature = "vespera"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
pub fn security(&self, requirement: impl Into<String>) -> &Self {
let mut guard = self.openapi.write();
let openapi = guard.get_or_insert_with(RouteOpenApi::default);
openapi.security.push(requirement.into());
self
}
#[cfg(any(feature = "utoipa", feature = "vespera"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "utoipa", feature = "vespera"))))]
pub fn openapi_metadata(&self) -> Option<RouteOpenApi> {
self.openapi.read().clone()
}
}