Skip to main content

Crate openapi_ui

Crate openapi_ui 

Source
Expand description

§openapi-ui

Crates.io Documentation License: MIT

openapi-ui is a library for generating documentation UIs from OpenAPI specifications.

It takes an OpenAPI JSON string and produces a self-contained HTML file with a responsive UI.

§Web Framework Examples

§Usage

use openapi_ui::{generate_docs, ThemeMode};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let openapi_json = r#"{"openapi": "3.0.0", "info": {"title": "API", "version": "1.0.0"}, "paths": {}}"#;
     
    // Generate HTML with system theme and default favicon
    let html = generate_docs(openapi_json, ThemeMode::System, None, None)?;
     
    std::fs::write("docs.html", html)?;
    Ok(())
}

For more control, use the UIBuilder:

use openapi_ui::{UIBuilder, OpenAPISpec};

let html = UIBuilder::new(spec)
    .theme("dark")
    .build();

Re-exports§

pub use error::Result;
pub use error::UIError;
pub use openapi::HttpScheme;
pub use openapi::OpenAPISpec;
pub use openapi::SchemaType;
pub use theme::ThemeMode;
pub use theme::get_complete_theme_css;
pub use theme::get_theme_css;
pub use ui::UIBuilder;
pub use ui::UIConfig;
pub use ui::generate_base_ui;
pub use ui::generate_docs;
pub use ui::generate_ui;

Modules§

error
openapi
template
theme
ui