spin_manifest/schema/
v1.rsuse serde::Deserialize;
use spin_serde::FixedStringVersion;
pub use super::common::{
ComponentBuildConfig as ComponentBuildConfigV1, ComponentSource as ComponentSourceV1,
Variable as VariableV1, WasiFilesMount as WasiFilesMountV1,
};
type Map<K, V> = indexmap::IndexMap<K, V>;
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AppManifestV1 {
#[serde(alias = "spin_version")]
#[allow(dead_code)]
spin_manifest_version: FixedStringVersion<1>,
pub name: String,
#[serde(default)]
pub version: String,
#[serde(default)]
pub description: String,
#[serde(default)]
pub authors: Vec<String>,
pub trigger: AppTriggerV1,
#[serde(default)]
pub variables: Map<String, VariableV1>,
#[serde(rename = "component")]
#[serde(default)]
pub components: Vec<ComponentV1>,
}
#[derive(Deserialize)]
pub struct AppTriggerV1 {
#[serde(rename = "type")]
pub trigger_type: String,
#[serde(flatten)]
pub config: toml::Table,
}
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ComponentV1 {
pub id: String,
pub source: ComponentSourceV1,
pub trigger: toml::Table,
#[serde(default)]
pub description: String,
#[serde(default)]
pub config: Map<String, String>,
#[serde(default)]
pub environment: Map<String, String>,
#[serde(default)]
pub files: Vec<WasiFilesMountV1>,
#[serde(default)]
pub exclude_files: Vec<String>,
#[serde(default)]
pub allowed_http_hosts: Vec<String>,
#[serde(default)]
pub allowed_outbound_hosts: Option<Vec<String>>,
#[serde(default)]
pub key_value_stores: Vec<String>,
#[serde(default)]
pub sqlite_databases: Vec<String>,
#[serde(default)]
pub ai_models: Vec<String>,
#[serde(default)]
pub build: Option<ComponentBuildConfigV1>,
}
#[cfg(test)]
mod tests {
use toml::toml;
use super::*;
#[derive(Deserialize)]
#[allow(dead_code)]
struct FakeGlobalTriggerConfig {
global_option: bool,
}
#[derive(Deserialize)]
#[allow(dead_code)]
struct FakeTriggerConfig {
option: Option<bool>,
}
#[test]
fn deserializing_trigger_configs() {
let manifest = AppManifestV1::deserialize(toml! {
spin_manifest_version = "1"
name = "trigger-configs"
trigger = { type = "fake", global_option = true }
[[component]]
id = "my-component"
source = "example.wasm"
[component.trigger]
option = true
})
.unwrap();
FakeGlobalTriggerConfig::deserialize(manifest.trigger.config).unwrap();
FakeTriggerConfig::deserialize(manifest.components[0].trigger.clone()).unwrap();
}
}