Skip to main content

Crate dioxus_openapi

Crate dioxus_openapi 

Source
Expand description

OpenAPI for Dioxus server functions.

Pair api_get / api_post with build_openapi so paths never need to be listed twice: the macros expand to Dioxus #[get]/#[post] and inventory-register a utoipa path (with tags applied correctly for Scalar).

§App setup

[dependencies]
dioxus-openapi = "0.1"

[features]
server = ["dioxus/server", "dioxus-openapi/server"]
use dioxus_openapi::{api_get, api_post, build_openapi, SpecOptions, TagMeta};

#[api_get("/api/hello", tag = "demo")]
pub async fn hello() -> Result<String> { Ok("hi".into()) }

const SPEC: SpecOptions = SpecOptions {
    title: "My API",
    version: "0.1.0",
    description: Some("…"),
    tags: &[TagMeta { name: "demo", description: Some("Demo routes") }],
};

// GET /api/openapi.json
async fn openapi_json() -> axum::Json<utoipa::openapi::OpenApi> {
    axum::Json(build_openapi(&SPEC))
}

Structs§

RegisteredPathserver
One documented endpoint, registered by crate::api_get / crate::api_post.
ScalarOptionsserver
Options for the Scalar interactive API reference HTML shell.
SpecOptionsserver
Document-level OpenAPI info + optional tag descriptions.
TagMetaserver
Tag metadata for the top-level OpenAPI tags array (sidebar descriptions).

Functions§

append_tagged_pathserver
Like PathsBuilder::path_from, but also copies tags from [utoipa::__dev::Tags] onto the operation.
build_openapiserver
Build the full OpenAPI document from all inventory-registered paths.
scalar_htmlserver
Build a standalone Scalar HTML document for GET /api/docs (or similar).

Attribute Macros§

api_get
#[api_get("/path", tag = "...", ...)]
api_post
#[api_post("/path", tag = "...", ...)]