diff --git a/modules/fundamental/src/sbom/model/mod.rs b/modules/fundamental/src/sbom/model/mod.rs index 9400ed90..0b922449 100644 --- a/modules/fundamental/src/sbom/model/mod.rs +++ b/modules/fundamental/src/sbom/model/mod.rs @@ -1,18 +1,16 @@ pub mod details; use super::service::SbomService; -use crate::purl::model::summary::purl::PurlSummary; -use crate::source_document::model::SourceDocument; -use crate::Error; +use crate::{ + purl::model::summary::purl::PurlSummary, source_document::model::SourceDocument, Error, +}; use async_graphql::SimpleObject; -use sea_orm::prelude::Uuid; -use sea_orm::ModelTrait; +use sea_orm::{prelude::Uuid, ModelTrait, PaginatorTrait}; use serde::{Deserialize, Serialize}; use time::OffsetDateTime; -use trustify_common::db::ConnectionOrTransaction; -use trustify_common::model::Paginated; +use trustify_common::{db::ConnectionOrTransaction, model::Paginated}; use trustify_entity::{ - labels::Labels, relationship::Relationship, sbom, sbom_node, source_document, + labels::Labels, relationship::Relationship, sbom, sbom_node, sbom_package, source_document, }; use utoipa::ToSchema; @@ -64,6 +62,9 @@ pub struct SbomSummary { pub source_document: Option, pub described_by: Vec, + + /// The number of packages this SBOM has + pub number_of_packages: u64, } impl SbomSummary { @@ -72,13 +73,14 @@ impl SbomSummary { service: &SbomService, tx: &ConnectionOrTransaction<'_>, ) -> Result, Error> { - // TODO: consider improving the n-select issue here + // TODO: consider improving the n-select issues here let described_by = service .describes_packages(sbom.sbom_id, Paginated::default(), ()) .await? .items; let source_document = sbom.find_related(source_document::Entity).one(tx).await?; + let number_of_packages = sbom.find_related(sbom_package::Entity).count(tx).await?; Ok(match node { Some(_) => Some(SbomSummary { @@ -89,6 +91,7 @@ impl SbomSummary { None }, described_by, + number_of_packages, }), None => None, }) diff --git a/openapi.yaml b/openapi.yaml index 5a565064..f6cf466c 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -3021,11 +3021,17 @@ components: - type: object required: - described_by + - number_of_packages properties: described_by: type: array items: $ref: '#/components/schemas/SbomPackage' + number_of_packages: + type: integer + format: int64 + description: The number of packages this SBOM has + minimum: 0 total: type: integer format: int64 @@ -3512,11 +3518,17 @@ components: - type: object required: - described_by + - number_of_packages properties: described_by: type: array items: $ref: '#/components/schemas/SbomPackage' + number_of_packages: + type: integer + format: int64 + description: The number of packages this SBOM has + minimum: 0 Severity: type: string description: |-