git_lfs_api/models.rs
1//! Types shared between the batch and locking endpoints.
2
3use serde::{Deserialize, Serialize};
4
5/// A server refspec, used by both batch and locking requests for
6/// auth schemes that take the ref into account (added in LFS v2.4).
7///
8/// See `docs/api/batch.md` § "Ref Property".
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
10pub struct Ref {
11 pub name: String,
12}
13
14impl Ref {
15 pub fn new(name: impl Into<String>) -> Self {
16 Self { name: name.into() }
17 }
18}
19
20/// User identity attached to a lock by the server.
21#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
22pub struct Owner {
23 pub name: String,
24}
25
26/// A lock record returned by the locking API.
27///
28/// `locked_at` is an uppercase RFC 3339-formatted timestamp with second
29/// precision per the spec. We carry it as a string — parsing into a typed
30/// timestamp is left to callers (avoids pulling in a date/time crate here).
31///
32/// Field order matters for `--json` output: the upstream test fixtures
33/// `grep -E` against literal `{"id":...,"path":...,"owner":...,"locked_at":...}`,
34/// and serde's derived `Serialize` follows declaration order.
35#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
36pub struct Lock {
37 pub id: String,
38 pub path: String,
39 #[serde(default, skip_serializing_if = "Option::is_none")]
40 pub owner: Option<Owner>,
41 pub locked_at: String,
42}