Skip to content

Commit 18e0ca2

Browse files
committed
schema: Derive Clone on most public types
When searching through parsed vulnerabilities being able to clone them makes working with the types far easier.
1 parent 159f40c commit 18e0ca2

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/schema.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use serde::de::{self, Visitor};
33
use serde::{Deserialize, Deserializer, Serialize, Serializer};
44
/// Package identifies the code library or command that
55
/// is potentially affected by a particular vulnerability.
6-
#[derive(Debug, Serialize, Deserialize)]
7-
6+
#[derive(Debug, Serialize, Deserialize, Clone)]
87
pub struct Package {
98
/// The name of the package or dependency.
109
pub name: String,
@@ -330,7 +329,7 @@ impl<'de> Deserialize<'de> for Ecosystem {
330329

331330
/// Type of the affected range supplied. This can be an ecosystem
332331
/// specific value, semver, or a git commit hash.
333-
#[derive(Debug, Serialize, Deserialize)]
332+
#[derive(Debug, Serialize, Deserialize, Clone)]
334333
#[serde(rename_all = "UPPERCASE")]
335334
#[non_exhaustive]
336335
pub enum RangeType {
@@ -350,7 +349,7 @@ pub enum RangeType {
350349

351350
/// The event captures information about the how and when
352351
/// the package was affected by the vulnerability.
353-
#[derive(Debug, Serialize, Deserialize)]
352+
#[derive(Debug, Serialize, Deserialize, Clone)]
354353
#[serde(rename_all = "lowercase")]
355354
#[non_exhaustive]
356355
pub enum Event {
@@ -371,7 +370,7 @@ pub enum Event {
371370

372371
/// The range of versions of a package for which
373372
/// it is affected by the vulnerability.
374-
#[derive(Debug, Serialize, Deserialize)]
373+
#[derive(Debug, Serialize, Deserialize, Clone)]
375374
pub struct Range {
376375
/// The format that the range events are specified in, for
377376
/// example SEMVER or GIT.
@@ -393,7 +392,7 @@ pub struct Range {
393392
/// by a particular vulnerability. The affected ranges can include
394393
/// when the vulnerability was first introduced and also when it
395394
/// was fixed.
396-
#[derive(Debug, Serialize, Deserialize)]
395+
#[derive(Clone, Debug, Serialize, Deserialize)]
397396
pub struct Affected {
398397
/// The package that is affected by the vulnerability
399398
#[serde(skip_serializing_if = "Option::is_none")]
@@ -433,7 +432,7 @@ pub struct Affected {
433432
/// The type of reference information that has been provided. Examples include
434433
/// links to the original report, external advisories, or information about the
435434
/// fix.
436-
#[derive(Debug, Serialize, Deserialize)]
435+
#[derive(Clone, Debug, Serialize, Deserialize)]
437436
#[serde(rename_all = "UPPERCASE")]
438437
#[non_exhaustive]
439438
pub enum ReferenceType {
@@ -476,7 +475,7 @@ pub enum ReferenceType {
476475
}
477476

478477
/// Reference to additional information about the vulnerability.
479-
#[derive(Debug, Serialize, Deserialize)]
478+
#[derive(Clone, Debug, Serialize, Deserialize)]
480479
pub struct Reference {
481480
/// The type of reference this URL points to.
482481
#[serde(rename = "type")]
@@ -489,7 +488,7 @@ pub struct Reference {
489488

490489
/// The [`SeverityType`](SeverityType) describes the quantitative scoring method used to rate the
491490
/// severity of the vulnerability.
492-
#[derive(Debug, Serialize, Deserialize)]
491+
#[derive(Clone, Debug, Serialize, Deserialize)]
493492
#[non_exhaustive]
494493
pub enum SeverityType {
495494
/// A CVSS vector string representing the unique characteristics and severity of the vulnerability
@@ -518,7 +517,7 @@ pub enum SeverityType {
518517

519518
/// The type and score used to describe the severity of a vulnerability using one
520519
/// or more quantitative scoring methods.
521-
#[derive(Debug, Serialize, Deserialize)]
520+
#[derive(Clone, Debug, Serialize, Deserialize)]
522521
pub struct Severity {
523522
/// The severity type property must be a [`SeverityType`](SeverityType), which describes the
524523
/// quantitative method used to calculate the associated score.
@@ -534,7 +533,7 @@ pub struct Severity {
534533
/// the type or role of the individual or entity being credited.
535534
///
536535
/// These values and their definitions correspond directly to the [MITRE CVE specification](https://cveproject.github.io/cve-schema/schema/v5.0/docs/#collapseDescription_oneOf_i0_containers_cna_credits_items_type).
537-
#[derive(Debug, Serialize, Deserialize)]
536+
#[derive(Clone, Debug, Serialize, Deserialize)]
538537
#[serde(rename_all = "UPPERCASE")]
539538
#[non_exhaustive]
540539
pub enum CreditType {
@@ -573,7 +572,7 @@ pub enum CreditType {
573572

574573
/// Provides a way to give credit for the discovery, confirmation, patch or other events in the
575574
/// life cycle of a vulnerability.
576-
#[derive(Debug, Serialize, Deserialize)]
575+
#[derive(Clone, Debug, Serialize, Deserialize)]
577576
pub struct Credit {
578577
pub name: String,
579578
#[serde(skip_serializing_if = "Option::is_none")]
@@ -588,7 +587,7 @@ pub struct Credit {
588587
/// This is the entity that is returned when vulnerable data exists for
589588
/// a given package or when requesting information about a specific vulnerability
590589
/// by unique identifier.
591-
#[derive(Debug, Serialize, Deserialize)]
590+
#[derive(Clone, Debug, Serialize, Deserialize)]
592591
pub struct Vulnerability {
593592
/// The schema_version field is used to indicate which version of the OSV schema a particular
594593
/// vulnerability was exported with.

0 commit comments

Comments
 (0)