Skip to main content

switchback_traits/model/
contract.rs

1//! Stored contract, group, and companion shapes.
2
3use std::path::PathBuf;
4
5use crate::ids::{GroupId, SpecVersion};
6use crate::model::entity::StoredEntity;
7use crate::model::manual::Source;
8
9/// Serialized contract within a [`ReferenceManual`](super::manual::ReferenceManual).
10#[derive(Clone, Debug, PartialEq, Eq)]
11pub struct ManualContract {
12    /// [`ContractFamily`](crate::traits::ContractFamily) name (e.g. `"openapi"`, `"protobuf"`).
13    pub family: String,
14    /// Parsed spec version for this contract instance.
15    pub version: SpecVersion,
16    /// Intra-contract groups (packages, tags, applications, etc.).
17    pub groups: Vec<Group>,
18    /// Companion documents embedded in the switchback artifact.
19    pub companions: Vec<Companion>,
20    /// Contract-level protocol attachments (for example server URLs).
21    pub protocols: Vec<crate::model::ProtocolAttachment>,
22}
23
24/// Intra-contract grouping unit (package, tag group, application, etc.).
25#[derive(Clone, Debug, PartialEq, Eq)]
26pub struct Group {
27    /// Stable group key within the contract ([`GroupId`]).
28    pub id: GroupId,
29    /// Output directory segment for this group under the markdown root.
30    pub dir: String,
31    /// Human-readable group title for package/overview pages.
32    pub title: String,
33    /// Optional overview prose for the group page.
34    pub overview: Option<String>,
35    /// Provenance pointer into the switchback source layer, when available.
36    pub source: Option<Source>,
37    /// Entities belonging to this group.
38    ///
39    /// Populated in the serialized switchback; empty on parser-side
40    /// [`Contract`](crate::traits::Contract) views (entities are queried separately).
41    pub entities: Vec<StoredEntity>,
42    /// Filesystem path to the contract input used for the package-page *path* line.
43    ///
44    /// Parser-local provenance only; not serialized on the wire.
45    pub source_path: PathBuf,
46}
47
48/// Companion document embedded in the switchback.
49#[derive(Clone, Debug, PartialEq, Eq)]
50pub struct Companion {
51    /// Output filename relative to the companion output directory.
52    pub output_name: String,
53    /// Raw companion file bytes.
54    pub bytes: Vec<u8>,
55    /// MIME type for the companion (e.g. `"text/markdown"`).
56    pub media_type: String,
57    /// Human nav label (first markdown heading or humanized stem).
58    pub title: String,
59    /// Logical source directory relative to corpus root (slash-separated).
60    pub source_dir: String,
61    /// Source filename stem (e.g. `README`, `MOVING-TO-V2`).
62    pub stem: String,
63}