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 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//! ## Web Framework Examples
12//!
13//! - [Axum](https://github.com/kimolalekan/openapi-ui/blob/main/examples/axum.rs)
14//! - [Actix-web](https://github.com/kimolalekan/openapi-ui/blob/main/examples/actix.rs)
15//! - [Rocket](https://github.com/kimolalekan/openapi-ui/blob/main/examples/rocket.rs)
16//! - [Warp](https://github.com/kimolalekan/openapi-ui/blob/main/examples/warp.rs)
17//! - [Poem](https://github.com/kimolalekan/openapi-ui/blob/main/examples/poem.rs)
18//! - [Salvo](https://github.com/kimolalekan/openapi-ui/blob/main/examples/salvo.rs)
19//!
20//! ## Usage
21//!
22//! ```rust
23//! use openapi_ui::{generate_docs, ThemeMode};
24//!
25//! fn main() -> Result<(), Box<dyn std::error::Error>> {
26//!     let openapi_json = r#"{"openapi": "3.0.0", "info": {"title": "API", "version": "1.0.0"}, "paths": {}}"#;
27//!     
28//!     // Generate HTML with system theme and default favicon
29//!     let html = generate_docs(openapi_json, ThemeMode::System, None, None)?;
30//!     
31//!     std::fs::write("docs.html", html)?;
32//!     Ok(())
33//! }
34//! ```
35//!
36//! For more control, use the [`UIBuilder`]:
37//!
38//! ```rust
39//! use openapi_ui::{UIBuilder, OpenAPISpec};
40//!
41//! # fn run(spec: OpenAPISpec) -> Result<(), Box<dyn std::error::Error>> {
42//! let html = UIBuilder::new(spec)
43//!     .theme("dark")
44//!     .build();
45//! # Ok(())
46//! # }
47//! ```
48
49pub mod error;
50pub mod openapi;
51pub mod template;
52pub mod theme;
53pub mod ui;
54
55pub use error::{Result, UIError};
56pub use openapi::{HttpScheme, OpenAPISpec, SchemaType};
57pub use theme::{ThemeMode, get_complete_theme_css, get_theme_css};
58pub use ui::{UIBuilder, UIConfig, generate_base_ui, generate_docs, generate_ui};