|
19 | 19 | use once_cell::sync::Lazy; |
20 | 20 | use regex::Regex; |
21 | 21 |
|
22 | | -use crate::external_models::uri::validate_uri; |
| 22 | +use crate::external_models::normalized_string::validate_normalized_string; |
| 23 | +use crate::external_models::uri::{validate_purl, validate_uri}; |
23 | 24 | use crate::models::attached_text::AttachedText; |
24 | 25 | use crate::models::code::{Commits, Patches}; |
25 | 26 | use crate::models::external_reference::ExternalReferences; |
@@ -114,126 +115,41 @@ impl Validate for Component { |
114 | 115 | ) |
115 | 116 | .add_field_option("mime_type", self.mime_type.as_ref(), validate_mime_type) |
116 | 117 | .add_struct_option("supplier", self.supplier.as_ref(), version) |
| 118 | + .add_field_option("author", self.author.as_ref(), validate_normalized_string) |
| 119 | + .add_field_option( |
| 120 | + "publisher", |
| 121 | + self.publisher.as_ref(), |
| 122 | + validate_normalized_string, |
| 123 | + ) |
| 124 | + .add_field_option("group", self.group.as_ref(), validate_normalized_string) |
| 125 | + .add_field("name", self.name.as_ref(), validate_normalized_string) |
| 126 | + .add_field_option("version", self.version.as_ref(), validate_normalized_string) |
| 127 | + .add_field_option( |
| 128 | + "description", |
| 129 | + self.description.as_ref(), |
| 130 | + validate_normalized_string, |
| 131 | + ) |
| 132 | + .add_enum_option("scope", self.scope.as_ref(), validate_scope) |
| 133 | + .add_struct_option("hashes", self.hashes.as_ref(), version) |
| 134 | + .add_struct_option("licenses", self.licenses.as_ref(), version) |
| 135 | + .add_field_option( |
| 136 | + "copyright", |
| 137 | + self.copyright.as_ref(), |
| 138 | + validate_normalized_string, |
| 139 | + ) |
| 140 | + .add_field_option("cpe", self.cpe.as_ref(), validate_cpe) |
| 141 | + .add_field_option("purl", self.purl.as_ref(), validate_purl) |
| 142 | + .add_struct_option("swid", self.swid.as_ref(), version) |
| 143 | + .add_struct_option("pedigree", self.pedigree.as_ref(), version) |
| 144 | + .add_struct_option( |
| 145 | + "external_references", |
| 146 | + self.external_references.as_ref(), |
| 147 | + version, |
| 148 | + ) |
| 149 | + .add_struct_option("properties", self.properties.as_ref(), version) |
| 150 | + .add_struct_option("components", self.components.as_ref(), version) |
| 151 | + .add_struct_option("evidence", self.evidence.as_ref(), version) |
117 | 152 | .into() |
118 | | - |
119 | | - /* |
120 | | - if let Some(supplier) = &self.supplier { |
121 | | - let context = context.with_struct("Component", "supplier"); |
122 | | -
|
123 | | - results.push(supplier.validate_with_context(context)); |
124 | | - } |
125 | | -
|
126 | | - if let Some(author) = &self.author { |
127 | | - let context = context.with_struct("Component", "author"); |
128 | | -
|
129 | | - results.push(author.validate_with_context(context)); |
130 | | - } |
131 | | -
|
132 | | - if let Some(publisher) = &self.publisher { |
133 | | - let context = context.with_struct("Component", "publisher"); |
134 | | -
|
135 | | - results.push(publisher.validate_with_context(context)); |
136 | | - } |
137 | | -
|
138 | | - if let Some(group) = &self.group { |
139 | | - let context = context.with_struct("Component", "group"); |
140 | | -
|
141 | | - results.push(group.validate_with_context(context)); |
142 | | - } |
143 | | -
|
144 | | - let name_context = context.with_struct("Component", "name"); |
145 | | -
|
146 | | - results.push(self.name.validate_with_context(name_context)); |
147 | | -
|
148 | | - if let Some(version) = &self.version { |
149 | | - let context = context.with_struct("Component", "version"); |
150 | | -
|
151 | | - results.push(version.validate_with_context(context)); |
152 | | - } |
153 | | -
|
154 | | - if let Some(description) = &self.description { |
155 | | - let context = context.with_struct("Component", "description"); |
156 | | -
|
157 | | - results.push(description.validate_with_context(context)); |
158 | | - } |
159 | | -
|
160 | | - if let Some(scope) = &self.scope { |
161 | | - let context = context.with_struct("Component", "scope"); |
162 | | -
|
163 | | - results.push(scope.validate_with_context(context)); |
164 | | - } |
165 | | -
|
166 | | - if let Some(hashes) = &self.hashes { |
167 | | - let context = context.with_struct("Component", "hashes"); |
168 | | -
|
169 | | - results.push(hashes.validate_with_context(context)); |
170 | | - } |
171 | | -
|
172 | | - if let Some(licenses) = &self.licenses { |
173 | | - let context = context.with_struct("Component", "licenses"); |
174 | | -
|
175 | | - results.push(licenses.validate_with_context(context)); |
176 | | - } |
177 | | -
|
178 | | - if let Some(copyright) = &self.copyright { |
179 | | - let context = context.with_struct("Component", "copyright"); |
180 | | -
|
181 | | - results.push(copyright.validate_with_context(context)); |
182 | | - } |
183 | | -
|
184 | | - if let Some(cpe) = &self.cpe { |
185 | | - let context = context.with_struct("Component", "cpe"); |
186 | | -
|
187 | | - results.push(cpe.validate_with_context(context)); |
188 | | - } |
189 | | -
|
190 | | - if let Some(purl) = &self.purl { |
191 | | - let context = context.with_struct("Component", "purl"); |
192 | | -
|
193 | | - results.push(purl.validate_with_context(context)); |
194 | | - } |
195 | | -
|
196 | | - if let Some(swid) = &self.swid { |
197 | | - let context = context.with_struct("Component", "swid"); |
198 | | -
|
199 | | - results.push(swid.validate_with_context(context)); |
200 | | - } |
201 | | -
|
202 | | - if let Some(pedigree) = &self.pedigree { |
203 | | - let context = context.with_struct("Component", "pedigree"); |
204 | | -
|
205 | | - results.push(pedigree.validate_with_context(context)); |
206 | | - } |
207 | | -
|
208 | | - if let Some(external_references) = &self.external_references { |
209 | | - let context = context.with_struct("Component", "external_references"); |
210 | | -
|
211 | | - results.push(external_references.validate_with_context(context)); |
212 | | - } |
213 | | -
|
214 | | - if let Some(properties) = &self.properties { |
215 | | - let context = context.with_struct("Component", "properties"); |
216 | | -
|
217 | | - results.push(properties.validate_with_context(context)); |
218 | | - } |
219 | | -
|
220 | | - if let Some(components) = &self.components { |
221 | | - let context = context.with_struct("Component", "components"); |
222 | | -
|
223 | | - results.push(components.validate_with_context(context)); |
224 | | - } |
225 | | -
|
226 | | - if let Some(evidence) = &self.evidence { |
227 | | - let context = context.with_struct("Component", "evidence"); |
228 | | -
|
229 | | - results.push(evidence.validate_with_context(context)); |
230 | | - } |
231 | | -
|
232 | | - results |
233 | | - .into_iter() |
234 | | - .fold(ValidationResult::default(), |acc, result| acc.merge(result)) |
235 | | -
|
236 | | - */ |
237 | 153 | } |
238 | 154 | } |
239 | 155 |
|
@@ -512,7 +428,7 @@ pub struct Copyright(pub String); |
512 | 428 | pub struct CopyrightTexts(pub(crate) Vec<Copyright>); |
513 | 429 |
|
514 | 430 | impl Validate for CopyrightTexts { |
515 | | - fn validate(&self, version: SpecVersion) -> ValidationResult { |
| 431 | + fn validate(&self, _version: SpecVersion) -> ValidationResult { |
516 | 432 | ValidationContext::new() |
517 | 433 | .add_list("inner", &self.0, validate_copyright) |
518 | 434 | .into() |
|
0 commit comments