pub mod doc;
#[cfg(feature = "swagger-ui-embedded")]
pub mod embedded;
pub use silent_openapi_macros::endpoint;
pub mod error;
pub mod handler;
pub mod middleware;
pub mod redoc;
pub mod route;
pub mod schema;
pub mod ui_html;
pub use error::{OpenApiError, Result};
pub use handler::SwaggerUiHandler;
pub use middleware::SwaggerUiMiddleware;
pub use redoc::{ReDocHandler, ReDocMiddleware};
pub use route::{DocumentedRoute, RouteDocumentation, RouteOpenApiExt};
pub use schema::OpenApiDoc;
pub use utoipa::{
IntoParams, IntoResponses, ToResponse, ToSchema,
openapi::{self, OpenApi},
};
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
#[derive(Clone)]
pub struct SwaggerUiOptions {
pub try_it_out_enabled: bool,
}
impl Default for SwaggerUiOptions {
fn default() -> Self {
Self {
try_it_out_enabled: true,
}
}
}
pub fn create_openapi_doc(
title: &str,
version: &str,
description: &str,
) -> utoipa::openapi::OpenApi {
use utoipa::openapi::*;
OpenApiBuilder::new()
.info(
InfoBuilder::new()
.title(title)
.version(version)
.description(Some(description))
.build(),
)
.build()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_version() {
#[allow(clippy::const_is_empty)]
{
assert!(!VERSION.is_empty());
}
}
#[test]
fn test_create_openapi_doc() {
let doc = create_openapi_doc("Test API", "1.0.0", "A test API");
assert_eq!(doc.info.title, "Test API");
assert_eq!(doc.info.version, "1.0.0");
assert_eq!(doc.info.description, Some("A test API".to_string()));
}
}