diff --git a/crates/oapi/docs/endpoint.md b/crates/oapi/docs/endpoint.md index 004271ea4..08abdaa74 100644 --- a/crates/oapi/docs/endpoint.md +++ b/crates/oapi/docs/endpoint.md @@ -41,6 +41,33 @@ fn endpoint() {} * `security(...)` List of [`SecurityRequirement`][security]s local to the path operation. +# Security Attributes + +To configure security requirements, you need to add one or more security schemes when creating an `OpenApi` object, +as indicated in the example: + +```rust +use salvo_oapi::security::{Http, HttpAuthScheme}; +use salvo_oapi::{OpenApi, SecurityScheme}; + +#[tokio::main] +async fn main() { + let doc = OpenApi::new("test", "0.1") + .add_security_scheme( + "bearer", + SecurityScheme::Http(Http::new(HttpAuthScheme::Bearer).bearer_format("JSON"))); +} +``` + +And, accordingly, when using the `endpoint` macro, specify the scheme: + +```rust +use salvo_oapi::endpoint; + +#[endpoint(security(["bearer" = ["bearer"]]))] +pub async fn authenticated_action() {} +``` + # Request Body Attributes **Simple format definition by `request_body = ...`** diff --git a/crates/oapi/src/extract/parameter/cookie.rs b/crates/oapi/src/extract/parameter/cookie.rs index e7a58a869..a96ba0153 100644 --- a/crates/oapi/src/extract/parameter/cookie.rs +++ b/crates/oapi/src/extract/parameter/cookie.rs @@ -28,7 +28,7 @@ impl Deref for CookieParam { type Target = T; fn deref(&self) -> &Self::Target { - self.0.as_ref().expect("`CookieParam` defref get `None`") + self.0.as_ref().expect("`CookieParam` deref get `None`") } } impl Deref for CookieParam { @@ -41,7 +41,7 @@ impl Deref for CookieParam { impl DerefMut for CookieParam { fn deref_mut(&mut self) -> &mut Self::Target { - self.0.as_mut().expect("`CookieParam` defref_mut get `None`") + self.0.as_mut().expect("`CookieParam` deref_mut get `None`") } } impl DerefMut for CookieParam {