OpenApiDoc

Struct OpenApiDoc 

Source
pub struct OpenApiDoc { /* private fields */ }
Expand description

OpenAPI文档构建器

提供便捷的方法来构建和管理OpenAPI文档。

Implementations§

Source§

impl OpenApiDoc

Source

pub fn new(title: &str, version: &str) -> Self

创建一个新的OpenAPI文档

§参数
  • title: API标题
  • version: API版本
§示例
use silent_openapi::OpenApiDoc;

let doc = OpenApiDoc::new("用户API", "1.0.0");
Source

pub fn from_openapi(openapi: OpenApi) -> Self

由现有的 OpenApi 对象创建文档包装

Source

pub fn description<S: Into<String>>(self, description: S) -> Self

设置API描述

Source

pub fn add_server(self, url: &str, description: Option<&str>) -> Self

添加服务器信息

§参数
  • url: 服务器URL
  • description: 服务器描述
Source

pub fn add_path(self, path: &str, path_item: PathItem) -> Self

添加路径项

§参数
  • path: API路径
  • path_item: 路径项定义
Source

pub fn add_paths(self, paths: Vec<(String, PathItem)>) -> Self

批量添加路径

§参数
  • paths: 路径映射表
Source

pub fn add_placeholder_schemas(self, type_names: &[&str]) -> Self

为给定类型名追加占位 schema(占位 Object,用于引用解析)

Source

pub fn apply_registered_schemas(self) -> Self

应用由 endpoint 宏注册的 ToSchema 完整 schema

Source

pub fn add_bearer_auth( self, scheme_name: &str, description: Option<&str>, ) -> Self

添加 Bearer/JWT 安全定义

Source

pub fn set_global_security(self, scheme_name: &str, scopes: &[&str]) -> Self

设置全局 security 要求

Source

pub fn openapi(&self) -> &OpenApi

获取内部的OpenAPI对象

Source

pub fn into_openapi(self) -> OpenApi

转换为OpenAPI对象

Source

pub fn to_json(&self) -> Result<String>

序列化为JSON字符串

Source

pub fn to_pretty_json(&self) -> Result<String>

序列化为格式化的JSON字符串

Source

pub fn to_json_value(&self) -> Result<Value>

序列化为JSON Value

Trait Implementations§

Source§

impl Clone for OpenApiDoc

Source§

fn clone(&self) -> OpenApiDoc

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more