Skip to content

Commit deb6b93

Browse files
authored
Fix #138 (#141)
2 parents 700ccbd + b999f5a commit deb6b93

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ serde_json = "1"
5050
syn = "2.0"
5151

5252
actix-multipart = "0.6"
53+
actix-session = "0.10"
5354
garde-actix-web = "0.9"
5455
chrono = "0.4.20"
5556
garde = { version = "0.20", features = ["derive", "serde"] }

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ For a complete example, see [the sample petstore](https://github.com/netwo-io/ap
174174
| `actix` (default) | Enables documenting types from `actix` | |
175175
| `lab_query` | Enables documenting `actix_web_lab::extract::Query` | [`actix-web-lab`](https://crates.io/crates/actix-web-lab) |
176176
| `garde` | Enables input validation through `garde` | [`garde`](https://crates.io/crates/garde) |
177+
| `actix-session` | Enables documenting types from `actix-session` | [`actix-session`](https://crates.io/crates/actix-session) |
177178
| `actix-web-grants` | Enables support for `actix-web-grants` | [`actix-web-grants`](https://crates.io/crates/actix-web-grants) |
178179
| `rapidoc` | Enables RapiDoc to expose the generated openapi file | |
179180
| `redoc` | Enables Redoc to expose the generated openapi file | |

apistos-core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ actix-web = { workspace = true, optional = true }
2121
actix-web-lab = { workspace = true, optional = true }
2222
actix-web-grants = { workspace = true, optional = true }
2323
actix-multipart = { workspace = true, optional = true }
24+
actix-session = { workspace = true, optional = true }
2425
garde-actix-web = { workspace = true, optional = true }
2526
chrono = { workspace = true, optional = true }
2627
rust_decimal = { workspace = true, optional = true }
@@ -54,6 +55,7 @@ garde = ["actix", "dep:garde-actix-web"]
5455
chrono = ["dep:chrono", "schemars/chrono"]
5556
multipart = ["actix", "dep:serde", "dep:actix-multipart"]
5657
rust_decimal = ["dep:rust_decimal", "schemars/rust_decimal"]
58+
actix-session = ["actix", "dep:serde", "dep:actix-session"]
5759
uuid = ["dep:uuid", "schemars/uuid1"]
5860
url = ["dep:url", "schemars/url"]
5961
extras = ["chrono", "multipart", "rust_decimal", "uuid", "url"]

apistos-core/src/components/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ pub mod json;
88
pub mod multipart;
99
#[cfg(feature = "actix")]
1010
pub mod parameters;
11+
#[cfg(feature = "actix-session")]
12+
pub mod session;
1113
pub mod simple;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use crate::ApiComponent;
2+
use apistos_models::paths::{Parameter, ParameterDefinition, ParameterIn, RequestBody};
3+
use apistos_models::reference_or::ReferenceOr;
4+
use schemars::schema::{InstanceType, Schema, SchemaObject, SingleOrVec, StringValidation};
5+
6+
impl ApiComponent for actix_session::Session {
7+
fn required() -> bool {
8+
true
9+
}
10+
11+
fn child_schemas() -> Vec<(String, ReferenceOr<Schema>)> {
12+
vec![]
13+
}
14+
15+
fn raw_schema() -> Option<ReferenceOr<Schema>> {
16+
Some(ReferenceOr::Object(Schema::Object(SchemaObject {
17+
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))),
18+
string: Some(Box::new(StringValidation::default())),
19+
..Default::default()
20+
})))
21+
}
22+
23+
fn schema() -> Option<(String, ReferenceOr<Schema>)> {
24+
None
25+
}
26+
27+
fn request_body() -> Option<RequestBody> {
28+
None
29+
}
30+
31+
fn parameters() -> Vec<Parameter> {
32+
vec![Parameter {
33+
name: "id".to_string(), // from default actix-session's CookieConfiguration
34+
_in: ParameterIn::Cookie,
35+
required: Some(true),
36+
definition: Self::raw_schema().map(ParameterDefinition::Schema),
37+
..Default::default()
38+
}]
39+
}
40+
}

0 commit comments

Comments
 (0)