Skip to main content

spin_manifest/schema/v2/
dependency.rs

1use std::path::PathBuf;
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use spin_serde::KebabId;
6
7/// Specifies how to satisfy an import dependency of the component. This may be one of:
8///
9/// - A semantic versioning constraint for the package version to use. Spin fetches the latest matching version of the package whose name matches the dependency name from the default registry.
10///
11/// Example: `"my:dep/import" = ">= 0.1.0"`
12///
13/// - A package from a registry.
14///
15/// Example: `"my:dep/import" = { version = "0.1.0", registry = "registry.io", ...}`
16///
17/// - A package from a filesystem path.
18///
19/// Example: `"my:dependency" = { path = "path/to/component.wasm", export = "my-export" }`
20///
21/// - A component in the application. The referenced component binary is composed: additional
22///   configuration such as files, networking, storage, etc. are ignored. This is intended
23///   primarily as a convenience for including dependencies in the manifest so that they
24///   can be built using `spin build`.
25///
26/// Example: `"my:dependency" = { component = "my-dependency", export = "my-export" }`
27///
28/// - A package from an HTTP URL.
29///
30/// Example: `"my:import" = { url = "https://example.com/component.wasm", sha256 = "sha256:..." }`
31///
32/// Learn more: https://spinframework.dev/v3/writing-apps#using-component-dependencies
33#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
34#[serde(untagged, deny_unknown_fields)]
35pub enum ComponentDependency {
36    /// `... = ">= 0.1.0"`
37    #[schemars(description = "")] // schema docs are on the parent
38    Version(String),
39    /// `... = { version = "0.1.0", registry = "registry.io", ...}`
40    #[schemars(description = "")] // schema docs are on the parent
41    Package {
42        /// A semantic versioning constraint for the package version to use. Required. Spin
43        /// fetches the latest matching version from the specified registry, or from
44        /// the default registry if no registry is specified.
45        ///
46        /// Example: `"my:dep/import" = { version = ">= 0.1.0" }`
47        ///
48        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-registry
49        version: String,
50        /// The registry that hosts the package. If omitted, this defaults to your
51        /// system default registry.
52        ///
53        /// Example: `"my:dep/import" = { registry = "registry.io", version = "0.1.0" }`
54        ///
55        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-registry
56        registry: Option<String>,
57        /// The name of the package to use. If omitted, this defaults to the package name of the
58        /// imported interface.
59        ///
60        /// Example: `"my:dep/import" = { package = "your:implementation", version = "0.1.0" }`
61        ///
62        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-registry
63        package: Option<String>,
64        /// The name of the export in the package. If omitted, this defaults to the name of the import.
65        ///
66        /// Example: `"my:dep/import" = { export = "your:impl/export", version = "0.1.0" }`
67        ///
68        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-registry
69        export: Option<String>,
70        /// The set of configurations to inherit from the parent component. If omitted or set to `false`,
71        /// no configurations will be inherited. If `true`, all configurations will be inherited.
72        /// Selective inheritance can be specified by enumerating the configuration keys the dependency
73        /// would like to inherit.
74        ///
75        /// Examples:
76        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = true }`
77        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = ["ai_models", "allowed_outbound_hosts"] }`
78        inherit_configuration: Option<InheritConfiguration>,
79    },
80    /// `... = { path = "path/to/component.wasm", export = "my-export" }`
81    #[schemars(description = "")] // schema docs are on the parent
82    Local {
83        /// The path to the Wasm file that implements the dependency.
84        ///
85        /// Example: `"my:dep/import" = { path = "path/to/component.wasm" }`
86        ///
87        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-local-component
88        path: PathBuf,
89        /// The name of the export in the package. If omitted, this defaults to the name of the import.
90        ///
91        /// Example: `"my:dep/import" = { export = "your:impl/export", path = "path/to/component.wasm" }`
92        ///
93        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-local-component
94        export: Option<String>,
95        /// The set of configurations to inherit from the parent component. If omitted or set to `false`,
96        /// no configurations will be inherited. If `true`, all configurations will be inherited.
97        /// Selective inheritance can be specified by enumerating the configuration keys the dependency
98        /// would like to inherit.
99        ///
100        /// Examples:
101        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = true }`
102        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = ["ai_models", "allowed_outbound_hosts"] }`
103        inherit_configuration: Option<InheritConfiguration>,
104    },
105    /// `... = { url = "https://example.com/component.wasm", sha256 = "..." }`
106    #[schemars(description = "")] // schema docs are on the parent
107    HTTP {
108        /// The URL to the Wasm component that implements the dependency.
109        ///
110        /// Example: `"my:dep/import" = { url = "https://example.com/component.wasm", sha256 = "sha256:..." }`
111        ///
112        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-url
113        url: String,
114        /// The SHA256 digest of the Wasm file. This is required for integrity checking. Must begin with `sha256:`.
115        ///
116        /// Example: `"my:dep/import" = { sha256 = "sha256:...", ... }`
117        ///
118        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-url
119        digest: String,
120        /// The name of the export in the package. If omitted, this defaults to the name of the import.
121        ///
122        /// Example: `"my:dep/import" = { export = "your:impl/export", ... }`
123        ///
124        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-url
125        export: Option<String>,
126        /// The set of configurations to inherit from the parent component. If omitted or set to `false`,
127        /// no configurations will be inherited. If `true`, all configurations will be inherited.
128        /// Selective inheritance can be specified by enumerating the configuration keys the dependency
129        /// would like to inherit.
130        ///
131        /// Examples:
132        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = true }`
133        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = ["ai_models", "allowed_outbound_hosts"] }`
134        inherit_configuration: Option<InheritConfiguration>,
135    },
136    /// `... = { component = "my-dependency" }`
137    #[schemars(description = "")] // schema docs are on the parent
138    AppComponent {
139        /// The ID of the component which implements the dependency.
140        ///
141        /// Example: `"my:dep/import" = { component = "my-dependency" }`
142        ///
143        /// Learn more: https://spinframework.dev/writing-apps#using-component-dependencies
144        component: KebabId,
145        /// The name of the export in the package. If omitted, this defaults to the name of the import.
146        ///
147        /// Example: `"my:dep/import" = { export = "your:impl/export", component = "my-dependency" }`
148        ///
149        /// Learn more: https://spinframework.dev/writing-apps#using-component-dependencies
150        export: Option<String>,
151        /// The set of configurations to inherit from the parent component. If omitted or set to `false`,
152        /// no configurations will be inherited. If `true`, all configurations will be inherited.
153        /// Selective inheritance can be specified by enumerating the configuration keys the dependency
154        /// would like to inherit.
155        ///
156        /// Examples:
157        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = true }`
158        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = ["ai_models", "allowed_outbound_hosts"] }`
159        inherit_configuration: Option<InheritConfiguration>,
160    },
161}
162
163impl ComponentDependency {
164    /// Returns the `inherit_configuration` field if present on this dependency variant.
165    pub fn inherit_configuration(&self) -> Option<&InheritConfiguration> {
166        match self {
167            ComponentDependency::Version(_) => None,
168            ComponentDependency::Package {
169                inherit_configuration,
170                ..
171            }
172            | ComponentDependency::Local {
173                inherit_configuration,
174                ..
175            }
176            | ComponentDependency::HTTP {
177                inherit_configuration,
178                ..
179            }
180            | ComponentDependency::AppComponent {
181                inherit_configuration,
182                ..
183            } => inherit_configuration.as_ref(),
184        }
185    }
186
187    /// Sets the `inherit_configuration` field on this dependency variant.
188    /// No-op for `Version` variants.
189    pub fn set_inherit_configuration(&mut self, value: InheritConfiguration) {
190        match self {
191            ComponentDependency::Version(_) => {}
192            ComponentDependency::Package {
193                inherit_configuration,
194                ..
195            }
196            | ComponentDependency::Local {
197                inherit_configuration,
198                ..
199            }
200            | ComponentDependency::HTTP {
201                inherit_configuration,
202                ..
203            }
204            | ComponentDependency::AppComponent {
205                inherit_configuration,
206                ..
207            } => {
208                *inherit_configuration = Some(value);
209            }
210        }
211    }
212}
213
214/// Specifies how to satisfy an import dependency of the component. This may be one of:
215///
216/// - A semantic versioning constraint for the package version to use. Spin fetches the latest matching version of the package whose name matches the dependency name from the default registry.
217///
218/// Example: `"my:dep/import" = ">= 0.1.0"`
219///
220/// - A package from a registry.
221///
222/// Example: `"my:dep/import" = { version = "0.1.0", registry = "registry.io", ...}`
223///
224/// - A package from a filesystem path.
225///
226/// Example: `"my:dependency" = { path = "path/to/component.wasm", export = "my-export" }`
227///
228/// - A component in the application. The referenced component binary is composed: additional
229///   configuration such as files, networking, storage, etc. are ignored. This is intended
230///   primarily as a convenience for including dependencies in the manifest so that they
231///   can be built using `spin build`.
232///
233/// Example: `"my:dependency" = { component = "my-dependency", export = "my-export" }`
234///
235/// - A package from an HTTP URL.
236///
237/// Example: `"my:import" = { url = "https://example.com/component.wasm", sha256 = "sha256:..." }`
238///
239/// Learn more: https://spinframework.dev/v3/writing-apps#using-component-dependencies
240#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
241#[serde(untagged, deny_unknown_fields)]
242pub enum TriggerDependency {
243    /// `... = { version = "0.1.0", registry = "registry.io", ...}`
244    #[schemars(description = "")] // schema docs are on the parent
245    Package {
246        /// A semantic versioning constraint for the package version to use. Required. Spin
247        /// fetches the latest matching version from the specified registry, or from
248        /// the default registry if no registry is specified.
249        ///
250        /// Example: `"my:dep/import" = { version = ">= 0.1.0" }`
251        ///
252        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-registry
253        version: String,
254        /// The registry that hosts the package. If omitted, this defaults to your
255        /// system default registry.
256        ///
257        /// Example: `"my:dep/import" = { registry = "registry.io", version = "0.1.0" }`
258        ///
259        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-registry
260        registry: Option<String>,
261        /// The name of the package to use. If omitted, this defaults to the package name of the
262        /// imported interface.
263        ///
264        /// Example: `"my:dep/import" = { package = "your:implementation", version = "0.1.0" }`
265        ///
266        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-registry
267        package: String,
268        /// The set of configurations to inherit from the parent component. If omitted or set to `false`,
269        /// no configurations will be inherited. If `true`, all configurations will be inherited.
270        /// Selective inheritance can be specified by enumerating the configuration keys the dependency
271        /// would like to inherit.
272        ///
273        /// Examples:
274        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = true }`
275        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = ["ai_models", "allowed_outbound_hosts"] }`
276        inherit_configuration: Option<InheritConfiguration>,
277    },
278    /// `... = { path = "path/to/component.wasm", export = "my-export" }`
279    #[schemars(description = "")] // schema docs are on the parent
280    Local {
281        /// The path to the Wasm file that implements the dependency.
282        ///
283        /// Example: `"my:dep/import" = { path = "path/to/component.wasm" }`
284        ///
285        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-local-component
286        path: PathBuf,
287        /// The set of configurations to inherit from the parent component. If omitted or set to `false`,
288        /// no configurations will be inherited. If `true`, all configurations will be inherited.
289        /// Selective inheritance can be specified by enumerating the configuration keys the dependency
290        /// would like to inherit.
291        ///
292        /// Examples:
293        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = true }`
294        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = ["ai_models", "allowed_outbound_hosts"] }`
295        inherit_configuration: Option<InheritConfiguration>,
296    },
297    /// `... = { url = "https://example.com/component.wasm", sha256 = "..." }`
298    #[schemars(description = "")] // schema docs are on the parent
299    HTTP {
300        /// The URL to the Wasm component that implements the dependency.
301        ///
302        /// Example: `"my:dep/import" = { url = "https://example.com/component.wasm", sha256 = "sha256:..." }`
303        ///
304        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-url
305        url: String,
306        /// The SHA256 digest of the Wasm file. This is required for integrity checking. Must begin with `sha256:`.
307        ///
308        /// Example: `"my:dep/import" = { sha256 = "sha256:...", ... }`
309        ///
310        /// Learn more: https://spinframework.dev/writing-apps#dependencies-from-a-url
311        digest: String,
312        /// The set of configurations to inherit from the parent component. If omitted or set to `false`,
313        /// no configurations will be inherited. If `true`, all configurations will be inherited.
314        /// Selective inheritance can be specified by enumerating the configuration keys the dependency
315        /// would like to inherit.
316        ///
317        /// Examples:
318        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = true }`
319        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = ["ai_models", "allowed_outbound_hosts"] }`
320        inherit_configuration: Option<InheritConfiguration>,
321    },
322    /// `... = { component = "my-dependency" }`
323    #[schemars(description = "")] // schema docs are on the parent
324    AppComponent {
325        /// The ID of the component which implements the dependency.
326        ///
327        /// Example: `"my:dep/import" = { component = "my-dependency" }`
328        ///
329        /// Learn more: https://spinframework.dev/writing-apps#using-component-dependencies
330        component: KebabId,
331        /// The set of configurations to inherit from the parent component. If omitted or set to `false`,
332        /// no configurations will be inherited. If `true`, all configurations will be inherited.
333        /// Selective inheritance can be specified by enumerating the configuration keys the dependency
334        /// would like to inherit.
335        ///
336        /// Examples:
337        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = true }`
338        ///     `"my:dep/import" = { version = "0.1.0", inherit_configuration = ["ai_models", "allowed_outbound_hosts"] }`
339        inherit_configuration: Option<InheritConfiguration>,
340    },
341}
342
343/// The set of configurations to inherit from the parent component.
344///
345/// Can be specified as:
346/// - `true` — inherit all configurations
347/// - `false` — inherit no configurations (equivalent to omitting the field)
348/// - `["key1", "key2"]` — inherit only the specified configuration keys
349#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
350#[serde(untagged)]
351pub enum InheritConfiguration {
352    /// All or no configurations will be inherited, specified as `true` or `false`.
353    All(bool),
354    /// Only the specified configuration keys will be inherited from the parent component.
355    Some(Vec<String>),
356}