mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
feat: add lockfile schema generation
This commit is contained in:
parent
949e863cb9
commit
3738481c5b
133
crates/cargo-util-schemas/lockfile.schema.json
Normal file
133
crates/cargo-util-schemas/lockfile.schema.json
Normal file
@ -0,0 +1,133 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"title": "EncodableResolve",
|
||||
"description": "The `Cargo.lock` structure.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"version": {
|
||||
"type": [
|
||||
"integer",
|
||||
"null"
|
||||
],
|
||||
"format": "uint32",
|
||||
"minimum": 0
|
||||
},
|
||||
"package": {
|
||||
"type": [
|
||||
"array",
|
||||
"null"
|
||||
],
|
||||
"items": {
|
||||
"$ref": "#/$defs/EncodableDependency"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"description": "`root` is optional to allow backward compatibility.",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/$defs/EncodableDependency"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"type": [
|
||||
"object",
|
||||
"null"
|
||||
],
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"patch": {
|
||||
"$ref": "#/$defs/Patch"
|
||||
}
|
||||
},
|
||||
"$defs": {
|
||||
"EncodableDependency": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"version": {
|
||||
"type": "string"
|
||||
},
|
||||
"source": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"checksum": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"type": [
|
||||
"array",
|
||||
"null"
|
||||
],
|
||||
"items": {
|
||||
"$ref": "#/$defs/EncodablePackageId"
|
||||
}
|
||||
},
|
||||
"replace": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/$defs/EncodablePackageId"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"version"
|
||||
]
|
||||
},
|
||||
"EncodablePackageId": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"version": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"source": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name"
|
||||
]
|
||||
},
|
||||
"Patch": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"unused": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/$defs/EncodableDependency"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"unused"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ use crate::core::{GitReference, SourceKind};
|
||||
|
||||
/// The `Cargo.lock` structure.
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
|
||||
pub struct EncodableResolve {
|
||||
pub version: Option<u32>,
|
||||
pub package: Option<Vec<EncodableDependency>>,
|
||||
@ -20,6 +21,7 @@ pub struct EncodableResolve {
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
|
||||
pub struct Patch {
|
||||
pub unused: Vec<EncodableDependency>,
|
||||
}
|
||||
@ -33,6 +35,7 @@ impl Patch {
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialOrd, Ord, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
|
||||
pub struct EncodableDependency {
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
@ -43,6 +46,11 @@ pub struct EncodableDependency {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(
|
||||
feature = "unstable-schema",
|
||||
derive(schemars::JsonSchema),
|
||||
schemars(with = "String")
|
||||
)]
|
||||
pub struct EncodableSourceId {
|
||||
/// Full string of the source
|
||||
source_str: String,
|
||||
@ -150,6 +158,7 @@ impl Ord for EncodableSourceId {
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Hash, Clone)]
|
||||
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
|
||||
pub struct EncodablePackageId {
|
||||
pub name: String,
|
||||
pub version: Option<String>,
|
||||
@ -253,3 +262,11 @@ enum EncodablePackageIdErrorKind {
|
||||
#[error(transparent)]
|
||||
Source(#[from] EncodableSourceIdError),
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-schema")]
|
||||
#[test]
|
||||
fn dump_lockfile_schema() {
|
||||
let schema = schemars::schema_for!(crate::lockfile::EncodableResolve);
|
||||
let dump = serde_json::to_string_pretty(&schema).unwrap();
|
||||
snapbox::assert_data_eq!(dump, snapbox::file!("../lockfile.schema.json").raw());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user