pub struct SwaggerUiMiddleware { /* private fields */ }Expand description
Swagger UI 中间件
实现了Silent的MiddleWareHandler trait,可以作为中间件添加到路由中。 当请求匹配Swagger UI相关路径时,直接返回响应;否则继续执行后续处理器。
Implementations§
Source§impl SwaggerUiMiddleware
impl SwaggerUiMiddleware
Sourcepub fn new(ui_path: &str, openapi: OpenApi) -> Result<Self>
pub fn new(ui_path: &str, openapi: OpenApi) -> Result<Self>
创建新的Swagger UI中间件
§参数
ui_path: Swagger UI的访问路径,如 “/swagger-ui”openapi: OpenAPI规范对象
§示例
ⓘ
use silent::prelude::*;
use silent_openapi::SwaggerUiMiddleware;
use utoipa::OpenApi;
#[derive(OpenApi)]
#[openapi(paths(), components(schemas()))]
struct ApiDoc;
let middleware = SwaggerUiMiddleware::new("/swagger-ui", ApiDoc::openapi());
let route = Route::new("")
.hook(middleware)
.get(your_handler);Sourcepub fn with_custom_api_doc_path(
ui_path: &str,
api_doc_path: &str,
openapi: OpenApi,
) -> Result<Self>
pub fn with_custom_api_doc_path( ui_path: &str, api_doc_path: &str, openapi: OpenApi, ) -> Result<Self>
使用自定义的API文档路径
Sourcepub fn with_options(
ui_path: &str,
openapi: OpenApi,
options: SwaggerUiOptions,
) -> Result<Self>
pub fn with_options( ui_path: &str, openapi: OpenApi, options: SwaggerUiOptions, ) -> Result<Self>
使用自定义选项创建中间件
Trait Implementations§
Source§impl Clone for SwaggerUiMiddleware
impl Clone for SwaggerUiMiddleware
Source§fn clone(&self) -> SwaggerUiMiddleware
fn clone(&self) -> SwaggerUiMiddleware
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SwaggerUiMiddleware
impl RefUnwindSafe for SwaggerUiMiddleware
impl Send for SwaggerUiMiddleware
impl Sync for SwaggerUiMiddleware
impl Unpin for SwaggerUiMiddleware
impl UnwindSafe for SwaggerUiMiddleware
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more