Skip to main content

sova_openapi/
doc.rs

1use serde_json::Value;
2
3/// Per-route OpenAPI annotations stored in route meta.
4#[derive(Debug, Clone)]
5pub struct Doc {
6    pub(crate) skip: bool,
7    pub(crate) body_schema: Option<Value>,
8    pub(crate) query_schema: Option<Value>,
9    pub(crate) params_schema: Option<Value>,
10    pub(crate) responses: Vec<(u16, Value)>,
11}
12
13impl Doc {
14    pub fn new() -> Self {
15        Self {
16            skip: false,
17            body_schema: None,
18            query_schema: None,
19            params_schema: None,
20            responses: Vec::new(),
21        }
22    }
23
24    /// Mark the route as intentionally undocumented.
25    pub fn skip() -> Self {
26        Self {
27            skip: true,
28            ..Self::new()
29        }
30    }
31
32    pub fn is_skip(&self) -> bool {
33        self.skip
34    }
35
36    pub fn body_schema(mut self, schema: Value) -> Self {
37        self.body_schema = Some(schema);
38        self
39    }
40
41    pub fn query_schema(mut self, schema: Value) -> Self {
42        self.query_schema = Some(schema);
43        self
44    }
45
46    pub fn params_schema(mut self, schema: Value) -> Self {
47        self.params_schema = Some(schema);
48        self
49    }
50
51    pub fn ok_schema(mut self, schema: Value) -> Self {
52        self.responses.push((200, schema));
53        self
54    }
55
56    pub fn created_schema(mut self, schema: Value) -> Self {
57        self.responses.push((201, schema));
58        self
59    }
60
61    pub fn response(mut self, status: u16, schema: Value) -> Self {
62        self.responses.push((status, schema));
63        self
64    }
65}
66
67impl Default for Doc {
68    fn default() -> Self {
69        Self::new()
70    }
71}