scancode_rust/models/
file_info.rs1use serde::{Serialize, Deserialize};
2
3#[derive(Serialize, Debug)]
4pub struct FileInfo {
5 pub name: String,
6 pub base_name: String,
7 pub extension: String,
8 pub path: String,
9 #[serde(rename = "type")] pub file_type: FileType,
11 pub mime_type: Option<String>,
12 pub size: u64,
13 pub date: Option<String>,
14 pub sha1: Option<String>,
15 pub md5: Option<String>,
16 pub sha256: Option<String>,
17 pub programming_language: Option<String>,
18 #[serde(rename = "detected_license_expression_spdx")] pub license_expression: Option<String>,
20 pub license_detections: Vec<LicenseDetection>,
21 pub copyrights: Vec<Copyright>,
22 pub urls: Vec<OutputURL>,
23 pub scan_errors: Vec<String>,
24}
25
26#[derive(Serialize, Debug)]
27pub struct PackageData {
28 #[serde(rename = "type")] pub package_type: Option<String>,
30 pub namespace: Option<String>,
31 pub name: Option<String>,
32 pub version: Option<String>,
33 pub homepage_url: Option<String>,
34 pub download_url: Option<String>,
35 pub copyright: Option<String>,
36 pub license_detections: Vec<LicenseDetection>,
37 pub dependencies: Vec<Dependency>,
38 pub parties: Vec<Party>,
39 pub purl: Option<String>,
40}
41
42#[derive(Serialize, Debug)]
43pub struct LicenseDetection {
44 #[serde(rename = "license_expression_spdx")] pub license_expression: String,
46 pub matches: Vec<Match>,
47}
48
49#[derive(Serialize, Debug)]
50pub struct Match {
51 pub score: f64,
52 pub start_line: usize,
53 pub end_line: usize,
54 #[serde(rename = "license_expression_spdx")] pub license_expression: String,
56 pub rule_identifier: String,
57 pub matched_text: Option<String>,
58}
59
60#[derive(Serialize, Debug)]
61pub struct Copyright {
62 pub copyright: String,
63 pub start_line: usize,
64 pub end_line: usize,
65}
66
67#[derive(Serialize, Debug)]
68pub struct Dependency {
69 pub purl: Option<String>,
70 pub scope: Option<String>,
71 pub is_optional: bool,
72}
73
74#[derive(Serialize, Debug)]
75pub struct Party {
76 pub email: StringOrArray,
77}
78
79#[derive(Serialize, Debug)]
80pub struct OutputURL {
81 pub url: String,
82}
83
84#[derive(Debug)]
85pub enum FileType {
86 File,
87 Directory,
88}
89
90impl Serialize for FileType {
91 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
92 where
93 S: serde::Serializer,
94 {
95 let value = match self {
96 FileType::File => "file",
97 FileType::Directory => "directory",
98 };
99 serializer.serialize_str(value)
100 }
101}
102
103#[derive(Serialize, Deserialize, Debug, Clone)]
104#[serde(untagged)]
105pub enum StringOrArray {
106 String(String),
107 Array(Vec<String>),
108 Null,
109}