use std::sync::Arc;
use std::sync::Mutex;
use openapiv3::OpenAPI;
use crate::internals::AccessSwaggapiPageBuilder;
use crate::internals::SwaggapiPageBuilderImpl;
pub trait SwaggapiPage: AccessSwaggapiPageBuilder {
fn openapi(&self) -> Arc<OpenAPI>;
}
impl<P: AccessSwaggapiPageBuilder> SwaggapiPage for P {
fn openapi(&self) -> Arc<OpenAPI> {
SwaggapiPageBuilderImpl::build(self.get_builder())
}
}
pub struct PageOfEverything;
impl AccessSwaggapiPageBuilder for PageOfEverything {
fn get_builder(&self) -> &'static SwaggapiPageBuilder {
static BUILDER: SwaggapiPageBuilder = SwaggapiPageBuilder::new();
&BUILDER
}
}
pub struct SwaggapiPageBuilder {
pub(crate) title: Option<&'static str>,
pub(crate) description: Option<&'static str>,
pub(crate) terms_of_service: Option<&'static str>,
pub(crate) contact_name: Option<&'static str>,
pub(crate) contact_url: Option<&'static str>,
pub(crate) contact_email: Option<&'static str>,
pub(crate) license_name: Option<&'static str>,
pub(crate) license_url: Option<&'static str>,
pub(crate) version: Option<&'static str>,
pub(crate) filename: Option<&'static str>,
pub(crate) state: Mutex<Option<SwaggapiPageBuilderImpl>>,
}
impl SwaggapiPageBuilder {
pub const fn new() -> Self {
Self {
title: None,
description: None,
terms_of_service: None,
contact_name: None,
contact_url: None,
contact_email: None,
license_name: None,
license_url: None,
version: None,
filename: None,
state: Mutex::new(None),
}
}
pub const fn title(mut self, title: &'static str) -> Self {
self.title = Some(title);
self
}
pub const fn description(mut self, description: &'static str) -> Self {
self.description = Some(description);
self
}
pub const fn terms_of_service(mut self, terms: &'static str) -> Self {
self.terms_of_service = Some(terms);
self
}
pub const fn contact_name(mut self, name: &'static str) -> Self {
self.contact_name = Some(name);
self
}
pub const fn contact_url(mut self, url: &'static str) -> Self {
self.contact_url = Some(url);
self
}
pub const fn contact_email(mut self, email: &'static str) -> Self {
self.contact_email = Some(email);
self
}
pub const fn license_name(mut self, name: &'static str) -> Self {
self.license_name = Some(name);
self
}
pub const fn license_url(mut self, url: &'static str) -> Self {
self.license_url = Some(url);
self
}
pub const fn filename(mut self, file: &'static str) -> Self {
self.filename = Some(file);
self
}
}