Skip to main content

rustferry_remote/
schema.rs

1//! JSON Schema generation for Ferry Remote Build Protocol v1.
2
3use schemars::{JsonSchema, schema_for};
4
5use crate::{
6    ArtifactDownloadRequest, ArtifactDownloadResult, ArtifactListRequest, ArtifactManifest,
7    CancellationAck, CancellationRequest, CleanupConfirmation, CleanupRequest, CompileHandoff,
8    CompilePhaseEvidence, EventPage, EventRequest, GitSnapshotDescriptor, HandshakeRequest,
9    HandshakeResponse, IosDeviceBuildRequest, IosDeviceBuildResult, JobHandle,
10    ProviderDoctorReport, ProviderDoctorRequest, RemoteBuildEvent, SealedUnsignedArchive,
11    SnapshotArtifactDescriptor, SnapshotArtifactReceipt, SnapshotBuildComplete, SnapshotBuildStart,
12    SnapshotJobAccepted, SnapshotSessionError, SourceBundleDescriptor,
13};
14
15/// Every standalone document exchanged or persisted by protocol v1.
16///
17/// The generated schema is a catalog expressed as `anyOf`; transport operations still determine
18/// which concrete document is valid at each boundary.
19#[derive(JsonSchema)]
20#[schemars(title = "Ferry Remote Build Protocol v1", untagged)]
21#[allow(clippy::large_enum_variant)]
22pub enum RemoteProtocolV1Document {
23    /// Client-to-provider compatibility request.
24    HandshakeRequest(HandshakeRequest),
25    /// Provider-to-client compatibility response.
26    HandshakeResponse(HandshakeResponse),
27    /// Client-to-provider readiness request.
28    ProviderDoctorRequest(ProviderDoctorRequest),
29    /// Provider-to-client readiness report.
30    ProviderDoctorReport(ProviderDoctorReport),
31    /// Declarative physical-iPhone build request.
32    IosDeviceBuildRequest(IosDeviceBuildRequest),
33    /// Complete public compile-to-sign handoff.
34    CompileHandoff(CompileHandoff),
35    /// Initial declaration for one SSH snapshot session.
36    SnapshotBuildStart(SnapshotBuildStart),
37    /// Separately framed deterministic source descriptor.
38    SourceBundleDescriptor(SourceBundleDescriptor),
39    /// Operation-bound descriptor for one GitHub dirty-source snapshot.
40    GitSnapshotDescriptor(GitSnapshotDescriptor),
41    /// Worker acknowledgement for one snapshot job.
42    SnapshotJobAccepted(SnapshotJobAccepted),
43    /// Unsigned archive descriptor and compile evidence.
44    SnapshotArtifactDescriptor(SnapshotArtifactDescriptor),
45    /// Client proof of durable independent artifact verification.
46    SnapshotArtifactReceipt(SnapshotArtifactReceipt),
47    /// Terminal non-retaining snapshot cleanup proof.
48    SnapshotBuildComplete(SnapshotBuildComplete),
49    /// Secret-free terminal snapshot failure.
50    SnapshotSessionError(SnapshotSessionError),
51    /// Public credential-free compile evidence.
52    CompilePhaseEvidence(CompilePhaseEvidence),
53    /// Sealed unsigned archive descriptor.
54    SealedUnsignedArchive(SealedUnsignedArchive),
55    /// Accepted provider job handle.
56    JobHandle(JobHandle),
57    /// One NDJSON event envelope.
58    RemoteBuildEvent(RemoteBuildEvent),
59    /// Bounded event page.
60    EventPage(EventPage),
61    /// Event-page request.
62    EventRequest(EventRequest),
63    /// Cancellation request.
64    CancellationRequest(CancellationRequest),
65    /// Cancellation acknowledgement.
66    CancellationAck(CancellationAck),
67    /// Artifact-list request.
68    ArtifactListRequest(ArtifactListRequest),
69    /// Artifact download request.
70    ArtifactDownloadRequest(ArtifactDownloadRequest),
71    /// Verified artifact download result.
72    ArtifactDownloadResult(ArtifactDownloadResult),
73    /// Provider cleanup request.
74    CleanupRequest(CleanupRequest),
75    /// Provider cleanup proof.
76    CleanupConfirmation(CleanupConfirmation),
77    /// Terminal build result.
78    IosDeviceBuildResult(IosDeviceBuildResult),
79    /// Persisted artifact provenance and integrity manifest.
80    ArtifactManifest(ArtifactManifest),
81}
82
83/// Generate deterministic pretty-printed JSON Schema for protocol v1.
84///
85/// # Errors
86///
87/// Returns a serialization error if the in-memory schema cannot be encoded as JSON.
88pub fn protocol_v1_schema_json() -> Result<String, serde_json::Error> {
89    let mut json = serde_json::to_string_pretty(&schema_for!(RemoteProtocolV1Document))?;
90    json.push('\n');
91    Ok(json)
92}