rustapi_openapi/
config.rs

1//! OpenAPI configuration
2
3/// Configuration for OpenAPI documentation
4#[derive(Debug, Clone)]
5pub struct OpenApiConfig {
6    /// API title
7    pub title: String,
8    /// API version
9    pub version: String,
10    /// API description
11    pub description: Option<String>,
12    /// Path to serve OpenAPI JSON
13    pub json_path: String,
14    /// Path to serve Swagger UI
15    pub docs_path: String,
16}
17
18impl Default for OpenApiConfig {
19    fn default() -> Self {
20        Self {
21            title: "RustAPI Application".to_string(),
22            version: "1.0.0".to_string(),
23            description: None,
24            json_path: "/openapi.json".to_string(),
25            docs_path: "/docs".to_string(),
26        }
27    }
28}
29
30impl OpenApiConfig {
31    /// Create a new OpenAPI configuration
32    pub fn new(title: impl Into<String>, version: impl Into<String>) -> Self {
33        Self {
34            title: title.into(),
35            version: version.into(),
36            ..Default::default()
37        }
38    }
39
40    /// Set API description
41    pub fn description(mut self, description: impl Into<String>) -> Self {
42        self.description = Some(description.into());
43        self
44    }
45
46    /// Set path for OpenAPI JSON endpoint
47    pub fn json_path(mut self, path: impl Into<String>) -> Self {
48        self.json_path = path.into();
49        self
50    }
51
52    /// Set path for Swagger UI docs
53    pub fn docs_path(mut self, path: impl Into<String>) -> Self {
54        self.docs_path = path.into();
55        self
56    }
57}