use std::borrow::Cow;
use topcoat_router::Router;
use crate::{Document, SecurityScheme, generate::generate};
#[derive(Debug, Clone)]
pub struct OpenApi {
pub(crate) title: Cow<'static, str>,
pub(crate) version: Cow<'static, str>,
pub(crate) description: Option<Cow<'static, str>>,
pub(crate) servers: Vec<Cow<'static, str>>,
pub(crate) tags: Vec<(Cow<'static, str>, Cow<'static, str>)>,
pub(crate) security_schemes: Vec<(Cow<'static, str>, SecurityScheme)>,
}
impl OpenApi {
#[must_use]
pub fn new(title: impl Into<Cow<'static, str>>, version: impl Into<Cow<'static, str>>) -> Self {
Self {
title: title.into(),
version: version.into(),
description: None,
servers: Vec::new(),
tags: Vec::new(),
security_schemes: Vec::new(),
}
}
#[must_use]
pub fn description(mut self, description: impl Into<Cow<'static, str>>) -> Self {
self.description = Some(description.into());
self
}
#[must_use]
pub fn server(mut self, url: impl Into<Cow<'static, str>>) -> Self {
self.servers.push(url.into());
self
}
#[must_use]
pub fn tag(
mut self,
name: impl Into<Cow<'static, str>>,
description: impl Into<Cow<'static, str>>,
) -> Self {
self.tags.push((name.into(), description.into()));
self
}
#[must_use]
pub fn security_scheme(
mut self,
name: impl Into<Cow<'static, str>>,
scheme: SecurityScheme,
) -> Self {
self.security_schemes.push((name.into(), scheme));
self
}
#[must_use]
pub fn generate(&self, router: &Router) -> Document {
generate(self, router)
}
}