pesde/src/source/git/specifier.rs
daimond113 51fc6c3abd
refactor: move schema gen to test
Moves schema generation over to a test instead of
as a feature. This allows us to publish the crate
since we use a schemars from Git, which is not
supported by crates.io.
2025-02-06 23:49:25 +01:00

31 lines
1 KiB
Rust

use relative_path::RelativePathBuf;
use serde::{Deserialize, Serialize};
use std::fmt::Display;
use crate::source::DependencySpecifier;
/// The specifier for a Git dependency
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(test, derive(schemars::JsonSchema))]
pub struct GitDependencySpecifier {
/// The repository of the package
#[serde(
serialize_with = "crate::util::serialize_gix_url",
deserialize_with = "crate::util::deserialize_git_like_url"
)]
#[cfg_attr(test, schemars(with = "url::Url"))]
pub repo: gix::Url,
/// The revision of the package
pub rev: String,
/// The path of the package in the repository
#[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(test, schemars(with = "Option<std::path::PathBuf>"))]
pub path: Option<RelativePathBuf>,
}
impl DependencySpecifier for GitDependencySpecifier {}
impl Display for GitDependencySpecifier {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}#{}", self.repo, self.rev)
}
}