1use apistos_plugins::ui::{UIPlugin, UIPluginConfig};
4
5const RAPIDOC_DEFAULT: &str = include_str!("../assets/index.html");
6
7pub struct RapidocConfig {
9 html: String,
10 path: String,
11}
12
13impl RapidocConfig {
14 pub fn new<T: ToString>(path: &T) -> Self {
16 Self {
17 html: RAPIDOC_DEFAULT.to_string(),
18 path: path.to_string(),
19 }
20 }
21
22 pub fn with_html(mut self, html_path: String) -> Self {
25 self.html = html_path;
26 self
27 }
28}
29
30impl UIPluginConfig for RapidocConfig {
31 fn build(self: Box<Self>, openapi_path: &str) -> Box<dyn UIPlugin> {
32 Box::new(Rapidoc::new(*self, openapi_path))
33 }
34}
35
36#[doc(hidden)]
37pub struct Rapidoc {
38 html: String,
39 path: String,
40 openapi_path: String,
41}
42
43impl Rapidoc {
44 pub fn new(config: RapidocConfig, openapi_path: &str) -> Self {
45 Self {
46 html: config.html,
47 path: config.path,
48 openapi_path: openapi_path.to_string(),
49 }
50 }
51}
52
53impl UIPlugin for Rapidoc {
54 fn path(&self) -> String {
55 self.path.clone()
56 }
57
58 fn to_html(&self) -> String {
59 self.html.replace("$specUrl", &self.openapi_path)
60 }
61}