Crate silent_openapi

Crate silent_openapi 

Source
Expand description

§Silent OpenAPI

为Silent Web框架提供OpenAPI 3.0支持,包括自动文档生成和Swagger UI集成。

§主要特性

  • 🚀 基于utoipa的高性能OpenAPI文档生成
  • 📖 内置Swagger UI界面
  • 🔧 与Silent框架深度集成
  • 📝 支持路由文档自动收集
  • 🎯 零运行时开销的编译时文档生成

§快速开始

use silent::prelude::*;
use silent_openapi::{OpenApiDoc, SwaggerUiHandler};
use utoipa::OpenApi;

#[derive(OpenApi)]
#[openapi(
    paths(get_hello),
    components(schemas())
)]
struct ApiDoc;

async fn get_hello(_req: Request) -> Result<Response> {
    Ok(Response::text("Hello, OpenAPI!"))
}

fn main() {
    let route = Route::new("")
        .get(get_hello)
        .append(SwaggerUiHandler::new("/swagger-ui", ApiDoc::openapi()));

    Server::new().run(route);
}

Re-exports§

pub use error::OpenApiError;
pub use error::Result;
pub use handler::SwaggerUiHandler;
pub use middleware::SwaggerUiMiddleware;
pub use route::DocumentedRoute;
pub use route::RouteDocumentation;
pub use route::RouteOpenApiExt;
pub use schema::OpenApiDoc;

Modules§

doc
error
Silent OpenAPI 错误处理
handler
Swagger UI 处理器
middleware
Swagger UI 中间件
openapi
Rust implementation of Openapi Spec V3.1.
route
路由文档收集和扩展
schema
OpenAPI 文档模式和工具

Structs§

OpenApi
Root object of the OpenAPI document.
SwaggerUiOptions
Swagger UI 配置选项

Constants§

VERSION
Silent OpenAPI的版本信息

Traits§

IntoParams
Trait used to convert implementing type to OpenAPI parameters.
IntoResponses
This trait is implemented to document a type (like an enum) which can represent multiple responses, to be used in operation.
ToResponse
This trait is implemented to document a type which represents a single response which can be referenced or reused as a component in multiple operations.
ToSchema
Trait for implementing OpenAPI Schema object.

Functions§

create_openapi_doc
创建一个基础的OpenAPI文档结构

Attribute Macros§

endpoint

Derive Macros§

IntoParams
Generate path parameters from struct’s fields.
IntoResponses
Generate responses with status codes what can be attached to the utoipa::path.
ToResponse
Generate reusable OpenAPI response that can be used in utoipa::path or in OpenApi.
ToSchema
Generate reusable OpenAPI schema to be used together with OpenApi.