Skip to main content

openapi_nexus_go/
config.rs

1//! Go HTTP generator-specific configuration
2
3use serde::{Deserialize, Serialize};
4use tracing::error;
5
6use openapi_nexus_core::NamingConvention;
7
8/// Go HTTP generator-specific configuration
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct GoHttpConfig {
11    /// File naming convention (camelCase, kebab-case, snake_case, PascalCase)
12    #[serde(default = "default_file_naming_convention")]
13    pub file_naming_convention: NamingConvention,
14
15    /// Go module path (e.g., "github.com/example/sdk")
16    #[serde(default)]
17    pub module_path: Option<String>,
18
19    /// Package name (defaults to OpenAPI title in lowercase)
20    #[serde(default)]
21    pub package_name: Option<String>,
22}
23
24fn default_file_naming_convention() -> NamingConvention {
25    NamingConvention::SnakeCase
26}
27
28impl Default for GoHttpConfig {
29    fn default() -> Self {
30        Self {
31            file_naming_convention: default_file_naming_convention(),
32            module_path: None,
33            package_name: None,
34        }
35    }
36}
37
38impl From<toml::value::Table> for GoHttpConfig {
39    fn from(value: toml::value::Table) -> Self {
40        use serde::Deserialize;
41        match GoHttpConfig::deserialize(value) {
42            Ok(config) => config,
43            Err(e) => {
44                error!(
45                    "Failed to parse Go HTTP config: {}. Using default configuration.",
46                    e
47                );
48                Self::default()
49            }
50        }
51    }
52}