Skip to content

Commit

Permalink
Improved OpenAPI docs (#820)
Browse files Browse the repository at this point in the history
* oapi: extend security attributes docs

* oapi: fix typo

* oapi: fix checks
  • Loading branch information
markcda committed Jun 24, 2024
1 parent 654b45a commit 385e6b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions crates/oapi/docs/endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...`**
Expand Down
4 changes: 2 additions & 2 deletions crates/oapi/src/extract/parameter/cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T> Deref for CookieParam<T, true> {
type Target = T;

fn deref(&self) -> &Self::Target {
self.0.as_ref().expect("`CookieParam<T, true>` defref get `None`")
self.0.as_ref().expect("`CookieParam<T, true>` deref get `None`")
}
}
impl<T> Deref for CookieParam<T, false> {
Expand All @@ -41,7 +41,7 @@ impl<T> Deref for CookieParam<T, false> {

impl<T> DerefMut for CookieParam<T, true> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.0.as_mut().expect("`CookieParam<T, true>` defref_mut get `None`")
self.0.as_mut().expect("`CookieParam<T, true>` deref_mut get `None`")
}
}
impl<T> DerefMut for CookieParam<T, false> {
Expand Down

0 comments on commit 385e6b0

Please sign in to comment.