nestforge_core/
documentation.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, Default)]
4pub struct RouteResponseDocumentation {
5 pub status: u16,
6 pub description: String,
7}
8
9#[derive(Debug, Clone, Serialize, Deserialize, Default)]
10pub struct RouteDocumentation {
11 pub method: String,
12 pub path: String,
13 pub summary: Option<String>,
14 pub description: Option<String>,
15 pub tags: Vec<String>,
16 pub responses: Vec<RouteResponseDocumentation>,
17 pub requires_auth: bool,
18 pub required_roles: Vec<String>,
19}
20
21impl RouteDocumentation {
22 pub fn new(method: impl Into<String>, path: impl Into<String>) -> Self {
23 Self {
24 method: method.into(),
25 path: path.into(),
26 summary: None,
27 description: None,
28 tags: Vec::new(),
29 responses: vec![RouteResponseDocumentation {
30 status: 200,
31 description: "OK".to_string(),
32 }],
33 requires_auth: false,
34 required_roles: Vec::new(),
35 }
36 }
37
38 pub fn with_summary(mut self, summary: impl Into<String>) -> Self {
39 self.summary = Some(summary.into());
40 self
41 }
42
43 pub fn with_description(mut self, description: impl Into<String>) -> Self {
44 self.description = Some(description.into());
45 self
46 }
47
48 pub fn with_tags<I, S>(mut self, tags: I) -> Self
49 where
50 I: IntoIterator<Item = S>,
51 S: Into<String>,
52 {
53 self.tags = tags.into_iter().map(Into::into).collect();
54 self
55 }
56
57 pub fn with_responses(mut self, responses: Vec<RouteResponseDocumentation>) -> Self {
58 self.responses = responses;
59 self
60 }
61
62 pub fn requires_auth(mut self) -> Self {
63 self.requires_auth = true;
64 self
65 }
66
67 pub fn with_required_roles<I, S>(mut self, roles: I) -> Self
68 where
69 I: IntoIterator<Item = S>,
70 S: Into<String>,
71 {
72 self.required_roles = roles.into_iter().map(Into::into).collect();
73 self
74 }
75}
76
77pub trait DocumentedController: Send + Sync + 'static {
78 fn route_docs() -> Vec<RouteDocumentation> {
79 Vec::new()
80 }
81}