Skip to content

cloacina-workflow::input_interface

Rust

Injectable input interface — JSON Schema generation (CLOACI-I-0128).

Canonical home for turning a Rust type into a JSON Schema descriptor and for the InputSlot contract. Lives in cloacina-workflow (not core cloacina) because the #[workflow(params(...))] macro emits calls to these helpers into packaged cdylibs, which depend on cloacina-workflow, not core. Core cloacina re-exports this module.

Spec: [CLOACI-S-0013]; descriptor decision: [CLOACI-A-0007] (JSON Schema via schemars).

  • InputSlot (cloacina_api_types::InputSlot)

pub

Opt-in schema derivation for accumulator/reactor boundary types (CLOACI-I-0128 Task D).

Unlike workflow params (whose types we control via #[workflow(params(...))]), computation-graph boundary types are defined in the author’s crate and may or may not derive schemars::JsonSchema. We do NOT want to force the derive — so the #[computation_graph] macro can’t unconditionally call schema_for (that needs the bound at compile time).

Instead the macro emits a probe over [SchemaProbe<T>] that, via autoref specialization (the stable-Rust dtolnay pattern), resolves to the real schema when T: JsonSchema and to a permissive {} (“any”) schema otherwise. Authors opt a boundary type into rich typing simply by adding #[derive(schemars::JsonSchema)]; types without it degrade to name-only slots rather than failing to compile.

Usage (what the macro emits)

{
use ::cloacina_workflow::input_interface::{ProbeTyped as _, ProbeFallback as _};
(&::cloacina_workflow::input_interface::SchemaProbe::<MyType>::new())
.probe_input_schema()
}

pub

fn new() -> Self
Source
pub fn new() -> Self {
SchemaProbe(core::marker::PhantomData)
}

pub

Specific arm of the probe: selected when T: JsonSchema (zero autorefs on a &SchemaProbe<T> receiver), yielding the real derived schema.

fn probe_input_schema(&self) -> serde_json::Value
Source
fn probe_input_schema(&self) -> serde_json::Value;

pub

Fallback arm of the probe: selected for any T (one autoref on a &SchemaProbe<T> receiver), yielding a permissive “any” schema. Method resolution prefers ProbeTyped whenever its T: JsonSchema bound holds.

fn probe_input_schema(&self) -> serde_json::Value
Source
fn probe_input_schema(&self) -> serde_json::Value;

pub

fn schema_for<T: schemars::JsonSchema>() -> serde_json::Value

Generate a JSON Schema for T as a serde_json::Value.

The macro-generated #[workflow(params(...))] descriptor calls this per declared param type; accumulator/reactor boundary derivation (Task D) calls it per boundary type. Returns Value::Null only if the generated schema fails to serialize (not expected for a well-formed JsonSchema impl).

Source
pub fn schema_for<T: schemars::JsonSchema>() -> serde_json::Value {
let root = schemars::SchemaGenerator::default().into_root_schema_for::<T>();
serde_json::to_value(root).unwrap_or(serde_json::Value::Null)
}

pub

fn default_json<T: serde::Serialize>(
value: T,
) -> Option<serde_json::Value>

Serialize a default value to serde_json::Value for an InputSlot::default. Returns None if the value can’t serialize.

Source
pub fn default_json<T: serde::Serialize>(value: T) -> Option<serde_json::Value> {
serde_json::to_value(value).ok()
}

pub

fn slots_to_json(slots: &[InputSlot]) -> String

Serialize a slot list to the JSON array string carried across the FFI descriptor entrypoint (InputInterfaceEntry::slots_json). Falls back to an empty array on serialization failure.

Source
pub fn slots_to_json(slots: &[InputSlot]) -> String {
serde_json::to_string(slots).unwrap_or_else(|_| "[]".to_string())
}