Skip to main content

openapi_ui/
lib.rs

1//! # openapi-ui
2//!
3//! [![Crates.io](https://img.shields.io/crates/v/openapi-ui.svg)](https://crates.io/crates/openapi-ui)
4//! [![Documentation](https://docs.rs/openapi-ui/badge.svg)](https://docs.rs/openapi-ui)
5//! [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6//!
7//! `openapi-ui` is a library for generating custom documentation UIs from OpenAPI specifications.
8//!
9//! It takes an OpenAPI JSON string and produces a self-contained HTML file with a responsive UI.
10//! 
11//! **[🌐 Live Demo](https://kimolalekan.github.io/openapi-ui)**
12//!
13//! ## Web Framework Examples
14//!
15//! - [Axum](https://github.com/kimolalekan/openapi-ui/blob/main/examples/axum.rs)
16//! - [Actix-web](https://github.com/kimolalekan/openapi-ui/blob/main/examples/actix.rs)
17//! - [Rocket](https://github.com/kimolalekan/openapi-ui/blob/main/examples/rocket.rs)
18//! - [Warp](https://github.com/kimolalekan/openapi-ui/blob/main/examples/warp.rs)
19//! - [Poem](https://github.com/kimolalekan/openapi-ui/blob/main/examples/poem.rs)
20//! - [Salvo](https://github.com/kimolalekan/openapi-ui/blob/main/examples/salvo.rs)
21//!
22//! ## Generating OpenAPI JSON with utoipa
23//!
24//! The OpenAPI JSON can be generated using [utoipa](https://crates.io/crates/utoipa):
25//!
26//! ```rust,ignore
27//! use utoipa::OpenApi;
28//! use openapi_ui::{generate_docs, ThemeMode};
29//!
30//! #[derive(OpenApi)]
31//! #[openapi(paths(get_users), components(schemas(User)))]
32//! struct ApiDoc;
33//!
34//! let openapi_json = ApiDoc::openapi().to_pretty_json().unwrap();
35//! let html = generate_docs(&openapi_json, ThemeMode::System, None, None).unwrap();
36//! ```
37//!
38//! ## Usage
39//!
40//! ```rust
41//! use openapi_ui::{generate_docs, ThemeMode};
42//!
43//! fn main() -> Result<(), Box<dyn std::error::Error>> {
44//!     let openapi_json = r#"{"openapi": "3.0.0", "info": {"title": "API", "version": "1.0.0"}, "paths": {}}"#;
45//!     
46//!     // Generate HTML with system theme and default favicon
47//!     let html = generate_docs(openapi_json, ThemeMode::System, None, None)?;
48//!     
49//!     std::fs::write("docs.html", html)?;
50//!     Ok(())
51//! }
52//! ```
53//!
54//! For more control, use the [`UIBuilder`]:
55//!
56//! ```rust
57//! use openapi_ui::{UIBuilder, OpenAPISpec};
58//!
59//! # fn run(spec: OpenAPISpec) -> Result<(), Box<dyn std::error::Error>> {
60//! let html = UIBuilder::new(spec)
61//!     .theme("dark")
62//!     .build();
63//! # Ok(())
64//! # }
65//! ```
66
67pub mod error;
68pub mod openapi;
69pub mod template;
70pub mod theme;
71pub mod ui;
72
73pub use error::{Result, UIError};
74pub use openapi::{HttpScheme, OpenAPISpec, SchemaType};
75pub use theme::{ThemeMode, get_complete_theme_css, get_theme_css};
76pub use ui::{UIBuilder, UIConfig, generate_base_ui, generate_docs, generate_ui};