use crate::APIRouter;
#[derive(Debug)]
pub struct APIApp<S = ()>
where
S: Clone + Send + Sync + 'static,
{
pub(crate) title: Option<String>,
pub(crate) summary: Option<String>,
pub(crate) description: Option<String>,
pub(crate) version: String,
pub(crate) openapi_path: String,
pub(crate) docs_path: String,
pub(crate) state: S,
pub(crate) host: Option<String>,
pub(crate) port: Option<i32>,
pub(crate) routers: Vec<APIRouter<S>>,
}
impl Default for APIApp<()> {
fn default() -> Self {
Self {
title: None,
summary: None,
description: None,
version: "0.0.1".to_owned(),
openapi_path: "/openapi.json".to_owned(),
docs_path: "/docs".to_owned(),
state: (),
host: None,
port: None,
routers: vec![],
}
}
}
impl APIApp<()> {
pub fn new() -> Self {
Self::default()
}
}
impl<S> APIApp<S>
where
S: Clone + Send + Sync + 'static,
{
pub fn new_with_state(state: S) -> Self {
Self {
title: None,
summary: None,
description: None,
version: "0.0.1".to_owned(),
openapi_path: "/openapi.json".to_owned(),
docs_path: "/docs".to_owned(),
state,
host: None,
port: None,
routers: vec![],
}
}
pub fn set_title(mut self, title: &str) -> Self {
self.title = Some(title.to_owned());
self
}
pub fn set_summary(mut self, summary: &str) -> Self {
self.summary = Some(summary.to_owned());
self
}
pub fn set_description(mut self, description: &str) -> Self {
self.description = Some(description.to_owned());
self
}
pub fn set_version(mut self, version: &str) -> Self {
self.version = version.to_owned();
self
}
pub fn set_openapi_path(mut self, openapi_path: &str) -> Self {
self.openapi_path = openapi_path.to_owned();
self
}
pub fn set_docs_path(mut self, docs_path: &str) -> Self {
self.docs_path = docs_path.to_owned();
self
}
pub fn set_host(mut self, host: &str) -> Self {
self.host = Some(host.to_owned());
self
}
pub fn set_port(mut self, port: i32) -> Self {
self.port = Some(port);
self
}
pub fn register_router(mut self, router: APIRouter<S>) -> Self {
self.routers.push(router);
self
}
}