1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use super::*;
#[derive(Debug, Clone, Default)]
pub struct Builder {
spec: Spec,
path_prefix: String,
}
#[inline]
pub fn spec() -> Builder {
Builder::default()
}
impl Builder {
#[inline]
pub fn info(mut self, info: Info) -> Self {
self.spec.info = info;
self
}
#[inline]
pub fn server(mut self, server: Server) -> Self {
self.spec.servers.push(server);
self
}
#[inline]
pub fn prefix(mut self, path: String) -> Self {
assert!(path.starts_with('/'));
self.path_prefix = path;
self
}
pub fn build<F, Ret>(self, op: F) -> (Spec, Ret)
where
F: FnOnce() -> Ret,
{
let mut collector = new();
collector.path_prefix = self.path_prefix;
collector.spec = self.spec;
let cell = RefCell::new(collector);
let ret = COLLECTOR.set(&cell, || op());
let mut spec = cell.into_inner().spec();
spec.openapi = "3.0.1".into();
(spec, ret)
}
}