Skip to main content

tokmd_analysis_types/
license.rs

1//! License analysis receipt DTOs.
2//!
3//! These contract types remain re-exported from the crate root to preserve
4//! existing `tokmd_analysis_types::...` names.
5
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct LicenseReport {
10    pub findings: Vec<LicenseFinding>,
11    pub effective: Option<String>,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct LicenseFinding {
16    pub spdx: String,
17    pub confidence: f32,
18    pub source_path: String,
19    pub source_kind: LicenseSourceKind,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
23#[serde(rename_all = "snake_case")]
24pub enum LicenseSourceKind {
25    Metadata,
26    Text,
27}
28
29#[cfg(test)]
30mod tests {
31    use super::LicenseSourceKind;
32
33    #[test]
34    fn license_source_kind_serde_roundtrip() -> Result<(), Box<dyn std::error::Error>> {
35        for variant in [LicenseSourceKind::Metadata, LicenseSourceKind::Text] {
36            let json = serde_json::to_string(&variant)?;
37            let back: LicenseSourceKind = serde_json::from_str(&json)?;
38            assert_eq!(back, variant);
39        }
40        Ok(())
41    }
42}