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//! ## Generating OpenAPI JSON with utoipa
21//!
22//! The OpenAPI JSON can be generated using [utoipa](https://crates.io/crates/utoipa):
23//!
24//! ```rust,ignore
25//! use utoipa::OpenApi;
26//! use openapi_ui::{generate_docs, ThemeMode};
27//!
28//! #[derive(OpenApi)]
29//! #[openapi(paths(get_users), components(schemas(User)))]
30//! struct ApiDoc;
31//!
32//! let openapi_json = ApiDoc::openapi().to_pretty_json().unwrap();
33//! let html = generate_docs(&openapi_json, ThemeMode::System, None, None).unwrap();
34//! ```
35//!
36//! ## Usage
37//!
38//! ```rust
39//! use openapi_ui::{generate_docs, ThemeMode};
40//!
41//! fn main() -> Result<(), Box<dyn std::error::Error>> {
42//!     let openapi_json = r#"{"openapi": "3.0.0", "info": {"title": "API", "version": "1.0.0"}, "paths": {}}"#;
43//!     
44//!     // Generate HTML with system theme and default favicon
45//!     let html = generate_docs(openapi_json, ThemeMode::System, None, None)?;
46//!     
47//!     std::fs::write("docs.html", html)?;
48//!     Ok(())
49//! }
50//! ```
51//!
52//! For more control, use the [`UIBuilder`]:
53//!
54//! ```rust
55//! use openapi_ui::{UIBuilder, OpenAPISpec};
56//!
57//! # fn run(spec: OpenAPISpec) -> Result<(), Box<dyn std::error::Error>> {
58//! let html = UIBuilder::new(spec)
59//!     .theme("dark")
60//!     .build();
61//! # Ok(())
62//! # }
63//! ```
64
65pub mod error;
66pub mod openapi;
67pub mod template;
68pub mod theme;
69pub mod ui;
70
71pub use error::{Result, UIError};
72pub use openapi::{HttpScheme, OpenAPISpec, SchemaType};
73pub use theme::{ThemeMode, get_complete_theme_css, get_theme_css};
74pub use ui::{UIBuilder, UIConfig, generate_base_ui, generate_docs, generate_ui};