pub struct OpenApi { /* private fields */ }openapi only.Expand description
The settings of an OpenAPI document, such as the API’s title and version.
Call generate with a router to create the document
for its documented routes. For example, a route can serve it:
use topcoat::{
Result,
context::Cx,
openapi::{Document, OpenApi},
router::{route, router},
};
#[route(GET "/openapi.json")]
async fn spec(cx: &Cx) -> Result<Document> {
Ok(OpenApi::new("Acme API", "1.0.0")
.description("Everything you need for tea.")
.generate(&router(cx)))
}See Operation for documenting routes.
Implementations§
Source§impl OpenApi
impl OpenApi
Sourcepub fn new(
title: impl Into<Cow<'static, str>>,
version: impl Into<Cow<'static, str>>,
) -> OpenApi
pub fn new( title: impl Into<Cow<'static, str>>, version: impl Into<Cow<'static, str>>, ) -> OpenApi
Creates the settings for an API with the given title and version.
The version is that of the API itself, such as 1.0.0.
Sourcepub fn description(self, description: impl Into<Cow<'static, str>>) -> OpenApi
pub fn description(self, description: impl Into<Cow<'static, str>>) -> OpenApi
Sets a description of the API as a whole.
Sourcepub fn server(self, url: impl Into<Cow<'static, str>>) -> OpenApi
pub fn server(self, url: impl Into<Cow<'static, str>>) -> OpenApi
Adds a base URL the API is reachable at, such as
https://api.example.com.
Sourcepub fn tag(
self,
name: impl Into<Cow<'static, str>>,
description: impl Into<Cow<'static, str>>,
) -> OpenApi
pub fn tag( self, name: impl Into<Cow<'static, str>>, description: impl Into<Cow<'static, str>>, ) -> OpenApi
Describes a tag that operations use.
Documentation tools show the description next to the tag’s routes and list tags in the order they are described here.
Sourcepub fn security_scheme(
self,
name: impl Into<Cow<'static, str>>,
scheme: SecurityScheme,
) -> OpenApi
pub fn security_scheme( self, name: impl Into<Cow<'static, str>>, scheme: SecurityScheme, ) -> OpenApi
Registers a way for clients to authenticate under name.
Operations require it by that name with
Operation::security.
Sourcepub fn generate(&self, router: &Router) -> Document
pub fn generate(&self, router: &Router) -> Document
Creates the document for the documented routes of router.
A route is documented when an Operation is
attached to it, to a layer or layout that wraps it, or to the router
builder, unless the operation is
hidden.
§Panics
Panics when the routes are documented inconsistently:
- An operation describes a path parameter that its route’s path does not have.
- An operation requires a security scheme that is not registered.
- Two operations share an operation ID.
- A type passed to
Operation::queryis not a struct with named fields.
Trait Implementations§
Auto Trait Implementations§
impl Forget for OpenApi
impl Freeze for OpenApi
impl RefUnwindSafe for OpenApi
impl Send for OpenApi
impl Sync for OpenApi
impl Unpin for OpenApi
impl UnsafeUnpin for OpenApi
impl UnwindSafe for OpenApi
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more