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.
This commit is contained in:
daimond113 2025-02-06 23:49:25 +01:00
parent c698969f76
commit 51fc6c3abd
No known key found for this signature in database
GPG key ID: 640DC95EC1190354
15 changed files with 65 additions and 61 deletions

3
.gitignore vendored
View file

@ -5,4 +5,5 @@ cobertura.xml
tarpaulin-report.html tarpaulin-report.html
build_rs_cov.profraw build_rs_cov.profraw
registry/data registry/data
data data
manifest.schema.json

View file

@ -10,6 +10,7 @@ repository = "https://github.com/pesde-pkg/pesde"
include = ["src/**/*", "Cargo.toml", "Cargo.lock", "README.md", "LICENSE", "CHANGELOG.md"] include = ["src/**/*", "Cargo.toml", "Cargo.lock", "README.md", "LICENSE", "CHANGELOG.md"]
[features] [features]
default = ["wally-compat", "patches", "version-management"]
bin = [ bin = [
"dep:clap", "dep:clap",
"dep:dirs", "dep:dirs",
@ -34,7 +35,6 @@ bin = [
wally-compat = ["dep:serde_json"] wally-compat = ["dep:serde_json"]
patches = ["dep:git2"] patches = ["dep:git2"]
version-management = ["bin"] version-management = ["bin"]
schema = ["dep:schemars"]
[[bin]] [[bin]]
name = "pesde" name = "pesde"
@ -75,8 +75,6 @@ git2 = { version = "0.20.0", optional = true }
serde_json = { version = "1.0.136", optional = true } serde_json = { version = "1.0.136", optional = true }
schemars = { git = "https://github.com/daimond113/schemars", rev = "bc7c7d6", features = ["semver1", "url2"], optional = true }
anyhow = { version = "1.0.95", optional = true } anyhow = { version = "1.0.95", optional = true }
open = { version = "5.3.2", optional = true } open = { version = "5.3.2", optional = true }
keyring = { version = "3.6.1", features = ["crypto-rust", "windows-native", "apple-native", "async-secret-service", "tokio"], optional = true } keyring = { version = "3.6.1", features = ["crypto-rust", "windows-native", "apple-native", "async-secret-service", "tokio"], optional = true }
@ -93,6 +91,9 @@ paste = { version = "1.0.15", optional = true }
windows-registry = { version = "0.4.0", optional = true } windows-registry = { version = "0.4.0", optional = true }
windows = { version = "0.59.0", features = ["Win32_Storage", "Win32_Storage_FileSystem", "Win32_Security"], optional = true } windows = { version = "0.59.0", features = ["Win32_Storage", "Win32_Storage_FileSystem", "Win32_Security"], optional = true }
[dev-dependencies]
schemars = { git = "https://github.com/daimond113/schemars", rev = "bc7c7d6", features = ["semver1", "url2"] }
[workspace] [workspace]
resolver = "2" resolver = "2"
members = ["registry"] members = ["registry"]

View file

@ -48,4 +48,4 @@ tracing-actix-web = "0.7.15"
sentry = { version = "0.36.0", default-features = false, features = ["backtrace", "contexts", "debug-images", "panic", "reqwest", "rustls", "tracing"] } sentry = { version = "0.36.0", default-features = false, features = ["backtrace", "contexts", "debug-images", "panic", "reqwest", "rustls", "tracing"] }
sentry-actix = "0.36.0" sentry-actix = "0.36.0"
pesde = { path = "..", features = ["wally-compat"] } pesde = { path = "..", default-features = false, features = ["wally-compat"] }

View file

@ -6,8 +6,8 @@ use std::{fmt::Display, str::FromStr};
/// All supported engines /// All supported engines
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schema", schemars(rename_all = "snake_case"))] #[cfg_attr(test, schemars(rename_all = "snake_case"))]
pub enum EngineKind { pub enum EngineKind {
/// The pesde package manager /// The pesde package manager
Pesde, Pesde,

View file

@ -25,7 +25,7 @@ pub mod target;
/// A package manifest /// A package manifest
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
pub struct Manifest { pub struct Manifest {
/// The name of the package /// The name of the package
pub name: PackageName, pub name: PackageName,
@ -50,10 +50,7 @@ pub struct Manifest {
pub private: bool, pub private: bool,
/// The scripts of the package /// The scripts of the package
#[serde(default, skip_serializing)] #[serde(default, skip_serializing)]
#[cfg_attr( #[cfg_attr(test, schemars(with = "BTreeMap<String, std::path::PathBuf>"))]
feature = "schema",
schemars(with = "BTreeMap<String, std::path::PathBuf>")
)]
pub scripts: BTreeMap<String, RelativePathBuf>, pub scripts: BTreeMap<String, RelativePathBuf>,
/// The indices to use for the package /// The indices to use for the package
#[serde( #[serde(
@ -61,7 +58,7 @@ pub struct Manifest {
skip_serializing, skip_serializing,
deserialize_with = "crate::util::deserialize_gix_url_map" deserialize_with = "crate::util::deserialize_gix_url_map"
)] )]
#[cfg_attr(feature = "schema", schemars(with = "BTreeMap<String, url::Url>"))] #[cfg_attr(test, schemars(with = "BTreeMap<String, url::Url>"))]
pub indices: BTreeMap<String, gix::Url>, pub indices: BTreeMap<String, gix::Url>,
/// The indices to use for the package's wally dependencies /// The indices to use for the package's wally dependencies
#[cfg(feature = "wally-compat")] #[cfg(feature = "wally-compat")]
@ -70,7 +67,7 @@ pub struct Manifest {
skip_serializing, skip_serializing,
deserialize_with = "crate::util::deserialize_gix_url_map" deserialize_with = "crate::util::deserialize_gix_url_map"
)] )]
#[cfg_attr(feature = "schema", schemars(with = "BTreeMap<String, url::Url>"))] #[cfg_attr(test, schemars(with = "BTreeMap<String, url::Url>"))]
pub wally_indices: BTreeMap<String, gix::Url>, pub wally_indices: BTreeMap<String, gix::Url>,
/// The overrides this package has /// The overrides this package has
#[serde(default, skip_serializing)] #[serde(default, skip_serializing)]
@ -82,7 +79,7 @@ pub struct Manifest {
#[cfg(feature = "patches")] #[cfg(feature = "patches")]
#[serde(default, skip_serializing)] #[serde(default, skip_serializing)]
#[cfg_attr( #[cfg_attr(
feature = "schema", test,
schemars( schemars(
with = "BTreeMap<crate::names::PackageNames, BTreeMap<crate::source::ids::VersionId, std::path::PathBuf>>" with = "BTreeMap<crate::names::PackageNames, BTreeMap<crate::source::ids::VersionId, std::path::PathBuf>>"
) )
@ -99,7 +96,7 @@ pub struct Manifest {
pub place: BTreeMap<target::RobloxPlaceKind, String>, pub place: BTreeMap<target::RobloxPlaceKind, String>,
/// The engines this package supports /// The engines this package supports
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
#[cfg_attr(feature = "schema", schemars(with = "BTreeMap<EngineKind, String>"))] #[cfg_attr(test, schemars(with = "BTreeMap<EngineKind, String>"))]
pub engines: BTreeMap<EngineKind, VersionReq>, pub engines: BTreeMap<EngineKind, VersionReq>,
/// The standard dependencies of the package /// The standard dependencies of the package
@ -112,7 +109,7 @@ pub struct Manifest {
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub dev_dependencies: BTreeMap<Alias, DependencySpecifiers>, pub dev_dependencies: BTreeMap<Alias, DependencySpecifiers>,
/// The user-defined fields of the package /// The user-defined fields of the package
#[cfg_attr(feature = "schema", schemars(skip))] #[cfg_attr(test, schemars(skip))]
#[serde(flatten)] #[serde(flatten)]
pub user_defined_fields: HashMap<String, toml::Value>, pub user_defined_fields: HashMap<String, toml::Value>,
} }
@ -151,7 +148,7 @@ impl FromStr for Alias {
} }
} }
#[cfg(feature = "schema")] #[cfg(test)]
impl schemars::JsonSchema for Alias { impl schemars::JsonSchema for Alias {
fn schema_name() -> std::borrow::Cow<'static, str> { fn schema_name() -> std::borrow::Cow<'static, str> {
"Alias".into() "Alias".into()
@ -249,3 +246,14 @@ pub mod errors {
AliasConflict(Alias), AliasConflict(Alias),
} }
} }
#[cfg(test)]
mod tests {
#[test]
pub fn generate_schema() {
let schema = schemars::schema_for!(super::Manifest);
let schema = serde_json::to_string_pretty(&schema).unwrap();
std::fs::write("manifest.schema.json", schema).unwrap();
}
}

View file

@ -32,7 +32,7 @@ impl FromStr for OverrideKey {
} }
} }
#[cfg(feature = "schema")] #[cfg(test)]
impl schemars::JsonSchema for OverrideKey { impl schemars::JsonSchema for OverrideKey {
fn schema_name() -> std::borrow::Cow<'static, str> { fn schema_name() -> std::borrow::Cow<'static, str> {
"OverrideKey".into() "OverrideKey".into()
@ -68,7 +68,7 @@ impl Display for OverrideKey {
/// A specifier for an override /// A specifier for an override
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
#[serde(untagged)] #[serde(untagged)]
pub enum OverrideSpecifier { pub enum OverrideSpecifier {
/// A specifier for a dependency /// A specifier for a dependency

View file

@ -9,8 +9,8 @@ use std::{
/// A kind of target /// A kind of target
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schema", schemars(rename_all = "snake_case"))] #[cfg_attr(test, schemars(rename_all = "snake_case"))]
pub enum TargetKind { pub enum TargetKind {
/// A Roblox target /// A Roblox target
Roblox, Roblox,
@ -78,14 +78,14 @@ impl TargetKind {
/// A target of a package /// A target of a package
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case", tag = "environment")] #[serde(rename_all = "snake_case", tag = "environment")]
pub enum Target { pub enum Target {
/// A Roblox target /// A Roblox target
Roblox { Roblox {
/// The path to the lib export file /// The path to the lib export file
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "schema", schemars(with = "Option<std::path::PathBuf>"))] #[cfg_attr(test, schemars(with = "Option<std::path::PathBuf>"))]
lib: Option<RelativePathBuf>, lib: Option<RelativePathBuf>,
/// The files to include in the sync tool's config /// The files to include in the sync tool's config
#[serde(default)] #[serde(default)]
@ -95,7 +95,7 @@ pub enum Target {
RobloxServer { RobloxServer {
/// The path to the lib export file /// The path to the lib export file
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "schema", schemars(with = "Option<std::path::PathBuf>"))] #[cfg_attr(test, schemars(with = "Option<std::path::PathBuf>"))]
lib: Option<RelativePathBuf>, lib: Option<RelativePathBuf>,
/// The files to include in the sync tool's config /// The files to include in the sync tool's config
#[serde(default)] #[serde(default)]
@ -105,36 +105,30 @@ pub enum Target {
Lune { Lune {
/// The path to the lib export file /// The path to the lib export file
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "schema", schemars(with = "Option<std::path::PathBuf>"))] #[cfg_attr(test, schemars(with = "Option<std::path::PathBuf>"))]
lib: Option<RelativePathBuf>, lib: Option<RelativePathBuf>,
/// The path to the bin export file /// The path to the bin export file
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "schema", schemars(with = "Option<std::path::PathBuf>"))] #[cfg_attr(test, schemars(with = "Option<std::path::PathBuf>"))]
bin: Option<RelativePathBuf>, bin: Option<RelativePathBuf>,
/// The exported scripts /// The exported scripts
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
#[cfg_attr( #[cfg_attr(test, schemars(with = "BTreeMap<String, std::path::PathBuf>"))]
feature = "schema",
schemars(with = "BTreeMap<String, std::path::PathBuf>")
)]
scripts: BTreeMap<String, RelativePathBuf>, scripts: BTreeMap<String, RelativePathBuf>,
}, },
/// A Luau target /// A Luau target
Luau { Luau {
/// The path to the lib export file /// The path to the lib export file
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "schema", schemars(with = "Option<std::path::PathBuf>"))] #[cfg_attr(test, schemars(with = "Option<std::path::PathBuf>"))]
lib: Option<RelativePathBuf>, lib: Option<RelativePathBuf>,
/// The path to the bin export file /// The path to the bin export file
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "schema", schemars(with = "Option<std::path::PathBuf>"))] #[cfg_attr(test, schemars(with = "Option<std::path::PathBuf>"))]
bin: Option<RelativePathBuf>, bin: Option<RelativePathBuf>,
/// The exported scripts /// The exported scripts
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
#[cfg_attr( #[cfg_attr(test, schemars(with = "BTreeMap<String, std::path::PathBuf>"))]
feature = "schema",
schemars(with = "BTreeMap<String, std::path::PathBuf>")
)]
scripts: BTreeMap<String, RelativePathBuf>, scripts: BTreeMap<String, RelativePathBuf>,
}, },
} }
@ -197,7 +191,7 @@ impl Display for Target {
/// The kind of a Roblox place property /// The kind of a Roblox place property
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum RobloxPlaceKind { pub enum RobloxPlaceKind {
/// The shared dependencies location /// The shared dependencies location

View file

@ -72,7 +72,7 @@ impl Display for PackageName {
} }
} }
#[cfg(feature = "schema")] #[cfg(test)]
impl schemars::JsonSchema for PackageName { impl schemars::JsonSchema for PackageName {
fn schema_name() -> std::borrow::Cow<'static, str> { fn schema_name() -> std::borrow::Cow<'static, str> {
"PackageName".into() "PackageName".into()
@ -110,8 +110,8 @@ impl PackageName {
/// All possible package names /// All possible package names
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schema", schemars(untagged))] #[cfg_attr(test, schemars(untagged))]
pub enum PackageNames { pub enum PackageNames {
/// A pesde package name /// A pesde package name
Pesde(PackageName), Pesde(PackageName),
@ -243,7 +243,7 @@ pub mod wally {
} }
} }
#[cfg(feature = "schema")] #[cfg(test)]
impl schemars::JsonSchema for WallyPackageName { impl schemars::JsonSchema for WallyPackageName {
fn schema_name() -> std::borrow::Cow<'static, str> { fn schema_name() -> std::borrow::Cow<'static, str> {
"WallyPackageName".into() "WallyPackageName".into()

View file

@ -6,20 +6,20 @@ use crate::source::DependencySpecifier;
/// The specifier for a Git dependency /// The specifier for a Git dependency
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
pub struct GitDependencySpecifier { pub struct GitDependencySpecifier {
/// The repository of the package /// The repository of the package
#[serde( #[serde(
serialize_with = "crate::util::serialize_gix_url", serialize_with = "crate::util::serialize_gix_url",
deserialize_with = "crate::util::deserialize_git_like_url" deserialize_with = "crate::util::deserialize_git_like_url"
)] )]
#[cfg_attr(feature = "schema", schemars(with = "url::Url"))] #[cfg_attr(test, schemars(with = "url::Url"))]
pub repo: gix::Url, pub repo: gix::Url,
/// The revision of the package /// The revision of the package
pub rev: String, pub rev: String,
/// The path of the package in the repository /// The path of the package in the repository
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "schema", schemars(with = "Option<std::path::PathBuf>"))] #[cfg_attr(test, schemars(with = "Option<std::path::PathBuf>"))]
pub path: Option<RelativePathBuf>, pub path: Option<RelativePathBuf>,
} }
impl DependencySpecifier for GitDependencySpecifier {} impl DependencySpecifier for GitDependencySpecifier {}

View file

@ -60,7 +60,7 @@ impl FromStr for VersionId {
} }
} }
#[cfg(feature = "schema")] #[cfg(test)]
impl schemars::JsonSchema for VersionId { impl schemars::JsonSchema for VersionId {
fn schema_name() -> std::borrow::Cow<'static, str> { fn schema_name() -> std::borrow::Cow<'static, str> {
"VersionId".into() "VersionId".into()

View file

@ -4,7 +4,7 @@ use std::{fmt::Display, path::PathBuf};
/// The specifier for a path dependency /// The specifier for a path dependency
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
pub struct PathDependencySpecifier { pub struct PathDependencySpecifier {
/// The path to the package /// The path to the package
pub path: PathBuf, pub path: PathBuf,

View file

@ -5,12 +5,12 @@ use std::fmt::Display;
/// The specifier for a pesde dependency /// The specifier for a pesde dependency
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
pub struct PesdeDependencySpecifier { pub struct PesdeDependencySpecifier {
/// The name of the package /// The name of the package
pub name: PackageName, pub name: PackageName,
/// The version requirement for the package /// The version requirement for the package
#[cfg_attr(feature = "schema", schemars(with = "String"))] #[cfg_attr(test, schemars(with = "String"))]
pub version: VersionReq, pub version: VersionReq,
/// The index to use for the package /// The index to use for the package
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]

View file

@ -4,7 +4,7 @@ use std::fmt::Display;
/// All possible dependency specifiers /// All possible dependency specifiers
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
#[serde(untagged)] #[serde(untagged)]
pub enum DependencySpecifiers { pub enum DependencySpecifiers {
/// A pesde dependency specifier /// A pesde dependency specifier

View file

@ -7,13 +7,13 @@ use crate::{names::wally::WallyPackageName, source::DependencySpecifier};
/// The specifier for a Wally dependency /// The specifier for a Wally dependency
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
pub struct WallyDependencySpecifier { pub struct WallyDependencySpecifier {
/// The name of the package /// The name of the package
#[serde(rename = "wally")] #[serde(rename = "wally")]
pub name: WallyPackageName, pub name: WallyPackageName,
/// The version requirement for the package /// The version requirement for the package
#[cfg_attr(feature = "schema", schemars(with = "String"))] #[cfg_attr(test, schemars(with = "String"))]
pub version: VersionReq, pub version: VersionReq,
/// The index to use for the package /// The index to use for the package
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]

View file

@ -7,7 +7,7 @@ use std::{fmt::Display, str::FromStr};
/// The specifier for a workspace dependency /// The specifier for a workspace dependency
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
pub struct WorkspaceDependencySpecifier { pub struct WorkspaceDependencySpecifier {
/// The name of the workspace package /// The name of the workspace package
#[serde(rename = "workspace")] #[serde(rename = "workspace")]
@ -28,20 +28,20 @@ impl Display for WorkspaceDependencySpecifier {
/// The type of version to use when publishing a package /// The type of version to use when publishing a package
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
pub enum VersionType { pub enum VersionType {
/// The "^" version type /// The "^" version type
#[default] #[default]
#[cfg_attr(feature = "schema", schemars(rename = "^"))] #[cfg_attr(test, schemars(rename = "^"))]
Caret, Caret,
/// The "~" version type /// The "~" version type
#[cfg_attr(feature = "schema", schemars(rename = "~"))] #[cfg_attr(test, schemars(rename = "~"))]
Tilde, Tilde,
/// The "=" version type /// The "=" version type
#[cfg_attr(feature = "schema", schemars(rename = "="))] #[cfg_attr(test, schemars(rename = "="))]
Exact, Exact,
/// The "*" version type /// The "*" version type
#[cfg_attr(feature = "schema", schemars(rename = "*"))] #[cfg_attr(test, schemars(rename = "*"))]
Wildcard, Wildcard,
} }
ser_display_deser_fromstr!(VersionType); ser_display_deser_fromstr!(VersionType);
@ -75,13 +75,13 @@ impl FromStr for VersionType {
/// Either a version type or a version requirement /// Either a version type or a version requirement
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(test, derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schema", schemars(untagged))] #[cfg_attr(test, schemars(untagged))]
pub enum VersionTypeOrReq { pub enum VersionTypeOrReq {
/// A version type /// A version type
VersionType(VersionType), VersionType(VersionType),
/// A version requirement /// A version requirement
#[cfg_attr(feature = "schema", schemars(with = "String"))] #[cfg_attr(test, schemars(with = "String"))]
Req(semver::VersionReq), Req(semver::VersionReq),
} }
ser_display_deser_fromstr!(VersionTypeOrReq); ser_display_deser_fromstr!(VersionTypeOrReq);