data_modelling_sdk/import/
mod.rs

1//! Import functionality
2//!
3//! Provides parsers for importing data models from various formats:
4//! - SQL (CREATE TABLE statements)
5//! - ODCS (Open Data Contract Standard) v3.1.0 YAML format (legacy ODCL formats supported for import)
6//! - JSON Schema
7//! - AVRO
8//! - Protobuf
9
10pub mod avro;
11#[cfg(feature = "bpmn")]
12pub mod bpmn;
13pub mod cads;
14#[cfg(feature = "dmn")]
15pub mod dmn;
16pub mod json_schema;
17pub mod odcs;
18pub mod odps;
19#[cfg(feature = "openapi")]
20pub mod openapi;
21pub mod protobuf;
22pub mod sql;
23
24// anyhow::Result not currently used in this module
25
26/// Result of an import operation.
27///
28/// Contains extracted tables and any errors/warnings from the import process.
29#[derive(Debug, serde::Serialize, serde::Deserialize)]
30#[must_use = "import results should be processed or errors checked"]
31pub struct ImportResult {
32    /// Tables extracted from the import
33    pub tables: Vec<TableData>,
34    /// Tables that require name input (for SQL imports with unnamed tables)
35    pub tables_requiring_name: Vec<TableRequiringName>,
36    /// Parse errors/warnings
37    pub errors: Vec<ImportError>,
38    /// Whether AI suggestions are available
39    pub ai_suggestions: Option<Vec<serde_json::Value>>,
40}
41
42/// Error during import
43#[derive(Debug, thiserror::Error, serde::Serialize, serde::Deserialize)]
44pub enum ImportError {
45    #[error("Parse error: {0}")]
46    ParseError(String),
47    #[error("Validation error: {0}")]
48    ValidationError(String),
49    #[error("IO error: {0}")]
50    IoError(String),
51    #[error("BPMN validation error: {0}")]
52    BPMNValidationError(String),
53    #[error("DMN validation error: {0}")]
54    DMNValidationError(String),
55    #[error("OpenAPI validation error: {0}")]
56    OpenAPIValidationError(String),
57    #[error("BPMN parse error: {0}")]
58    BPMNParseError(String),
59    #[error("DMN parse error: {0}")]
60    DMNParseError(String),
61    #[error("OpenAPI parse error: {0}")]
62    OpenAPIParseError(String),
63}
64
65/// Table data from import
66#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
67pub struct TableData {
68    pub table_index: usize,
69    pub name: Option<String>,
70    pub columns: Vec<ColumnData>,
71    // Additional fields can be added as needed
72}
73
74/// Column data from import
75#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
76pub struct ColumnData {
77    pub name: String,
78    pub data_type: String,
79    pub nullable: bool,
80    pub primary_key: bool,
81    /// Column description/documentation (from ODCS/ODCL description field)
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub description: Option<String>,
84    /// Quality rules and validation checks (from ODCS/ODCL quality array)
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub quality: Option<Vec<std::collections::HashMap<String, serde_json::Value>>>,
87    /// JSON Schema $ref reference path (from ODCS/ODCL $ref field)
88    #[serde(skip_serializing_if = "Option::is_none", rename = "$ref")]
89    pub ref_path: Option<String>,
90}
91
92// Re-export for convenience
93pub use avro::AvroImporter;
94pub use cads::CADSImporter;
95pub use json_schema::JSONSchemaImporter;
96pub use odcs::ODCSImporter;
97pub use odps::ODPSImporter;
98pub use protobuf::ProtobufImporter;
99pub use sql::SQLImporter;
100
101/// Table requiring name input (for SQL imports)
102#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
103pub struct TableRequiringName {
104    pub table_index: usize,
105    pub suggested_name: Option<String>,
106}