Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/loader/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl LocalLoader {
) -> Result<LockedApp> {
spin_manifest::normalize::normalize_manifest(&mut manifest, profile)?;

manifest.validate_required_fields()?;
manifest.validate_dependencies()?;

let AppManifest {
Expand Down
10 changes: 10 additions & 0 deletions crates/manifest/src/schema/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct AppManifest {
///
/// Example: `[[trigger.http]]`
#[serde(rename = "trigger")]
#[serde(default)]
#[schemars(with = "json_schema::TriggerSchema")]
pub triggers: Map<String, Vec<Trigger>>,
/// `[component.<id>]`
Expand All @@ -55,6 +56,15 @@ pub struct AppManifest {
}

impl AppManifest {
/// Ensures that required fields (where not enforced in the schema) are populated.
pub fn validate_required_fields(&self) -> anyhow::Result<()> {
if self.triggers.is_empty() {
anyhow::bail!("The application must have at least one trigger");
}

Ok(())
}

/// This method ensures that the dependencies of each component are valid.
pub fn validate_dependencies(&self) -> anyhow::Result<()> {
for (component_id, component) in &self.components {
Expand Down
134 changes: 67 additions & 67 deletions examples/spin-timer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions templates/http-empty/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#:schema https://schemas.spinframework.dev/spin/manifest-v2/latest.json

spin_manifest_version = 2

[application]
Expand Down
4 changes: 2 additions & 2 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ mod integration_tests {
},
)?;

let expected = "Error: No triggers in app\n";
assert_eq!(env.runtime_mut().stderr(), expected);
let expected = "application must have at least one trigger";
assert!(env.runtime_mut().stderr().contains(expected));

Ok(())
}
Expand Down
Loading