Skip to main content

dioxus_openapi/
lib.rs

1//! OpenAPI for Dioxus server functions.
2//!
3//! Pair [`api_get`] / [`api_post`] with [`build_openapi`] so paths never need
4//! to be listed twice: the macros expand to Dioxus `#[get]`/`#[post]` **and**
5//! inventory-register a utoipa path (with tags applied correctly for Scalar).
6//!
7//! # App setup
8//!
9//! ```toml
10//! [dependencies]
11//! dioxus-openapi = "0.1"
12//!
13//! [features]
14//! server = ["dioxus/server", "dioxus-openapi/server"]
15//! ```
16//!
17//! ```rust,ignore
18//! use dioxus_openapi::{api_get, api_post, build_openapi, SpecOptions, TagMeta};
19//!
20//! #[api_get("/api/hello", tag = "demo")]
21//! pub async fn hello() -> Result<String> { Ok("hi".into()) }
22//!
23//! const SPEC: SpecOptions = SpecOptions {
24//!     title: "My API",
25//!     version: "0.1.0",
26//!     description: Some("…"),
27//!     tags: &[TagMeta { name: "demo", description: Some("Demo routes") }],
28//! };
29//!
30//! // GET /api/openapi.json
31//! async fn openapi_json() -> axum::Json<utoipa::openapi::OpenApi> {
32//!     axum::Json(build_openapi(&SPEC))
33//! }
34//! ```
35
36#![cfg_attr(docsrs, feature(doc_cfg))]
37#![cfg_attr(not(feature = "server"), allow(unused_imports))]
38
39pub use dioxus_openapi_macros::{api_get, api_post};
40
41#[cfg(feature = "server")]
42mod runtime;
43
44#[cfg(feature = "server")]
45#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
46pub use runtime::{
47    append_tagged_path, build_openapi, scalar_html, RegisteredPath, ScalarOptions, SpecOptions,
48    TagMeta,
49};
50
51/// Re-export so macro expansions can `::dioxus_openapi::inventory::submit!`
52/// without the app depending on `inventory` directly.
53#[cfg(feature = "server")]
54#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
55#[doc(hidden)]
56pub use inventory;