Skip to content

Commit

Permalink
feat: add composite openapi specification and swagger ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Mar 20, 2024
1 parent 9b59ee9 commit 411c461
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 105 deletions.
59 changes: 3 additions & 56 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mod default {
}
}

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct PaginatedResults<R> {
pub items: Vec<R>,
Expand Down
14 changes: 14 additions & 0 deletions modules/graph/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use actix_web::http::StatusCode;
use actix_web::{web, HttpResponse, ResponseError};
use trustify_common::error::ErrorInformation;
use trustify_common::purl::PurlErr;
use utoipa::OpenApi;

pub fn configure(config: &mut web::ServiceConfig) {
config
Expand All @@ -16,6 +17,19 @@ pub fn configure(config: &mut web::ServiceConfig) {
.service(vulnerability::affected_products);
}

#[derive(OpenApi)]
#[openapi(
paths(
package::dependencies,
package::variants,
vulnerability::affected_packages,
vulnerability::affected_products
),
components(),
tags()
)]
pub struct ApiDoc;

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
Expand Down
20 changes: 16 additions & 4 deletions modules/graph/src/endpoints/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ pub struct PackageParams {
}

#[utoipa::path(
params(
("purl", Path, description = "Package URL to get dependencies for")
),
responses(
(status = 200, description = "Dependencies"),
),
)]
#[get("package/{purl}/dependencies")]
#[get("/package/{purl}/dependencies")]
pub async fn dependencies(
state: web::Data<Graph>,
purl: web::Path<String>,
Expand Down Expand Up @@ -53,11 +56,14 @@ pub async fn dependencies(
}

#[utoipa::path(
params(
("purl", Path, description = "Package URL to get dependencies for")
),
responses(
(status = 200, description = "Affected packages"),
),
)]
#[get("package/{purl}/dependents")]
#[get("/package/{purl}/dependents")]
pub async fn dependents(
state: web::Data<Graph>,
purl: web::Path<String>,
Expand All @@ -66,11 +72,14 @@ pub async fn dependents(
}

#[utoipa::path(
params(
("purl", Path, description = "Package URL to get dependencies for")
),
responses(
(status = 200, description = "Affected packages"),
),
)]
#[get("package/{purl}/variants")]
#[get("/package/{purl}/variants")]
pub async fn variants(
state: web::Data<Graph>,
purl: web::Path<String>,
Expand All @@ -90,11 +99,14 @@ pub async fn variants(
}

#[utoipa::path(
params(
("purl", Path, description = "Package URL to get dependencies for")
),
responses(
(status = 200, description = "Affected packages"),
),
)]
#[get("package/{purl}/vulnerabilities")]
#[get("/package/{purl}/vulnerabilities")]
pub async fn vulnerabilities(
state: web::Data<Graph>,
purl: web::Path<String>,
Expand Down
10 changes: 8 additions & 2 deletions modules/graph/src/endpoints/vulnerability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ use crate::graph::Graph;
use actix_web::{get, web, HttpResponse, Responder};

#[utoipa::path(
params(
("id", Path, description = "ID of the vulnerability")
),
responses(
(status = 200, description = "Affected packages"),
),
)]
#[get("vulnerability/{id}/affected/packages")]
#[get("/vulnerability/{id}/affected/packages")]
pub async fn affected_packages(
state: web::Data<Graph>,
id: web::Path<String>,
Expand All @@ -15,11 +18,14 @@ pub async fn affected_packages(
}

#[utoipa::path(
params(
("id", Path, description = "ID of the vulnerability")
),
responses(
(status = 200, description = "Affected products"),
),
)]
#[get("vulnerability/{id}/affected/products")]
#[get("/vulnerability/{id}/affected/products")]
pub async fn affected_products(
state: web::Data<Graph>,
id: web::Path<String>,
Expand Down
2 changes: 1 addition & 1 deletion modules/importer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ thiserror = "1"
time = { version = "0.3", features = ["serde-well-known"] }
tokio = { version = "1.30.0", features = ["full"] }
url = { version = "2.5.0", features = ["serde"] }
utoipa = { version = "4", features = ["actix_extras"] }
utoipa = { version = "4", features = ["actix_extras", "time", "url"] }
uuid = { version = "1.7.0", features = ["v4"] }
walker-common = "=0.6.0-alpha.8"
walker-extras = "=0.6.0-alpha.8"
Expand Down
Loading

0 comments on commit 411c461

Please sign in to comment.