Skip to content

Documentation page ​

Everything about the served document and the reference page is set on OpenApi, which you pass to ApiRouter::openapi(..). The defaults follow @elysiajs/openapi.

A full configuration ​

rust
fn openapi() -> OpenApi {
    OpenApi::new()
        .title("User API")
        .version("1.2.0")
        .description("Everything about users")
        .license("MIT")
        .server("https://api.example.com")
        .tag("Users", "User management")
        .path("/openapi")
        .spec_path("/openapi/json")
        .provider(Provider::Scalar(
            ScalarRenderer::default().version("1.79.0"),
        ))
        .exclude_paths(["/internal/*"])
        .exclude_methods(["OPTIONS"])
        .exclude_tags(["Internal"])
        .terms_of_service("https://example.com/terms")
        .contact(
            "API team",
            Some("https://example.com"),
            Some("api@example.com"),
        )
        .external_docs("https://docs.example.com", Some("Guides"))
        .extension("logo", serde_json::json!({ "url": "/logo.svg" }))
        .export_ts("web/api.ts")
}

Document ​

MethodSets
.title(..), .version(..), .description(..)info
.license(spdx), .license_url(name, url)info.license
.terms_of_service(url)info.termsOfService
.contact(name, url, email)info.contact
.server(url)an entry in servers
.tag(name, description)an entry in tags
.security_scheme(name, scheme)an entry in components.securitySchemes
.external_docs(url, description)externalDocs
.extension(name, value)a top-level x- field (the prefix is added if missing)
.openapi_version("3.1.0")the openapi field (default 3.2.0; 3.1.0 or 3.0.3 write event-stream and sequential JSON items as an extension)

Routes ​

MethodDefault
.path(..)/openapithe reference page
.spec_path(..){path}/jsonthe JSON document
.client_path(Some(..))/client.tsthe TypeScript client; None turns it off
.embed_spec(true)falseput the document inside the page instead of fetching it
.enabled(false)trueswitch every documentation route off at runtime

Leaving routes out ​

exclude_paths takes exact paths or prefixes ending in *, exclude_methods takes method names and exclude_tags drops every route with one of those tags. A route marked #[api(hide)] or Detail::new().hide() is left out the same way. Excluded routes are still served; only the document skips them, together with any schema nothing else uses.

Scalar or Swagger UI ​

Scalar is the default, pinned to @scalar/api-reference 1.79.0. Swagger UI uses swagger-ui-dist 5.35.0. Both versions are pinned so a new CDN release cannot break your page.

rust
OpenApi::new().provider(Provider::scalar());

OpenApi::new().provider(Provider::Scalar(
    ScalarRenderer::default()
        .version("1.79.0")
        .config("theme", "purple"),
));

OpenApi::new().provider(Provider::SwaggerUi(
    SwaggerRenderer::default()
        .theme("/static/swagger-light.css")
        .dark_theme("/static/swagger-dark.css")
        .option("docExpansion", "none"),
));

OpenApi::new().provider(Provider::None);
RendererMethods
ScalarRenderer.version(..), .cdn(url), .config(key, value) for Scalar's configuration
SwaggerRenderer.version(..), .cdn(url), .option(key, value), .theme(css), .dark_theme(css)

Provider::None serves only the JSON document.

Released under the MIT or Apache-2.0 license.